-
-
Notifications
You must be signed in to change notification settings - Fork 588
feat(iOS, Stack): Add controller invalidating to new stack impl #3219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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]; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Uh oh!
There was an error while loading. Please reload this page.