From 9727161e1809ed3eb206d814b26ca7f7a694c644 Mon Sep 17 00:00:00 2001 From: tboba Date: Tue, 16 Jan 2024 11:10:35 +0100 Subject: [PATCH 1/4] Fix invalid orientation of contained modals --- ios/RNSScreenStack.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index 3d678a04e9..5330e74532 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -646,6 +646,15 @@ - (void)layoutSubviews { [super layoutSubviews]; _controller.view.frame = self.bounds; + + // We need to update the bounds of the modal views here, since + // for contained modals they are not updated by modals themselves, + // when no other modal has been dismissed yet. + for (UIViewController *modal in _presentedModals) { + if (!CGRectEqualToRect(modal.view.frame, self.bounds)) { + modal.view.frame = self.bounds; + } + } } - (void)dismissOnReload From 7aa8ee0181c9baa7ec8973ccc0497ebe4124d568 Mon Sep 17 00:00:00 2001 From: tboba Date: Wed, 24 Jan 2024 20:57:32 +0100 Subject: [PATCH 2/4] Change choosing the frame from self.bouds to superview --- ios/RNSScreenStack.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index 5330e74532..e569bc9dc7 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -648,11 +648,13 @@ - (void)layoutSubviews _controller.view.frame = self.bounds; // We need to update the bounds of the modal views here, since - // for contained modals they are not updated by modals themselves, - // when no other modal has been dismissed yet. + // for contained modals they are not updated by modals themselves. for (UIViewController *modal in _presentedModals) { - if (!CGRectEqualToRect(modal.view.frame, self.bounds)) { - modal.view.frame = self.bounds; + BOOL isModalBeingDismissed = [modal isKindOfClass:[RNSScreen class]] && ((RNSScreen *)modal).isBeingDismissed; + CGRect correctFrame = modal.view.superview != nil ? modal.view.superview.frame : self.bounds; + + if (!CGRectEqualToRect(modal.view.frame, correctFrame) && !isModalBeingDismissed) { + modal.view.frame = correctFrame; } } } From 40f4f32a411fa7f44d97c4edcd5bdf57769ddde0 Mon Sep 17 00:00:00 2001 From: tboba Date: Wed, 24 Jan 2024 22:05:17 +0100 Subject: [PATCH 3/4] Add helpful comment --- ios/RNSScreenStack.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index e569bc9dc7..b81ddcb7d1 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -650,6 +650,11 @@ - (void)layoutSubviews // We need to update the bounds of the modal views here, since // for contained modals they are not updated by modals themselves. for (UIViewController *modal in _presentedModals) { + // Because `layoutSubviews` method is also called on grabbing the modal, + // we don't want to update the frame when modal is being dismissed. + // We also want to get the frame in correct position. In the best case, it + // will be modal's superview (UITransitionView), which frame is being changed correctly. + // Otherwise, we will fallback to the bounds of the ScreenStack. BOOL isModalBeingDismissed = [modal isKindOfClass:[RNSScreen class]] && ((RNSScreen *)modal).isBeingDismissed; CGRect correctFrame = modal.view.superview != nil ? modal.view.superview.frame : self.bounds; From d33a618cd7bcb265438fa418d2acb6eaf1e9977c Mon Sep 17 00:00:00 2001 From: tboba Date: Wed, 24 Jan 2024 22:17:39 +0100 Subject: [PATCH 4/4] Correct the comment --- ios/RNSScreenStack.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index b81ddcb7d1..643643c02f 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -653,8 +653,8 @@ - (void)layoutSubviews // Because `layoutSubviews` method is also called on grabbing the modal, // we don't want to update the frame when modal is being dismissed. // We also want to get the frame in correct position. In the best case, it - // will be modal's superview (UITransitionView), which frame is being changed correctly. - // Otherwise, we will fallback to the bounds of the ScreenStack. + // should be modal's superview (UITransitionView), which frame is being changed correctly. + // Otherwise, when superview is nil, we will fallback to the bounds of the ScreenStack. BOOL isModalBeingDismissed = [modal isKindOfClass:[RNSScreen class]] && ((RNSScreen *)modal).isBeingDismissed; CGRect correctFrame = modal.view.superview != nil ? modal.view.superview.frame : self.bounds;