react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fix useWindowDimensions not updating because of delayed applicationState update on iOS devices

Open Tuuben opened this issue 1 year ago • 0 comments

Summary:

Issue

When a real device is oriented into landscape and the user locks the screen during said orientation incase the user rotates back to previous orientation and unlocks the screen useWindowDimensions will not get the correctly updated values. This is due to applicationState being equal to UIApplicationStateInactive still when interfaceFrameDidChange gets called.

Fix

didUpdateDimensions on iOS. Now correctly emits the dimension values after the device has been oriented and device has been locked. By adding UIDeviceOrientationDidChangeNotification to NSNotificationCenter

Changelog:

  // RCTDeviceInfo.mm
  
  // Adds the interfaceFrameDidChange to UIDeviceOrientationDidChangeNotification
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(interfaceFrameDidChange)
                                               name:UIDeviceOrientationDidChangeNotification
                                             object:nil];

[IOS] [FIXED] - Emit didUpdateDimensions correctly

Test Plan:

Note: This doesn't seem to be replicable on simulators. It only happens on real iOS devices.

Before change:

Rotate Device > Lock Screen > Rotate back to portrait > Unlock phone IMG_6089

After change:

Same steps as above, now emits correct values IMG_6091

Tuuben avatar Sep 05 '24 15:09 Tuuben