Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using namespace facebook::react;

@interface RCTDeviceInfo () <NativeDeviceInfoSpec, RCTInitializing, RCTInvalidating>
// Atomic because the sync -getConstants reads it on the JS thread while the main thread rewrites it.
@property (atomic, copy) NSDictionary<NSString *, id> *constants;
@end

@implementation RCTDeviceInfo {
Expand All @@ -31,7 +33,6 @@ @implementation RCTDeviceInfo {
NSDictionary *_currentInterfaceDimensions;
BOOL _isFullscreen;
std::atomic<BOOL> _invalidated;
NSDictionary *_constants;

__weak UIWindow *_applicationWindow;
NSDictionary * (^_dimensionsProvider)(void);
Expand Down Expand Up @@ -122,7 +123,7 @@ - (void)initialize
- (void)invalidateCachedConstants
{
RCTAssertMainQueue();
_constants = @{
self.constants = @{
@"Dimensions" : [self _exportedDimensions],
// Note:
// This prop is deprecated and will be removed in a future release.
Expand Down Expand Up @@ -236,13 +237,13 @@ - (NSDictionary *)_exportedDimensions

- (NSDictionary<NSString *, id> *)getConstants
{
return _constants;
return self.constants;
}

- (void)didReceiveNewContentSizeMultiplier
{
[self invalidateCachedConstants];
NSDictionary *nextInterfaceDimensions = _constants[@"Dimensions"];
NSDictionary *nextInterfaceDimensions = self.constants[@"Dimensions"];

RCTModuleRegistry *moduleRegistry = _moduleRegistry;
RCTExecuteOnMainQueue(^{
Expand Down Expand Up @@ -280,7 +281,7 @@ - (void)interfaceOrientationDidChange
if ((isOrientationChanging || isResizingOrChangingToFullscreen) && RCTIsAppActive()) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDictionary *nextInterfaceDimensions = _constants[@"Dimensions"];
NSDictionary *nextInterfaceDimensions = self.constants[@"Dimensions"];
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions"
body:nextInterfaceDimensions];
// We only want to track the current _currentInterfaceOrientation and _isFullscreen only
Expand All @@ -303,7 +304,7 @@ - (void)interfaceFrameDidChange
- (void)_interfaceFrameDidChange
{
[self invalidateCachedConstants];
NSDictionary *nextInterfaceDimensions = _constants[@"Dimensions"];
NSDictionary *nextInterfaceDimensions = self.constants[@"Dimensions"];

// update and publish the even only when the app is in active state
if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions]) && RCTIsAppActive()) {
Expand Down
Loading