Skip to content

Commit 16e96d7

Browse files
committed
fix(ios): dismiss sheets properly during navigation and reload
- Remove dismiss from prepareForRecycle to not interfere with RNSScreenStack - Keep dismiss in dealloc for reload cleanup - Walk up presentation chain in dealloc to dismiss entire sheet stack
1 parent 9ecec14 commit 16e96d7

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

example/shared/src/components/sheets/PromptSheet.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const PromptSheet = forwardRef((props: PromptSheetProps, ref: Ref<TrueShe
4747
`Sheet prompt presented at index: ${e.nativeEvent.index}, position: ${e.nativeEvent.position}`
4848
);
4949

50-
inputRef.current?.focus();
50+
// inputRef.current?.focus();
5151
}}
5252
onDetentChange={(e) =>
5353
console.log(

example/shared/src/screens/ModalScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const ModalScreen = ({ onNavigateToTest, onDismiss }: ModalScreenProps) =
1818
return (
1919
<TrueSheetProvider>
2020
<View style={styles.content}>
21+
<Button text="Dismiss Modal" onPress={onDismiss} />
2122
<View style={styles.heading}>
2223
<Text style={styles.title}>Modal Screen</Text>
2324
<Text style={styles.subtitle}>
@@ -29,7 +30,6 @@ export const ModalScreen = ({ onNavigateToTest, onDismiss }: ModalScreenProps) =
2930
<Button text="TrueSheet FlatList" onPress={() => flatlistSheet.current?.present()} />
3031
<Spacer />
3132
<Button text="Navigate Test" onPress={onNavigateToTest} />
32-
<Button text="Dismiss Modal" onPress={onDismiss} />
3333

3434
<PromptSheet initialDetentIndex={0} ref={promptSheet} dimmed={false} />
3535
<FlatListSheet ref={flatlistSheet} />

ios/TrueSheetView.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ - (void)didMoveToWindow {
9696

9797
- (void)dealloc {
9898
if (_controller && _controller.presentingViewController) {
99-
[_controller dismissViewControllerAnimated:NO completion:nil];
99+
// Find the root presenting controller to dismiss the entire stack
100+
UIViewController *root = _controller.presentingViewController;
101+
while (root.presentingViewController != nil) {
102+
root = root.presentingViewController;
103+
}
104+
[root dismissViewControllerAnimated:YES completion:nil];
100105
}
101106

102107
_controller.delegate = nil;
@@ -258,10 +263,6 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
258263
- (void)prepareForRecycle {
259264
[super prepareForRecycle];
260265

261-
if (_controller && _controller.presentingViewController) {
262-
[_controller dismissViewControllerAnimated:YES completion:nil];
263-
}
264-
265266
[TrueSheetModule unregisterViewWithTag:@(self.tag)];
266267

267268
_lastStateSize = CGSizeZero;

0 commit comments

Comments
 (0)