-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: present during mount guide (#59)
* docs: add initialIndex + react-navigation troubleshooting and guide * chore: deps
- Loading branch information
Showing
13 changed files
with
374 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Presenting During Mount | ||
description: Present the bottom sheet on mount. | ||
keywords: [bottom sheet on mount, bottom sheet initialIndex] | ||
--- | ||
|
||
import onmount from './onmount.gif' | ||
|
||
Sometimes, you may want to present the sheet directly during mount. For example, you might want to present the sheet when a screen is opened through a deep link. | ||
|
||
<img alt="onmount" src={onmount} width="300"/> | ||
|
||
## How? | ||
|
||
You can do this by setting [`initialIndex`](/reference/props#initialindex) prop. It accepts the [`size`](/reference/types#sheetsize) `index` that your sheet is configured with. See [sizes](/reference/props#sizes) prop for more information. | ||
|
||
```tsx {5-6} | ||
const App = () => { | ||
return ( | ||
<TrueSheet | ||
sizes={['auto', '69%', 'large']} | ||
initialIndex={1} | ||
initialindexanimated | ||
> | ||
<View /> | ||
</TrueSheet> | ||
) | ||
} | ||
``` | ||
|
||
### Disabling Animation | ||
|
||
You may want to disable the present animation. To do this, simply set [`initialIndexAnimated`](/reference/props#initialindexanimated) to `false`. | ||
|
||
### Using with React Navigation | ||
|
||
Using this with [`react-navigation`](https://reactnavigation.org) can cause render issue. Check out the [troubleshooting guide](/troubleshooting#present-during-mount) for the fix 😉. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
sidebar_position: 6 | ||
description: Fix common issues when using True Native Bottom Sheet. | ||
keywords: [bottom sheet troubleshooting, fixing bottom sheet, debugging bottom sheet] | ||
--- | ||
|
||
# Troubleshooting | ||
|
||
## React Native Gesture Handler | ||
|
||
[`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/docs/) | ||
|
||
On Android, [RNGH does not work](https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation/#usage-with-modals-on-android) by default because modals are not located under React Native Root view in native hierarchy. To fix that, components need to be wrapped with `GestureHandlerRootView`. | ||
|
||
```tsx | ||
import { GestureHandlerRootView } from 'react-native-gesture-handler' | ||
``` | ||
|
||
```tsx | ||
return ( | ||
<TrueSheet ref={sheet}> | ||
<GestureHandlerRootView> | ||
<View /> | ||
</GestureHandlerRootView> | ||
</TrueSheet> | ||
) | ||
``` | ||
|
||
## React Navigation | ||
|
||
[`react-navigation`](https://reactnavigation.org) | ||
|
||
### Navigation Crash | ||
|
||
On IOS, navigating to a screen from within the Sheet can cause issues. To resolve this, dismiss the sheet before navigating! | ||
|
||
Example: | ||
```tsx | ||
const sheet = useRef<TrueSheet>(null) | ||
|
||
const navigate = async () => { | ||
await sheet.current?.dismiss() // wait for the sheet to dismiss ✅ | ||
navigation.navigate('SomeScreen') // navigate to the screen 🎉 | ||
} | ||
|
||
return ( | ||
<TrueSheet ref={sheet}> | ||
<Button onPress={navigate} title="Navigate to SomeScreen" /> | ||
<View /> | ||
</TrueSheet> | ||
) | ||
``` | ||
|
||
### Present during Mount | ||
|
||
On iOS, when setting [`initialIndex`](/reference/props#initialindex) and enabling `initialIndexAnimated` (default is `true`) to present during mount, the presentation animation becomes weird. This happens because RNN is not yet finished when the sheet is trying to present. | ||
|
||
To solve this, you can do the following: | ||
|
||
1. Set `initialIndexAnimated` to `false`. Disables animation during mount. | ||
|
||
```tsx | ||
return ( | ||
<TrueSheet initialIndex={0} initialIndexAnimated={false}> | ||
<View /> | ||
</TrueSheet> | ||
) | ||
``` | ||
|
||
2. Wait for the screen to fully transition. See [`transitionEnd`](https://reactnavigation.org/docs/native-stack-navigator/#transitionend) event. | ||
|
||
```tsx | ||
const navigation = useNavigation() | ||
const [isScreenShown, setIsScreenShown] = useState(false) | ||
|
||
// Subscribe to the transitionEnd event ✅ | ||
useEffect(() => { | ||
const unsubscribe = navigation.addListener("transitionEnd", ({ data }) => { | ||
if (!data.closing) { | ||
setIsScreenShown(true) | ||
} | ||
}) | ||
|
||
return unsubscribe | ||
}, []) | ||
|
||
// Wait for the screen to finish transitioning ✅ | ||
if (!isScreenShown) return null | ||
|
||
// Finally show the sheet 🎉 | ||
return ( | ||
<TrueSheet initialIndex={0} initialIndexAnimated> | ||
<View /> | ||
</TrueSheet> | ||
) | ||
``` | ||
|
||
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.