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
3 changes: 2 additions & 1 deletion ios/RNSScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace react = facebook::react;

@class RNSScreenView;

@interface RNSScreen : UIViewController <RNSViewControllerDelegate>
@interface RNSScreen : UIViewController <RNSViewControllerDelegate, UIAdaptivePresentationControllerDelegate>

- (instancetype)initWithView:(UIView *)view;
- (UIViewController *)findChildVCForConfigAndTrait:(RNSWindowTrait)trait includingModals:(BOOL)includingModals;
Expand Down Expand Up @@ -108,6 +108,7 @@ namespace react = facebook::react;
@property (nonatomic, copy) RCTDirectEventBlock onNativeDismissCancelled;
@property (nonatomic, copy) RCTDirectEventBlock onTransitionProgress;
@property (nonatomic, copy) RCTDirectEventBlock onGestureCancel;
@property (nonatomic, copy) RCTDirectEventBlock onModalDismiss;
#endif // RCT_NEW_ARCH_ENABLED

- (void)notifyFinishTransitioning;
Expand Down
17 changes: 17 additions & 0 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ - (void)setGestureEnabled:(BOOL)gestureEnabled
_gestureEnabled = gestureEnabled;
}

- (void)setOnModalDismiss:(RCTDirectEventBlock)onModalDismiss {
_onModalDismiss = onModalDismiss;
if (@available(iOS 13.0, tvOS 13.0, *)) {
_controller.modalInPresentation = onModalDismiss != nil;
}
}

- (void)setReplaceAnimation:(RNSScreenReplaceAnimation)replaceAnimation
{
_replaceAnimation = replaceAnimation;
Expand Down Expand Up @@ -977,6 +984,7 @@ - (void)viewDidAppear:(BOOL)animated

_isSwiping = NO;
_shouldNotify = YES;
self.presentationController.delegate = self;
}

- (void)viewDidDisappear:(BOOL)animated
Expand Down Expand Up @@ -1168,6 +1176,14 @@ - (id)findFirstResponder:(UIView *)parent
return nil;
}

#pragma mark - UIAdaptivePresentationControllerDelegate

- (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)presentationController {
if (self.screenView.onModalDismiss) {
self.screenView.onModalDismiss(nil);
}
}

#pragma mark - transition progress related methods

- (void)setupProgressNotification
Expand Down Expand Up @@ -1462,6 +1478,7 @@ @implementation RNSScreenManager
RCT_EXPORT_VIEW_PROPERTY(onWillAppear, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onWillDisappear, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onGestureCancel, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDismiss, RCTDirectEventBlock);

#if !TARGET_OS_TV
RCT_EXPORT_VIEW_PROPERTY(screenOrientation, UIInterfaceOrientationMask)
Expand Down
6 changes: 6 additions & 0 deletions src/native-stack/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ export type NativeStackNavigationOptions = {
* @platform ios
*/
transitionDuration?: number;
/**
* A callback that gets is called when an attempt is made to dismiss the presented view controller.
*
* @platform ios
*/
onModalDismiss?: () => void;
};

export type NativeStackNavigatorProps =
Expand Down
2 changes: 2 additions & 0 deletions src/native-stack/views/NativeStackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const RouteView = ({
swipeDirection = 'horizontal',
transitionDuration,
freezeOnBlur,
onModalDismiss,
} = options;

let {
Expand Down Expand Up @@ -277,6 +278,7 @@ const RouteView = ({
sheetExpandsWhenScrolledToEdge={sheetExpandsWhenScrolledToEdge}
customAnimationOnSwipe={customAnimationOnSwipe}
freezeOnBlur={freezeOnBlur}
onModalDismiss={onModalDismiss}
fullScreenSwipeEnabled={fullScreenSwipeEnabled}
hideKeyboardOnSwipe={hideKeyboardOnSwipe}
homeIndicatorHidden={homeIndicatorHidden}
Expand Down
7 changes: 7 additions & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ export interface ScreenProps extends ViewProps {
* A callback that gets called when the current screen disappears.
*/
onDisappear?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
/**
/**
* A callback that gets is called when an attempt is made to dismiss the presented view controller.
*
* @platform ios
*/
onModalDismiss?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
/**
* A callback that gets called when the current screen is dismissed by hardware back (on Android) or dismiss gesture (swipe back or down).
* The callback takes the number of dismissed screens as an argument since iOS 14 native header back button can pop more than 1 screen at a time.
Expand Down