Skip to content

Commit 103ec2f

Browse files
sahrensfacebook-github-bot
authored andcommitted
Fix Dimensions for ComponentScript
Summary: ComponentScript uses Dimensions, but doesn't support native modules, so we need to keep the `nativeExtensions` stuff that was dropped in D16525189. Reviewed By: PeteTheHeat Differential Revision: D16611233 fbshipit-source-id: c0add40529743e02ab7943814dc9f2188e8e0633
1 parent 0a68763 commit 103ec2f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Libraries/Utilities/Dimensions.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,23 @@ class Dimensions {
118118
}
119119
}
120120

121-
// Subscribe before calling getConstants to make sure we don't miss any updates in between.
122-
RCTDeviceEventEmitter.addListener(
123-
'didUpdateDimensions',
124-
(update: DimensionsPayload) => {
125-
Dimensions.set(update);
126-
},
127-
);
128-
Dimensions.set(NativeDeviceInfo.getConstants().Dimensions);
121+
let initialDims: ?$ReadOnly<{[key: string]: any}> =
122+
global.nativeExtensions &&
123+
global.nativeExtensions.DeviceInfo &&
124+
global.nativeExtensions.DeviceInfo.Dimensions;
125+
if (!initialDims) {
126+
// Subscribe before calling getConstants to make sure we don't miss any updates in between.
127+
RCTDeviceEventEmitter.addListener(
128+
'didUpdateDimensions',
129+
(update: DimensionsPayload) => {
130+
Dimensions.set(update);
131+
},
132+
);
133+
// Can't use NativeDeviceInfo in ComponentScript because it does not support NativeModules,
134+
// but has nativeExtensions instead.
135+
initialDims = NativeDeviceInfo.getConstants().Dimensions;
136+
}
137+
138+
Dimensions.set(initialDims);
129139

130140
module.exports = Dimensions;

0 commit comments

Comments
 (0)