Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ios/gamma/stack/RNSStackScreenComponentView.h
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +17,9 @@ typedef NS_ENUM(int, RNSScreenStackLifecycleState) {
};

@interface RNSStackScreenComponentView : RNSReactBaseView
#ifdef RCT_NEW_ARCH_ENABLED
<RNSViewControllerInvalidating>
#endif // RCT_NEW_ARCH_ENABLED

@property (nonatomic, weak, readwrite, nullable) RNSScreenStackHostComponentView *stackHost;
@property (nonatomic, strong, readonly, nonnull) RNSStackScreenController *controller;
Expand Down
56 changes: 56 additions & 0 deletions ios/gamma/stack/RNSStackScreenComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#import <react/renderer/components/rnscreens/Props.h>
#import <react/renderer/components/rnscreens/RCTComponentViewHelpers.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import "RNSInvalidatedComponentsRegistry.h"
#import "RNSViewControllerInvalidator.h"
#endif // RCT_NEW_ARCH_ENABLED

#import "Swift-Bridging.h"

namespace react = facebook::react;
Expand All @@ -18,6 +23,9 @@ @interface RNSStackScreenComponentView () <RCTMountingTransactionObserving>
@implementation RNSStackScreenComponentView {
RNSStackScreenController *_Nonnull _controller;
RNSStackScreenComponentEventEmitter *_Nonnull _reactEventEmitter;
#ifdef RCT_NEW_ARCH_ENABLED
BOOL _markedForInvalidation;
#endif // RCT_NEW_ARCH_ENABLED

// Flags
BOOL _needsLifecycleStateUpdate;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<RCTComponentViewProtocol> RNSStackScreenCls(void)
Expand Down
Loading