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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### 🐛 Bug fixes

- **iOS**: Navigating to a modal screen while the sheet is dismissing now opens the modal once the sheet is gone. With the patched `react-native-screens`, the modal never opened and no other modal could open until the app restarted. ([#1019](https://github.com/lodev09/react-native-true-sheet/pull/1019) by [@JacquesLeupin](https://github.com/JacquesLeupin))
- **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))
- **Android**: A sheet whose keyboard starts rising as the present slide ends, such as one that focuses an input around `onWillPresent`, now finishes presenting. It used to never fire `onDidPresent` or resolve `present()`, and kept swallowing taps. ([#1012](https://github.com/lodev09/react-native-true-sheet/pull/1012) by [@JacquesLeupin](https://github.com/JacquesLeupin))
- **Android**: When a sheet presented over another sheet changes its content size right before it dismisses, the sheet behind it now slides back instead of staying pushed down and not draggable. ([#1015](https://github.com/lodev09/react-native-true-sheet/pull/1015) by [@idlework](https://github.com/idlework))
- **Android**: The keyboard no longer counts against `maxContentHeight`, as on iOS. A sheet now rises above the keyboard instead of stopping at `maxContentHeight` with the keyboard covering the bottom of its content, such as a button below a text input. A sheet already at `maxContentHeight` now rises with the keyboard too, instead of staying put. ([#1017](https://github.com/lodev09/react-native-true-sheet/pull/1017) by [@wildseansy](https://github.com/wildseansy))
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