This repository has been archived by the owner on Jul 21, 2021. It is now read-only.
forked from necolas/react-native-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(setValueForStyles): to be compatible with react fiber
- Loading branch information
Showing
1 changed file
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ if (process.env.NODE_ENV !== 'production') { | |
|
||
var checkRenderMessage = function(owner) { | ||
if (owner) { | ||
var name = owner.getName(); | ||
var name = getComponentName(owner); | ||
if (name) { | ||
return ' Check the render method of `' + name + '`.'; | ||
} | ||
|
@@ -111,7 +111,7 @@ if (process.env.NODE_ENV !== 'production') { | |
var warnValidStyle = function(name, value, component) { | ||
var owner; | ||
if (component) { | ||
owner = component._currentElement._owner; | ||
owner = getComponentOwner(component); | ||
} | ||
if (name.indexOf('-') > -1) { | ||
warnHyphenatedStyleName(name, owner); | ||
|
@@ -129,6 +129,28 @@ if (process.env.NODE_ENV !== 'production') { | |
|
||
var styleWarnings = {}; | ||
|
||
function getComponentType(component) { | ||
if (component._currentElement) { | ||
return component._currentElement.type | ||
} | ||
|
||
// in case of fiber / react 16 | ||
return component.type.displayName; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gaearon
|
||
} | ||
|
||
function getComponentName(component) { | ||
return component.getName() || component.displayName; | ||
} | ||
|
||
function getComponentOwner(component) { | ||
if (component._currentElement) { | ||
return component._currentElement._owner; | ||
} | ||
|
||
// in case of fiber / react 16 | ||
return component._debugOwner; | ||
} | ||
|
||
/** | ||
* Convert a value into the proper css writable value. The style name `name` | ||
* should be logical (no hyphens) | ||
|
@@ -170,8 +192,8 @@ function dangerousStyleValue(name, value, component) { | |
// Allow '0' to pass through without warning. 0 is already special and | ||
// doesn't require units, so we don't need to warn about it. | ||
if (component && value !== '0') { | ||
var owner = component._currentElement._owner; | ||
var ownerName = owner ? owner.getName() : null; | ||
var owner = getComponentOwner(component); | ||
var ownerName = owner ? getComponentName(owner) : null; | ||
if (ownerName && !styleWarnings[ownerName]) { | ||
styleWarnings[ownerName] = {}; | ||
} | ||
|
@@ -190,7 +212,7 @@ function dangerousStyleValue(name, value, component) { | |
'a `%s` tag (owner: `%s`) was passed a numeric string value ' + | ||
'for CSS property `%s` (value: `%s`) which will be treated ' + | ||
'as a unitless number in a future version of React.', | ||
component._currentElement.type, | ||
getComponentType(component), | ||
ownerName || 'unknown', | ||
name, | ||
value | ||
|
Please use type.displayName || type.name.
ES classes and functions won't have displayName.