Skip to content
Closed
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
25 changes: 25 additions & 0 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#import "RNSDefines.h"
#import "UIView+RNSUtility.h"
#import "integrations/RNSLifecycleListenerProtocol.h"

#ifdef RCT_NEW_ARCH_ENABLED
namespace react = facebook::react;
Expand Down Expand Up @@ -76,6 +77,7 @@ @implementation RNSScreenView {
ContentWrapperBox _contentWrapperBox;
bool _sheetHasInitialDetentSet;
BOOL _shouldUpdateScrollEdgeEffects;
RNSScreen *_controllerBeforeInvalidate;
#ifdef RCT_NEW_ARCH_ENABLED
RCTSurfaceTouchHandler *_touchHandler;
react::RNSScreenShadowNode::ConcreteState::Shared _state;
Expand Down Expand Up @@ -630,6 +632,26 @@ - (void)notifyWillDisappear
if (_hideKeyboardOnSwipe) {
[self endEditing:YES];
}

// Notify any presented view controllers that conform to RNSLifecycleListenerProtocol
RNSScreen *controller = _controller ?: _controllerBeforeInvalidate;
if (controller) {
UIViewController *presented = controller.presentedViewController;
while (presented) {
UIViewController *next = presented.presentedViewController;
if ([presented conformsToProtocol:@protocol(RNSLifecycleListenerProtocol)]) {
BOOL isPresenterUnmounting = NO;
RNSScreen *presenter = (RNSScreen *)presented.presentingViewController;
if ([presenter isKindOfClass:[RNSScreen class]]) {
isPresenterUnmounting = presenter.screenView.isMarkedForUnmountInCurrentTransaction;
}
[(id<RNSLifecycleListenerProtocol>)presented screenWillDisappear:controller
isPresenterUnmounting:isPresenterUnmounting];
}
presented = next;
}
}

#ifdef RCT_NEW_ARCH_ENABLED
// If screen is already unmounted then there will be no event emitter
if (_eventEmitter != nullptr) {
Expand Down Expand Up @@ -965,6 +987,9 @@ - (BOOL)isTransparentModal

- (void)invalidateImpl
{
if (_controller && !_controllerBeforeInvalidate) {
_controllerBeforeInvalidate = _controller;
}
_controller = nil;
[_sheetsScrollView removeObserver:self forKeyPath:@"bounds" context:nil];
}
Expand Down
14 changes: 14 additions & 0 deletions ios/integrations/RNSLifecycleListenerProtocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@protocol RNSLifecycleListenerProtocol <NSObject>

// Called when a screen in the presenting hierarchy is about to disappear.
// @param screen The screen controller that is disappearing
// @param isPresenterUnmounting YES if the presenter (modal) itself is being unmounted
- (void)screenWillDisappear:(UIViewController *)screen isPresenterUnmounting:(BOOL)isPresenterUnmounting;

@end

NS_ASSUME_NONNULL_END