diff --git a/example/src/App.tsx b/example/src/App.tsx index 925aae4..f0b5996 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -9,7 +9,7 @@ import { SafeAreaProvider } from 'react-native-safe-area-context'; import { UserProvider } from './context/UserContext'; import { HomeScreen } from './screens'; -import { ScannerSheet } from './sheets'; +import { PersistentWithPortalSheet, ScannerSheet } from './sheets'; import { sharedStyles } from './styles/theme'; export default function App() { @@ -30,6 +30,10 @@ export default function App() { + {/* Persistent sheet with nested portal sheet inside */} + + + diff --git a/example/src/bottom-sheet.d.ts b/example/src/bottom-sheet.d.ts index ef2dc84..2bcd64e 100644 --- a/example/src/bottom-sheet.d.ts +++ b/example/src/bottom-sheet.d.ts @@ -11,5 +11,9 @@ declare module 'react-native-bottom-sheet-stack' { source: 'home' | 'navigation'; title?: string; }; + 'persistent-with-portal': true; + 'nested-portal-in-persistent': { + message: string; + }; } } diff --git a/example/src/screens/HomeScreen.tsx b/example/src/screens/HomeScreen.tsx index 5f84839..6826e94 100644 --- a/example/src/screens/HomeScreen.tsx +++ b/example/src/screens/HomeScreen.tsx @@ -24,6 +24,9 @@ export function HomeScreen() { const portalSheetControl = useBottomSheetControl('context-portal-sheet'); const portalModeSheetA = useBottomSheetControl('portal-mode-sheet-a'); const scannerControl = useBottomSheetControl('scanner-sheet'); + const persistentWithPortalControl = useBottomSheetControl( + 'persistent-with-portal' + ); return ( @@ -125,6 +128,15 @@ export function HomeScreen() { }) } /> + + + persistentWithPortalControl.open({ scaleBackground: true }) + } + /> {/* Features */} diff --git a/example/src/sheets/PersistentWithNestedPortal.tsx b/example/src/sheets/PersistentWithNestedPortal.tsx new file mode 100644 index 0000000..0db4f47 --- /dev/null +++ b/example/src/sheets/PersistentWithNestedPortal.tsx @@ -0,0 +1,212 @@ +import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types'; +import { forwardRef, useState } from 'react'; +import { StyleSheet, Text, View } from 'react-native'; +import { + BottomSheetPortal, + useBottomSheetContext, + useBottomSheetControl, +} from 'react-native-bottom-sheet-stack'; + +import { Badge, Button, SecondaryButton, Sheet } from '../components'; +import { colors, sharedStyles } from '../styles/theme'; + +/** + * Nested portal sheet content - defined inside the persistent sheet + * to demonstrate portal sheets can be declared within other sheets + */ +const NestedPortalSheetContent = forwardRef((_, ref) => { + const { close, params } = + useBottomSheetContext<'nested-portal-in-persistent'>(); + const [counter, setCounter] = useState(0); + + return ( + + + + + + Nested Portal Sheet + + This portal-based sheet is defined inside the persistent sheet. It has + access to the same React context as its parent. + + + {params?.message && ( + + Message from parent: + {params.message} + + )} + + + Local counter: + {counter} + + + +