Skip to content

Commit ea43137

Browse files
committed
Keep the existing observer when there is no key window
RCTKeyWindow() can return nil (backgrounded app, scene transition). Dropping the observer in that case would leave the module without one until another trigger happens to re-attach it.
1 parent b6e0caf commit ea43137

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎packages/react-native/React/CoreModules/RCTDeviceInfo.mm‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ - (void)_observeKeyWindowIfNeeded
154154
// The key window is looked up again instead of trusting the one captured in -init: when the host
155155
// app creates its window after this module is built, that capture is nil, the KVO below is never
156156
// installed, and app activation is left as the only trigger for a dimensions update.
157+
// A nil key window means there is nothing to observe yet (backgrounded app, scene transition);
158+
// keeping the current observer is better than dropping it until the next trigger comes along.
157159
UIWindow *keyWindow = RCTKeyWindow();
158-
if (keyWindow == _applicationWindow) {
160+
if (keyWindow == nil || keyWindow == _applicationWindow) {
159161
return;
160162
}
161163

0 commit comments

Comments
 (0)