diff --git a/docs/docs/troubleshooting.mdx b/docs/docs/troubleshooting.mdx index 78f21c86..26bd0f2f 100644 --- a/docs/docs/troubleshooting.mdx +++ b/docs/docs/troubleshooting.mdx @@ -69,6 +69,28 @@ Related: [#354](https://github.com/lodev09/react-native-true-sheet/issues/354) A fix has been submitted to Unistyles. See [PR #1061](https://github.com/jpudysz/react-native-unistyles/pull/1061). ::: +## Blank Screen When Dismissing React Native Modal on iOS + +When presenting a TrueSheet on top of a React Native `` and then dismissing the Modal (by setting `visible={false}`), the screen may go blank. This is a bug in React Native where dismissing a Modal that has another view controller presented on top of it only dismisses the topmost view controller, leaving the Modal in an inconsistent state. + +**Workaround:** + +Dismiss the sheet first before hiding the Modal: + +```tsx +const sheet = useRef(null) +const [modalVisible, setModalVisible] = useState(false) + +const closeModal = async () => { + await sheet.current?.dismiss() + setModalVisible(false) +} +``` + +:::info +A fix has been submitted to React Native. See [PR #55005](https://github.com/facebook/react-native/pull/55005). +::: + ## Weird layout render The sheet does not have control over how React Native renders components and may lead to rendering issues. To resolve this, try to minimize the use of `flex=1` in your content styles. Instead, use fixed `height` or employ `flexGrow`, `flexBasis`, etc., to manage your layout requirements. diff --git a/example/shared/src/screens/ModalScreen.tsx b/example/shared/src/screens/ModalScreen.tsx index 55922f40..b2f2eb44 100644 --- a/example/shared/src/screens/ModalScreen.tsx +++ b/example/shared/src/screens/ModalScreen.tsx @@ -1,9 +1,9 @@ -import { useRef } from 'react'; -import { StyleSheet, Text, View } from 'react-native'; -import { TrueSheetProvider, type TrueSheet } from '@lodev09/react-native-true-sheet'; +import { useRef, useState, useEffect } from 'react'; +import { Modal, StyleSheet, Text, View } from 'react-native'; +import { TrueSheet, TrueSheetProvider } from '@lodev09/react-native-true-sheet'; -import { BLUE, GAP, LIGHT_GRAY, SPACING } from '../utils'; -import { Button, Input, Spacer } from '../components'; +import { BLUE, DARK, DARK_BLUE, DARK_GRAY, GAP, LIGHT_GRAY, SPACING } from '../utils'; +import { Button, DemoContent, Input, Spacer } from '../components'; import { PromptSheet, FlatListSheet } from '../components/sheets'; export interface ModalScreenProps { @@ -15,6 +15,16 @@ export const ModalScreen = ({ onNavigateToTest, onDismiss }: ModalScreenProps) = const promptSheet = useRef(null); const flatlistSheet = useRef(null); + const [modalVisible, setModalVisible] = useState(false); + const modalSimpleSheet = useRef(null); + const modalFlatlistSheet = useRef(null); + + useEffect(() => { + if (modalVisible) { + modalSimpleSheet.current?.present(); + } + }, [modalVisible]); + return ( @@ -28,11 +38,46 @@ export const ModalScreen = ({ onNavigateToTest, onDismiss }: ModalScreenProps) =