Skip to content

Commit

Permalink
Fix Dimensions for ComponentScript
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sahrens authored and facebook-github-bot committed Aug 2, 2019
1 parent 0a68763 commit 103ec2f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Libraries/Utilities/Dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,23 @@ class Dimensions {
}
}

// Subscribe before calling getConstants to make sure we don't miss any updates in between.
RCTDeviceEventEmitter.addListener(
'didUpdateDimensions',
(update: DimensionsPayload) => {
Dimensions.set(update);
},
);
Dimensions.set(NativeDeviceInfo.getConstants().Dimensions);
let initialDims: ?$ReadOnly<{[key: string]: any}> =
global.nativeExtensions &&
global.nativeExtensions.DeviceInfo &&
global.nativeExtensions.DeviceInfo.Dimensions;
if (!initialDims) {
// Subscribe before calling getConstants to make sure we don't miss any updates in between.
RCTDeviceEventEmitter.addListener(
'didUpdateDimensions',
(update: DimensionsPayload) => {
Dimensions.set(update);
},
);
// Can't use NativeDeviceInfo in ComponentScript because it does not support NativeModules,
// but has nativeExtensions instead.
initialDims = NativeDeviceInfo.getConstants().Dimensions;
}

Dimensions.set(initialDims);

module.exports = Dimensions;

0 comments on commit 103ec2f

Please sign in to comment.