Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
50 changes: 50 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
RNSInvalidatedComponentsRegistry *_Nonnull _invalidatedComponentsRegistry;
#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
_invalidatedComponentsRegistry = [RNSInvalidatedComponentsRegistry new];
#endif // RCT_NEW_ARCH_ENABLED
_reactEventEmitter = [RNSStackScreenComponentEventEmitter new];

_needsLifecycleStateUpdate = NO;
Expand All @@ -58,6 +69,17 @@ - (void)setupController
_controller.view = self;
}

#pragma mark - UIView methods

- (void)willMoveToWindow:(UIWindow *)newWindow
{
#if RCT_NEW_ARCH_ENABLED
if (newWindow == nil) {
[_invalidatedComponentsRegistry flushInvalidViews];
}
#endif // RCT_NEW_ARCH_ENABLED
}

#pragma mark - Events

- (nonnull RNSStackScreenComponentEventEmitter *)reactEventEmitter
Expand Down Expand Up @@ -116,6 +138,34 @@ + (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]) {
[RNSViewControllerInvalidator invalidateViewIfDetached:self forRegistry:_invalidatedComponentsRegistry];
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First thing is: why do we have to scan whole list of mutations in every screen component? Why can't we just do it once per transaction in host component?

Copy link
Contributor Author

@t0maboro t0maboro Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flushInvalidViews is triggered when the component is moved out of the window. In such a scenario, the Host will keep all Screens in its registry - we don't know for how long (if the Screen cannot invalidate itself immediately on the mutation, it needs to mark that the mutation came and invalidate on willMoveToWindow:nil)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I don't have good suggestion here unfortunately, but I dislike this solution for it's excessive (hopefully) transaction scanning. I'll try to come up with something better soon. We can discuss this on Monday.


#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