From 2db492807b463e20aee67bfbd933dab2ce1c2411 Mon Sep 17 00:00:00 2001 From: Samuel Brucksch Date: Tue, 17 Nov 2026 12:00:46 +0100 Subject: [PATCH 1/2] fix(android): resolve resize and dismiss when the native view is gone onHostDestroy drops the view from the module's registry, but when the activity is destroyed while the JS runtime keeps running, the JS sheet stays mounted. resize(), dismiss() and dismissStack() then reject with VIEW_NOT_FOUND, which surfaces as an unhandled rejection when callers don't await them. Ignore VIEW_NOT_FOUND / SHEET_NOT_FOUND in those three methods; present() still rejects. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + jest.setup.js | 2 ++ src/TrueSheet.tsx | 16 +++++++++++--- src/__tests__/TrueSheet.test.tsx | 37 ++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 868e8cabc..5cd742fa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - **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)) +- **Android**: Calling `resize()`, `dismiss()` or `dismissStack()` on a sheet whose native view is already gone, for example after the activity was destroyed while JS kept running, now resolves instead of rejecting with "TrueSheetView with tag X not found". `present()` still rejects. ([#PR_NUMBER](https://github.com/lodev09/react-native-true-sheet/pull/PR_NUMBER) by [@SamuelBrucksch](https://github.com/SamuelBrucksch)) ### 💡 Others diff --git a/jest.setup.js b/jest.setup.js index 5ce5e6c2b..29dbf7c74 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -6,6 +6,8 @@ jest.mock('./src/specs/NativeTrueSheetModule', () => ({ default: { presentByRef: jest.fn(), dismissByRef: jest.fn(), + dismissStackByRef: jest.fn(), + resizeByRef: jest.fn(), dismissAll: jest.fn(), handleBackPress: jest.fn(), }, diff --git a/src/TrueSheet.tsx b/src/TrueSheet.tsx index 869d46757..40c83c822 100644 --- a/src/TrueSheet.tsx +++ b/src/TrueSheet.tsx @@ -99,6 +99,16 @@ const stopResponderNegotiation = (event: GestureResponderEvent) => { return false; }; +// The native view can be dropped while JS still holds the sheet (e.g. the Android +// activity is destroyed but the JS runtime keeps running). Native then rejects with +// VIEW_NOT_FOUND (Android) or SHEET_NOT_FOUND (iOS). A sheet that no longer exists +// has nothing left to resize or dismiss, so those calls resolve instead. +const ignoreMissingView = (error: unknown): void => { + const code = (error as { code?: unknown } | null)?.code; + if (code === 'VIEW_NOT_FOUND' || code === 'SHEET_NOT_FOUND') return; + throw error; +}; + interface TrueSheetState { shouldRenderNativeView: boolean; initialPresentReady: boolean; @@ -550,7 +560,7 @@ export class TrueSheet * @param index - The detent index to resize to */ public async resize(index: number): Promise { - await TrueSheetModule?.resizeByRef(this.handle, index); + await TrueSheetModule?.resizeByRef(this.handle, index).catch(ignoreMissingView); } /** @@ -561,7 +571,7 @@ export class TrueSheet // Dismissing before the lazy mount finishes cancels the present — nothing was presented if (this.cancelPendingPresent()) return; - return TrueSheetModule?.dismissByRef(this.handle, animated); + return TrueSheetModule?.dismissByRef(this.handle, animated).catch(ignoreMissingView); } /** @@ -570,7 +580,7 @@ export class TrueSheet * @param animated - Whether to animate the dismissal (default: true) */ public async dismissStack(animated: boolean = true): Promise { - return TrueSheetModule?.dismissStackByRef(this.handle, animated); + return TrueSheetModule?.dismissStackByRef(this.handle, animated).catch(ignoreMissingView); } componentDidMount(): void { diff --git a/src/__tests__/TrueSheet.test.tsx b/src/__tests__/TrueSheet.test.tsx index 5c2bfd62f..5d3c21620 100644 --- a/src/__tests__/TrueSheet.test.tsx +++ b/src/__tests__/TrueSheet.test.tsx @@ -806,6 +806,43 @@ describe('TrueSheet', () => { }); }); + describe('Missing native view', () => { + const missingView = (code: string) => + Object.assign(new Error('TrueSheetView with tag 1 not found'), { code }); + + const renderSheet = (name: string) => { + render( + + Content + + ); + return TrueSheet['instances'][name]!; + }; + + it.each(['VIEW_NOT_FOUND', 'SHEET_NOT_FOUND'])( + 'should resolve resize, dismiss and dismissStack on %s', + async (code) => { + const sheetRef = renderSheet(`missing-view-${code}`); + + jest.mocked(TrueSheetModule!.resizeByRef).mockRejectedValueOnce(missingView(code)); + jest.mocked(TrueSheetModule!.dismissByRef).mockRejectedValueOnce(missingView(code)); + jest.mocked(TrueSheetModule!.dismissStackByRef).mockRejectedValueOnce(missingView(code)); + + await expect(sheetRef.resize(0)).resolves.toBeUndefined(); + await expect(sheetRef.dismiss()).resolves.toBeUndefined(); + await expect(sheetRef.dismissStack()).resolves.toBeUndefined(); + } + ); + + it('should still reject other native errors', async () => { + const sheetRef = renderSheet('missing-view-other-error'); + const error = Object.assign(new Error('Failed to resize'), { code: 'RESIZE_FAILED' }); + jest.mocked(TrueSheetModule!.resizeByRef).mockRejectedValueOnce(error); + + await expect(sheetRef.resize(0)).rejects.toBe(error); + }); + }); + describe('Focus/Blur Events', () => { it('should call onWillFocus when triggered', async () => { const onWillFocusMock = jest.fn(); From baae4b21cb5a424bf2a1818c3473d754387710d2 Mon Sep 17 00:00:00 2001 From: Samuel Brucksch Date: Tue, 17 Nov 2026 12:00:46 +0100 Subject: [PATCH 2/2] docs: add changelog entry for #1026 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd742fa4..5c62f827d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - **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)) -- **Android**: Calling `resize()`, `dismiss()` or `dismissStack()` on a sheet whose native view is already gone, for example after the activity was destroyed while JS kept running, now resolves instead of rejecting with "TrueSheetView with tag X not found". `present()` still rejects. ([#PR_NUMBER](https://github.com/lodev09/react-native-true-sheet/pull/PR_NUMBER) by [@SamuelBrucksch](https://github.com/SamuelBrucksch)) +- **Android**: Calling `resize()`, `dismiss()` or `dismissStack()` on a sheet whose native view is already gone, for example after the activity was destroyed while JS kept running, now resolves instead of rejecting with "TrueSheetView with tag X not found". `present()` still rejects. ([#1026](https://github.com/lodev09/react-native-true-sheet/pull/1026) by [@SamuelBrucksch](https://github.com/SamuelBrucksch)) ### 💡 Others