diff --git a/ios/gamma/stack/RNSStackScreenComponentView.h b/ios/gamma/stack/RNSStackScreenComponentView.h index 9c89827232..05896ce817 100644 --- a/ios/gamma/stack/RNSStackScreenComponentView.h +++ b/ios/gamma/stack/RNSStackScreenComponentView.h @@ -1,6 +1,10 @@ #import "RNSReactBaseView.h" #import "RNSStackScreenComponentEventEmitter.h" +#ifdef RCT_NEW_ARCH_ENABLED +#import "RNSViewControllerInvalidating.h" +#endif // RCT_NEW_ARCH_ENABLED + NS_ASSUME_NONNULL_BEGIN @class RNSStackScreenController; @@ -13,6 +17,9 @@ typedef NS_ENUM(int, RNSScreenStackLifecycleState) { }; @interface RNSStackScreenComponentView : RNSReactBaseView +#ifdef RCT_NEW_ARCH_ENABLED + +#endif // RCT_NEW_ARCH_ENABLED @property (nonatomic, weak, readwrite, nullable) RNSScreenStackHostComponentView *stackHost; @property (nonatomic, strong, readonly, nonnull) RNSStackScreenController *controller; diff --git a/ios/gamma/stack/RNSStackScreenComponentView.mm b/ios/gamma/stack/RNSStackScreenComponentView.mm index f17c428743..c1d74a7ff9 100644 --- a/ios/gamma/stack/RNSStackScreenComponentView.mm +++ b/ios/gamma/stack/RNSStackScreenComponentView.mm @@ -6,6 +6,11 @@ #import #import +#ifdef RCT_NEW_ARCH_ENABLED +#import "RNSInvalidatedComponentsRegistry.h" +#import "RNSViewControllerInvalidator.h" +#endif // RCT_NEW_ARCH_ENABLED + #import "Swift-Bridging.h" namespace react = facebook::react; @@ -18,6 +23,9 @@ @interface RNSStackScreenComponentView () @implementation RNSStackScreenComponentView { RNSStackScreenController *_Nonnull _controller; RNSStackScreenComponentEventEmitter *_Nonnull _reactEventEmitter; +#ifdef RCT_NEW_ARCH_ENABLED + BOOL _markedForInvalidation; +#endif // RCT_NEW_ARCH_ENABLED // Flags BOOL _needsLifecycleStateUpdate; @@ -37,6 +45,9 @@ - (void)initState [self resetProps]; [self setupController]; +#ifdef RCT_NEW_ARCH_ENABLED + _markedForInvalidation = NO; +#endif // RCT_NEW_ARCH_ENABLED _reactEventEmitter = [RNSStackScreenComponentEventEmitter new]; _needsLifecycleStateUpdate = NO; @@ -58,6 +69,19 @@ - (void)setupController _controller.view = self; } +#pragma mark - UIView methods + +- (void)willMoveToWindow:(UIWindow *)newWindow +{ +#if RCT_NEW_ARCH_ENABLED + if (newWindow == nil) { + if (_markedForInvalidation) { + [self invalidateController]; + } + } +#endif // RCT_NEW_ARCH_ENABLED +} + #pragma mark - Events - (nonnull RNSStackScreenComponentEventEmitter *)reactEventEmitter @@ -116,6 +140,38 @@ + (BOOL)shouldBeRecycled return NO; } +#ifdef RCT_NEW_ARCH_ENABLED + +#pragma mark - RCTMountingTransactionObserving + +- (void)mountingTransactionWillMount:(const facebook::react::MountingTransaction &)transaction + withSurfaceTelemetry:(const facebook::react::SurfaceTelemetry &)surfaceTelemetry +{ + for (const auto &mutation : transaction.getMutations()) { + if ([self shouldInvalidateOnMutation:mutation]) { + if (self.window == nil) { + [self invalidateController]; + } else { + _markedForInvalidation = YES; + } + } + } +} + +#pragma mark - RNSViewControllerInvalidating + +- (void)invalidateController +{ + _controller = nil; +} + +- (BOOL)shouldInvalidateOnMutation:(const facebook::react::ShadowViewMutation &)mutation +{ + return (mutation.oldChildShadowView.tag == self.tag && mutation.type == facebook::react::ShadowViewMutation::Delete); +} + +#endif // RCT_NEW_ARCH_ENABLED + @end Class RNSStackScreenCls(void)