Skip to content
Draft
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
26 changes: 22 additions & 4 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#import <React/RCTShadowView.h>
#import <React/RCTUIManager.h>
#import <React/RCTUIManagerUtils.h>
#import <cxxreact/ReactNativeVersion.h>

#import "RNSConversions.h"
#import "RNSReactNativeVersionUtils.h"
#import "RNSSafeAreaViewNotifications.h"
#import "RNSScreenFooter.h"
#import "RNSScreenStack.h"
Expand Down Expand Up @@ -936,16 +938,23 @@ - (BOOL)isTransparentModal

- (void)invalidateImpl
{
_controller = nil;
[_sheetsScrollView removeObserver:self forKeyPath:@"bounds" context:nil];
// We want to run after container updates are performed (transitions etc.)
__weak auto weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
auto strongSelf = weakSelf;
if (strongSelf) {
strongSelf->_controller = nil;
[strongSelf->_sheetsScrollView removeObserver:self forKeyPath:@"bounds" context:nil];
}
});
}

#ifndef RCT_NEW_ARCH_ENABLED
#if !RCT_NEW_ARCH_ENABLED
- (void)invalidate
{
[self invalidateImpl];
}
#endif
#endif // !RCT_NEW_ARCH_ENABLED

#if !TARGET_OS_TV && !TARGET_OS_VISION

Expand Down Expand Up @@ -1509,6 +1518,15 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
#endif // !TARGET_OS_TV && !TARGET_OS_VISION
}

#if REACT_NATIVE_VERSION_MINOR >= 82
- (void)invalidate
{
if (!facebook::react::is082PrereleaseOrLower()) {
[self invalidateImpl];
}
}
#endif // REACT_NATIVE_VERSION_MINOR >= 82

#pragma mark - Paper specific
#else

Expand Down
60 changes: 35 additions & 25 deletions ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#import "RCTTouchHandler+RNSUtility.h"
#endif // RCT_NEW_ARCH_ENABLED

#import <cxxreact/ReactNativeVersion.h>
#import "RNSDefines.h"
#import "RNSPercentDrivenInteractiveTransition.h"
#import "RNSReactNativeVersionUtils.h"
#import "RNSScreen.h"
#import "RNSScreenStack.h"
#import "RNSScreenStackAnimator.h"
Expand Down Expand Up @@ -210,13 +212,13 @@ @implementation RNSScreenStackView {
RNSPercentDrivenInteractiveTransition *_interactionController;
__weak RNSScreenStackManager *_manager;
BOOL _updateScheduled;
#ifdef RCT_NEW_ARCH_ENABLED
#if RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
/// Screens that are subject of `ShadowViewMutation::Type::Delete` mutation
/// in current transaction. This vector should be populated when we receive notification via
/// `RCTMountingObserving` protocol, that a transaction will be performed, and should
/// be cleaned up when we're notified that the transaction has been completed.
std::vector<__strong RNSScreenView *> _toBeDeletedScreens;
#endif // RCT_NEW_ARCH_ENABLED
#endif // RCT_NEW_ARCH_ENABLED && REACT_NATIVE_VERSION_MINOR <= 82
}

#ifdef RCT_NEW_ARCH_ENABLED
Expand Down Expand Up @@ -1369,15 +1371,19 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
- (void)mountingTransactionWillMount:(const facebook::react::MountingTransaction &)transaction
withSurfaceTelemetry:(const facebook::react::SurfaceTelemetry &)surfaceTelemetry
{
for (const auto &mutation : transaction.getMutations()) {
if (mutation.type == react::ShadowViewMutation::Delete) {
RNSScreenView *_Nullable toBeRemovedChild = [self childScreenForTag:mutation.oldChildShadowView.tag];
if (toBeRemovedChild != nil) {
[toBeRemovedChild willBeUnmountedInUpcomingTransaction];
_toBeDeletedScreens.push_back(toBeRemovedChild);
#if REACT_NATIVE_VERSION_MINOR <= 82
if (facebook::react::is082PrereleaseOrLower()) {
for (const auto &mutation : transaction.getMutations()) {
if (mutation.type == react::ShadowViewMutation::Delete) {
RNSScreenView *_Nullable toBeRemovedChild = [self childScreenForTag:mutation.oldChildShadowView.tag];
if (toBeRemovedChild != nil) {
[toBeRemovedChild willBeUnmountedInUpcomingTransaction];
_toBeDeletedScreens.push_back(toBeRemovedChild);
}
}
}
}
#endif // REACT_NATIVE_VERSION_MINOR <= 82
}

- (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction &)transaction
Expand All @@ -1400,24 +1406,28 @@ - (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction
}
}

if (!self->_toBeDeletedScreens.empty()) {
__weak RNSScreenStackView *weakSelf = self;
// We want to run after container updates are performed (transitions etc.)
dispatch_async(dispatch_get_main_queue(), ^{
RNSScreenStackView *_Nullable strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}
for (RNSScreenView *screenRef : strongSelf->_toBeDeletedScreens) {
#ifdef RCT_NEW_ARCH_ENABLED
[screenRef invalidateImpl];
#else
[screenRef invalidate];
#endif
}
strongSelf->_toBeDeletedScreens.clear();
});
#if REACT_NATIVE_VERSION_MINOR <= 82
if (facebook::react::is082PrereleaseOrLower()) {
if (!self->_toBeDeletedScreens.empty()) {
__weak RNSScreenStackView *weakSelf = self;
// We want to run after container updates are performed (transitions etc.)
dispatch_async(dispatch_get_main_queue(), ^{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: it seems that we can consider removing that delay as invalidateImpl is doing the same right now, but I decided to leave it as it is, because we're invalidating a bit later and the code will be dropped when we stop supporting <0.82

RNSScreenStackView *_Nullable strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}
for (RNSScreenView *screenRef : strongSelf->_toBeDeletedScreens) {
#if RCT_NEW_ARCH_ENABLED
[screenRef invalidateImpl];
#else // RCT_NEW_ARCH_ENABLED
[screenRef invalidate];
#endif // RCT_NEW_ARCH_ENABLED
}
strongSelf->_toBeDeletedScreens.clear();
});
}
}
#endif // REACT_NATIVE_VERSION_MINOR <= 82
}

- (void)prepareForRecycle
Expand Down
2 changes: 1 addition & 1 deletion ios/bottom-tabs/RNSBottomTabsScreenComponentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#if REACT_NATIVE_VERSION_MINOR <= 82
#import "RNSViewControllerInvalidating.h"
#endif // REACT_NATIVE_VERSION_MINOR <= 82
#else // RCT_NEW_ARCH_ENABLED
#else // RCT_NEW_ARCH_ENABLED
#import <React/RCTInvalidating.h>
#endif // RCT_NEW_ARCH_ENABLED

Expand Down