-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
Summary: Changed StyleSheet.create to be the identity function. We no longer hide it behind an opaque number. Better for types and perf since we don't use it. I don't really know if we have/need any safer way of rolling this out than just landing it. It can break if the object passed to StyleSheet.create is mutated afterwards but that isn't a practice anywhere I've seen. Reviewed By: sophiebits Differential Revision: D7530023 fbshipit-source-id: bc1afa879c5a5d9cd95cb13bc8ff3347b3622851
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,12 @@ | |
'use strict'; | ||
|
||
const PixelRatio = require('PixelRatio'); | ||
const ReactNativePropRegistry = require('ReactNativePropRegistry'); | ||
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes'); | ||
const StyleSheetValidation = require('StyleSheetValidation'); | ||
|
||
const flatten = require('flattenStyle'); | ||
|
||
import type { | ||
____StyleSheetInternalStyleIdentifier_Internal as StyleSheetInternalStyleIdentifier, | ||
____Styles_Internal, | ||
____DangerouslyImpreciseStyle_Internal, | ||
____DangerouslyImpreciseStyleProp_Internal, | ||
|
@@ -171,16 +169,16 @@ if (hairlineWidth === 0) { | |
hairlineWidth = 1 / PixelRatio.get(); | ||
} | ||
|
||
const absoluteFillObject: LayoutStyle = { | ||
const absoluteFill: LayoutStyle = { | ||
position: 'absolute', | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0, | ||
}; | ||
const absoluteFill: StyleSheetInternalStyleIdentifier = ReactNativePropRegistry.register( | ||
absoluteFillObject, | ||
); // This also freezes it | ||
if (__DEV__) { | ||
Object.freeze(absoluteFill); | ||
} | ||
|
||
/** | ||
* A StyleSheet is an abstraction similar to CSS StyleSheets | ||
|
@@ -253,7 +251,7 @@ module.exports = { | |
* so `absoluteFill` can be used for convenience and to reduce duplication of these repeated | ||
* styles. | ||
*/ | ||
absoluteFill, | ||
absoluteFill: (absoluteFill: any), // TODO: This should be updated after we fix downstream Flow sites. | ||
|
||
/** | ||
* Sometimes you may want `absoluteFill` but with a couple tweaks - `absoluteFillObject` can be | ||
|
@@ -267,7 +265,7 @@ module.exports = { | |
* }, | ||
* }); | ||
*/ | ||
absoluteFillObject, | ||
absoluteFillObject: absoluteFill, | ||
|
||
/** | ||
* Combines two styles such that `style2` will override any styles in `style1`. | ||
|
@@ -361,14 +359,16 @@ module.exports = { | |
/** | ||
* Creates a StyleSheet style reference from the given object. | ||
*/ | ||
create<+S: ____Styles_Internal>( | ||
obj: S, | ||
): $ObjMap<S, (Object) => StyleSheetInternalStyleIdentifier> { | ||
const result = {}; | ||
for (const key in obj) { | ||
StyleSheetValidation.validateStyle(key, obj); | ||
result[key] = obj[key] && ReactNativePropRegistry.register(obj[key]); | ||
create<+S: ____Styles_Internal>(obj: S): $ObjMap<S, (Object) => any> { | ||
// TODO: This should return S as the return type. But first, | ||
// we need to codemod all the callsites that are typing this | ||
// return value as a number (even though it was opaque). | ||
if (__DEV__) { | ||
for (const key in obj) { | ||
StyleSheetValidation.validateStyle(key, obj); | ||
Object.freeze(obj[key]); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
} | ||
return result; | ||
return obj; | ||
This comment has been minimized.
Sorry, something went wrong.
brunolemos
Contributor
|
||
}, | ||
}; |
2 comments
on commit a8e3c7f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sebmarkbage
If there any discussion related to why you remove that registry and remove the supposed performance benefits that StyleSheet.create is supposed to bring over plain inline styles? Can't find this in the repo
Context: https://twitter.com/sebastienlorber/status/1067688788611264512
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand, the ReactNativePropRegistry
never sent the registered styles to the bridge but rather kept them in memory in js side.
Why it should be freeze in dev?