Skip to content

Commit a8e3c7f

Browse files
sebmarkbagefacebook-github-bot
authored andcommitted
Yolo Delete ReactNativePropRegistry
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
1 parent 722f88c commit a8e3c7f

File tree

6 files changed

+20
-61
lines changed

6 files changed

+20
-61
lines changed

Libraries/Renderer/shims/ReactNativePropRegistry.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

Libraries/StyleSheet/StyleSheet.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
'use strict';
1212

1313
const PixelRatio = require('PixelRatio');
14-
const ReactNativePropRegistry = require('ReactNativePropRegistry');
1514
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
1615
const StyleSheetValidation = require('StyleSheetValidation');
1716

1817
const flatten = require('flattenStyle');
1918

2019
import type {
21-
____StyleSheetInternalStyleIdentifier_Internal as StyleSheetInternalStyleIdentifier,
2220
____Styles_Internal,
2321
____DangerouslyImpreciseStyle_Internal,
2422
____DangerouslyImpreciseStyleProp_Internal,
@@ -171,16 +169,16 @@ if (hairlineWidth === 0) {
171169
hairlineWidth = 1 / PixelRatio.get();
172170
}
173171

174-
const absoluteFillObject: LayoutStyle = {
172+
const absoluteFill: LayoutStyle = {
175173
position: 'absolute',
176174
left: 0,
177175
right: 0,
178176
top: 0,
179177
bottom: 0,
180178
};
181-
const absoluteFill: StyleSheetInternalStyleIdentifier = ReactNativePropRegistry.register(
182-
absoluteFillObject,
183-
); // This also freezes it
179+
if (__DEV__) {
180+
Object.freeze(absoluteFill);
181+
}
184182

185183
/**
186184
* A StyleSheet is an abstraction similar to CSS StyleSheets
@@ -253,7 +251,7 @@ module.exports = {
253251
* so `absoluteFill` can be used for convenience and to reduce duplication of these repeated
254252
* styles.
255253
*/
256-
absoluteFill,
254+
absoluteFill: (absoluteFill: any), // TODO: This should be updated after we fix downstream Flow sites.
257255

258256
/**
259257
* Sometimes you may want `absoluteFill` but with a couple tweaks - `absoluteFillObject` can be
@@ -267,7 +265,7 @@ module.exports = {
267265
* },
268266
* });
269267
*/
270-
absoluteFillObject,
268+
absoluteFillObject: absoluteFill,
271269

272270
/**
273271
* Combines two styles such that `style2` will override any styles in `style1`.
@@ -361,14 +359,16 @@ module.exports = {
361359
/**
362360
* Creates a StyleSheet style reference from the given object.
363361
*/
364-
create<+S: ____Styles_Internal>(
365-
obj: S,
366-
): $ObjMap<S, (Object) => StyleSheetInternalStyleIdentifier> {
367-
const result = {};
368-
for (const key in obj) {
369-
StyleSheetValidation.validateStyle(key, obj);
370-
result[key] = obj[key] && ReactNativePropRegistry.register(obj[key]);
362+
create<+S: ____Styles_Internal>(obj: S): $ObjMap<S, (Object) => any> {
363+
// TODO: This should return S as the return type. But first,
364+
// we need to codemod all the callsites that are typing this
365+
// return value as a number (even though it was opaque).
366+
if (__DEV__) {
367+
for (const key in obj) {
368+
StyleSheetValidation.validateStyle(key, obj);
369+
Object.freeze(obj[key]);
370+
}
371371
}
372-
return result;
372+
return obj;
373373
},
374374
};

Libraries/StyleSheet/StyleSheetTypes.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
const AnimatedNode = require('AnimatedNode');
1515

16-
export opaque type ____StyleSheetInternalStyleIdentifier_Internal: number = number;
17-
1816
export type ColorValue = null | string;
1917
export type DimensionValue = null | number | string | AnimatedNode;
2018

@@ -224,8 +222,6 @@ type GenericStyleProp<+T> =
224222
| null
225223
| void
226224
| T
227-
| ____StyleSheetInternalStyleIdentifier_Internal
228-
| number
229225
| false
230226
| ''
231227
| $ReadOnlyArray<GenericStyleProp<T>>;

Libraries/StyleSheet/__tests__/flattenStyle-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('flattenStyle', () => {
150150
it('should ignore invalid class names', () => {
151151
var invalid = flattenStyle(1234, null);
152152

153-
expect(invalid).toEqual({});
153+
expect(invalid).toEqual(undefined);
154154
// Invalid class name 1234 skipping ...
155155
});
156156
});

Libraries/StyleSheet/flattenStyle.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,20 @@
1010
*/
1111
'use strict';
1212

13-
var ReactNativePropRegistry;
14-
1513
import type {
1614
DangerouslyImpreciseStyle,
1715
DangerouslyImpreciseStyleProp,
1816
} from 'StyleSheet';
1917

20-
function getStyle(style) {
21-
if (ReactNativePropRegistry === undefined) {
22-
ReactNativePropRegistry = require('ReactNativePropRegistry');
23-
}
24-
if (typeof style === 'number') {
25-
return ReactNativePropRegistry.getByID(style);
26-
}
27-
return style;
28-
}
29-
3018
function flattenStyle(
3119
style: ?DangerouslyImpreciseStyleProp,
3220
): ?DangerouslyImpreciseStyle {
33-
if (style == null) {
21+
if (style === null || typeof style !== 'object') {
3422
return undefined;
3523
}
3624

3725
if (!Array.isArray(style)) {
38-
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
39-
* error found when Flow v0.63 was deployed. To see the error delete this
40-
* comment and run Flow. */
41-
return getStyle(style);
26+
return style;
4227
}
4328

4429
var result = {};

jest/setup.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,7 @@ Object.keys(mockNativeModules).forEach(module => {
324324
});
325325

326326
jest
327-
.doMock('NativeModules', () => mockNativeModules)
328-
.doMock('ReactNativePropRegistry', () => ({
329-
register: id => id,
330-
getByID: () => mockEmptyObject,
331-
}));
327+
.doMock('NativeModules', () => mockNativeModules);
332328

333329
jest.doMock('requireNativeComponent', () => {
334330
const React = require('react');

0 commit comments

Comments
 (0)