From 88ee85720b8f94ca1bb8e9596ff51eacad4eac65 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 14 Oct 2024 16:15:39 +0200 Subject: [PATCH 1/2] fix: bad check whether we are in native stack or not --- ios/RNSScreen.mm | 19 +++++++++++++++---- ios/RNSScreenNavigationContainer.mm | 5 +++++ ios/RNSScreenStack.h | 7 +++++++ ios/RNSScreenStack.mm | 7 ++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index 6d069499f0..772e1ce900 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -304,15 +304,26 @@ - (void)setActivityStateOrNil:(NSNumber *)activityStateOrNil { int activityState = [activityStateOrNil intValue]; if (activityStateOrNil != nil && activityState != -1 && activityState != _activityState) { - if ([_controller.navigationController isKindOfClass:RNSNavigationController.class] && - _activityState < activityState) { - RCTLogError(@"[RNScreens] activityState can only progress in NativeStack"); - } + [self maybeAssertActivityStateProgressionOldValue:_activityState newValue:activityState]; _activityState = activityState; [_reactSuperview markChildUpdated]; } } +- (void)maybeAssertActivityStateProgressionOldValue:(int)oldValue newValue:(int)newValue +{ + if (self.isNativeStackScreen && newValue < oldValue) { + RCTLogError(@"[RNScreens] activityState can only progress in NativeStack"); + } +} + +- (BOOL)isNativeStackScreen +{ + UINavigationController *navCtrl = _controller.navigationController; + return [navCtrl isKindOfClass:RNSNavigationController.class] && + ((RNSNavigationController *)navCtrl).isNativeStackViewController; +} + #if !TARGET_OS_TV && !TARGET_OS_VISION - (void)setStatusBarStyle:(RNSStatusBarStyle)statusBarStyle { diff --git a/ios/RNSScreenNavigationContainer.mm b/ios/RNSScreenNavigationContainer.mm index d062e5f913..538230300c 100644 --- a/ios/RNSScreenNavigationContainer.mm +++ b/ios/RNSScreenNavigationContainer.mm @@ -12,6 +12,11 @@ @implementation RNSContainerNavigationController +- (BOOL)isNativeStackViewController +{ + return NO; +} + @end @implementation RNSScreenNavigationContainerView diff --git a/ios/RNSScreenStack.h b/ios/RNSScreenStack.h index 516fc49d99..5c218488ab 100644 --- a/ios/RNSScreenStack.h +++ b/ios/RNSScreenStack.h @@ -11,6 +11,13 @@ NS_ASSUME_NONNULL_BEGIN @interface RNSNavigationController : UINavigationController +/// @returns `YES` when this view controller was created as a part of native stack view. +/// Subclasses such as `RNSContainerNavigationController` should override this method. +/// +/// Note that this is a temporary workaround needed to perform some assertions. When it becomes +/// obselete it should be removed. +- (BOOL)isNativeStackViewController; + @end @interface RNSScreenStackView : diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index dacdc5f355..a238ca053d 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -52,6 +52,11 @@ @interface RNSScreenStackView () < @implementation RNSNavigationController +- (BOOL)isNativeStackViewController +{ + return YES; +} + #if !TARGET_OS_TV - (UIViewController *)childViewControllerForStatusBarStyle { @@ -953,7 +958,7 @@ - (void)navigationController:(UINavigationController *)navigationController - (void)markChildUpdated { - // do nothing + // In native stack this should be called only for `preload` purposes. [self updateContainer]; } From 4651eb9a47bc8cf1eebb13cf9adf86bcfa0ac032 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Tue, 15 Oct 2024 11:40:10 +0200 Subject: [PATCH 2/2] fix: improve (hopefully) check for whether the screen is in native stack --- ios/RNSScreen.mm | 5 ++--- ios/RNSScreenNavigationContainer.mm | 5 ----- ios/RNSScreenStack.h | 7 ------- ios/RNSScreenStack.mm | 5 ----- 4 files changed, 2 insertions(+), 20 deletions(-) diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index 772e1ce900..9b7d1d668e 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -317,11 +317,10 @@ - (void)maybeAssertActivityStateProgressionOldValue:(int)oldValue newValue:(int) } } +/// Note that this method works only after the screen is actually mounted under a screen stack view. - (BOOL)isNativeStackScreen { - UINavigationController *navCtrl = _controller.navigationController; - return [navCtrl isKindOfClass:RNSNavigationController.class] && - ((RNSNavigationController *)navCtrl).isNativeStackViewController; + return [_reactSuperview isKindOfClass:RNSScreenStackView.class]; } #if !TARGET_OS_TV && !TARGET_OS_VISION diff --git a/ios/RNSScreenNavigationContainer.mm b/ios/RNSScreenNavigationContainer.mm index 538230300c..d062e5f913 100644 --- a/ios/RNSScreenNavigationContainer.mm +++ b/ios/RNSScreenNavigationContainer.mm @@ -12,11 +12,6 @@ @implementation RNSContainerNavigationController -- (BOOL)isNativeStackViewController -{ - return NO; -} - @end @implementation RNSScreenNavigationContainerView diff --git a/ios/RNSScreenStack.h b/ios/RNSScreenStack.h index 5c218488ab..516fc49d99 100644 --- a/ios/RNSScreenStack.h +++ b/ios/RNSScreenStack.h @@ -11,13 +11,6 @@ NS_ASSUME_NONNULL_BEGIN @interface RNSNavigationController : UINavigationController -/// @returns `YES` when this view controller was created as a part of native stack view. -/// Subclasses such as `RNSContainerNavigationController` should override this method. -/// -/// Note that this is a temporary workaround needed to perform some assertions. When it becomes -/// obselete it should be removed. -- (BOOL)isNativeStackViewController; - @end @interface RNSScreenStackView : diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index a238ca053d..ed089be8d7 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -52,11 +52,6 @@ @interface RNSScreenStackView () < @implementation RNSNavigationController -- (BOOL)isNativeStackViewController -{ - return YES; -} - #if !TARGET_OS_TV - (UIViewController *)childViewControllerForStatusBarStyle {