Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### 🐛 Bug fixes

- **iOS**: A sheet navigator sheet opened while the base screen shows a `fullScreenModal` now presents over the modal. It used to never appear, its `dismiss()` rejected with "No sheet found", and the half-open route kept the modal from closing through the navigator. A sheet rendered beside the navigation tree, such as a root-level named sheet, now presents over a `fullScreenModal` too. ([#1021](https://github.com/lodev09/react-native-true-sheet/pull/1021) by [@maxlapides](https://github.com/maxlapides))

### 💡 Others

- The Expo example in `example/expo` now runs SDK 58, and the SDK 57 example moves to `example/expo-57` (`yarn expo-57`). The bare example is upgraded to React Native 0.88. ([#1016](https://github.com/lodev09/react-native-true-sheet/pull/1016) by [@lodev09](https://github.com/lodev09))
Expand Down
29 changes: 29 additions & 0 deletions example/bare/src/navigators/SheetNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,35 @@ const HomeScreen = () => {
<Button text="Open Small Footer Sheet" onPress={() => navigation.navigate('SmallFooter')} />
<Button text="Open Peek Sheet" onPress={() => navigation.navigate('Peek')} />
<Button text="Navigate to Test" onPress={() => navigation.navigate('Test')} />
<Button
text="Open Full Screen Modal"
onPress={() => navigation.navigate('SheetHomeStack', { screen: 'FullScreenModal' })}
/>
<Button text="Go Back" onPress={() => navigation.goBack()} />
</View>
);
};

// Repro: a sheet route opened while a fullScreenModal covers the navigator's base.
const FullScreenModalScreen = () => {
const navigation = useTrueSheetNavigation<AppStackParamList & SheetStackParamList>();

return (
<View style={styles.content}>
<View style={styles.heading}>
<Text style={styles.title}>Full Screen Modal</Text>
<Text style={styles.subtitle}>
A fullScreenModal inside the sheet navigator's base screen. Sheets opened from here
present over it.
</Text>
</View>
<Button text="Open Details Sheet" onPress={() => navigation.navigate('Details')} />
<Button text="Open Settings Sheet" onPress={() => navigation.navigate('Settings')} />
<Button text="Close Modal" onPress={() => navigation.goBack()} />
</View>
);
};

const TestScreenWrapper = () => {
const navigation = useAppNavigation();
return <TestScreen onGoBack={() => navigation.goBack()} />;
Expand All @@ -61,6 +85,11 @@ const SheetHomeNavigator = () => {
>
<SheetHomeStack.Screen name="Home" component={HomeScreen} />
<SheetHomeStack.Screen name="Test" component={TestScreenWrapper} />
<SheetHomeStack.Screen
name="FullScreenModal"
component={FullScreenModalScreen}
options={{ presentation: 'fullScreenModal', headerShown: false }}
/>
</SheetHomeStack.Navigator>
);
};
Expand Down
1 change: 1 addition & 0 deletions example/bare/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export type SheetStackParamList = {
export type SheetHomeStackParamList = {
Home: undefined;
Test: undefined;
FullScreenModal: undefined;
};
53 changes: 42 additions & 11 deletions ios/TrueSheetView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#import <React/RCTLog.h>
#import <React/RCTSurfaceTouchHandler.h>
#import <React/RCTUtils.h>
#import <React/UIView+React.h>
#import <react/renderer/core/State.h>

using namespace facebook::react;
Expand Down Expand Up @@ -119,10 +120,6 @@ - (void)didMoveToWindow {
if (!self.window)
return;

if (self.tag > 0) {
[TrueSheetModule registerView:self withTag:@(self.tag)];
}

if (_pendingNavigationRepresent && !_controller.isPresented) {
_pendingNavigationRepresent = NO;
[self presentAtIndex:_controller.activeDetentIndex animated:YES completion:nil];
Expand All @@ -144,7 +141,7 @@ - (void)presentInitialIfNeeded {
UIViewController *vc = [self findPresentingViewController];

// Only present if the view controller is in the same window
if (!vc || vc.view.window != self.window) {
if (!vc || vc.view.window != [self presentationWindow]) {
// Animate next time when sheet finally moves to the correct window
_initialDetentAnimated = YES;
return;
Expand Down Expand Up @@ -427,6 +424,12 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
if (!(updateMask & RNComponentViewUpdateMaskProps) || !_controller)
return;

// Registered on mount, not on window attach: a host mounted under a
// full-screen modal has no window yet but must still answer dismiss().
if (self.tag > 0) {
[TrueSheetModule registerView:self withTag:@(self.tag)];
}

[self setupScrollable];

if (_controller.isPresented) {
Expand All @@ -436,7 +439,7 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
_pendingPropsUpdate = YES;
} else if (_initialDetentIndex >= 0) {
_pendingLayoutUpdate = NO;
if (self.window) {
if ([self presentationWindow]) {
[self presentInitialIfNeeded];
}
}
Expand All @@ -460,7 +463,7 @@ - (void)prepareForRecycle {

strongSelf->_controller.delegate = strongSelf;
strongSelf->_controller.activeDetentIndex = -1;
if (strongSelf.window) {
if ([strongSelf presentationWindow]) {
[strongSelf presentInitialIfNeeded];
}
});
Expand Down Expand Up @@ -1046,7 +1049,7 @@ - (void)presenterScreenWillDisappear {

- (void)presenterScreenWillAppear {
if (_dismissedByNavigation && !_controller.isPresented && !_controller.isBeingPresented) {
if (self.window) {
if ([self presentationWindow]) {
[self presentAtIndex:_controller.activeDetentIndex animated:YES completion:nil];
} else {
_pendingNavigationRepresent = YES;
Expand Down Expand Up @@ -1153,11 +1156,39 @@ - (void)applySheetPropsUpdate {
[_controller setupDraggable];
}

- (UIViewController *)findPresentingViewController {
if (!self.window)
/**
* The window this sheet presents in. A full-screen modal takes the views under
* it out of the window. A sheet hosted beside the stack that presented it (e.g. a
* sheet navigator's sheet, next to its base screen) still sits above that stack,
* so it presents in the modal's window. A sheet inside that stack waits for its
* screen to come back.
*/
- (nullable UIWindow *)presentationWindow {
if (self.window)
return self.window;

UIView *rootView = self;
while (rootView.superview) {
rootView = rootView.superview;
}

// A detached view controller's root view still responds through its controller
UIResponder *responder = rootView.nextResponder;
if (![responder isKindOfClass:[UIViewController class]])
return nil;

UIViewController *rootViewController = self.window.rootViewController;
// react-native-screens keeps a presented screen's reactSuperview on its stack
UIViewController *modal = ((UIViewController *)responder).presentedViewController;
UIView *presentingStack = modal.viewIfLoaded.reactSuperview;
if (modal.isBeingDismissed || ![presentingStack isDescendantOfView:rootView] ||
[self isDescendantOfView:presentingStack])
return nil;

return modal.view.window;
}

- (UIViewController *)findPresentingViewController {
UIViewController *rootViewController = [self presentationWindow].rootViewController;
if (!rootViewController)
return nil;

Expand Down
Loading