Skip to content

Commit 6f2274a

Browse files
authored
Docs (#8)
* docs: add docs * docs: fix link * docs: part 2
1 parent 1ac6ca9 commit 6f2274a

32 files changed

+9182
-1272
lines changed

README.md

Lines changed: 5 additions & 302 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ yarn add @lodev09/react-native-true-sheet
2828
npm i @lodev09/react-native-true-sheet
2929
```
3030

31-
> This package is not compatible with [Expo Go](https://docs.expo.dev/get-started/expo-go/). Use this with [Expo CNG](https://docs.expo.dev/workflow/continuous-native-generation/) instead.
31+
## Documentation
32+
33+
- [Guides](https://sheet.lodev09.com/category/guides)
34+
- [Reference](https://sheet.lodev09.com/category/reference)
35+
- [Example](example)
3236

3337
## Usage
3438

@@ -58,307 +62,6 @@ return (
5862
)
5963
```
6064

61-
## Options
62-
63-
Props available for `TrueSheet`.
64-
Extends `ViewProps`
65-
66-
| Prop | Type | Default | Description | 🍎 | 🤖 |
67-
| - | - | - | - | - | - |
68-
| sizes | [`SheetSize[]`](#sheetsize) | `["medium", "large"]` | Array of sizes you want the sheet to support. Maximum of _**3 sizes**_ only! **_collapsed_**, **_half-expanded_**, and **_expanded_**. Example: `size={["auto", "60%", "large"]}`|||
69-
| name | `string` | - | The name to reference this sheet. It has to be **_unique_**. You can then present this sheet globally using its name. |||
70-
| backgroundColor | `ColorValue` | `"white"` | The sheet's background color. |||
71-
| cornerRadius | `number` | - | the sheet corner radius. |||
72-
| maxHeight | `number` | - | Overrides `"large"` or `"100%"` height. |||
73-
| contentContainerStyle | `StyleProp<ViewStyle>` | - | Optional content container styles. |||
74-
| FooterComponent | `ComponentType<...> \| ReactElement` | - | A component that floats at the bottom of the sheet. Accepts a functional `Component` or `ReactElement`. |||
75-
| dismissible | `boolean` | `true` | If set to `false`, the sheet will prevent interactive dismissal via dragging or clicking outside of it. |||
76-
| grabber | `boolean` | `true` | Shows a grabber (or handle). Native on IOS and styled `View` on Android. |||
77-
| grabberProps | [`TrueSheetGrabberProps`](#truesheetgrabberprops) | - | Overrides the grabber props for android. | ||
78-
| blurTint | [`BlurTint`](#blurtint) | - | The blur effect style on IOS. Overrides `backgroundColor` if set. Example: `"light"`, `"dark"`, etc. || |
79-
| scrollRef | `RefObject<...>` | - | The main scrollable ref that the sheet should handle on IOS. || |
80-
81-
## Methods
82-
83-
```tsx
84-
const sheet = useRef<TrueSheet>(null)
85-
86-
const resize = () => {
87-
sheet.current?.resize(1)
88-
}
89-
90-
const dismiss = () => {
91-
sheet.current?.dismiss()
92-
}
93-
94-
return (
95-
<View>
96-
<Button onPress={resize} title="Resize to 80%" />
97-
<Button onPress={dismiss} title="Dimiss" />
98-
<TrueSheet sizes={['auto', '80%']} ref={sheet}>
99-
// ...
100-
</TrueSheet>
101-
</View>
102-
)
103-
```
104-
105-
| Name | Parameters | Description |
106-
| - | - | - |
107-
| present | `index: number = 0` | Present the modal sheet. Optionally accepts a size `index`. See `sizes` prop. |
108-
| resize | `index: number` | Resizes the sheet programmatically by `index`. This is an alias of the `present(index)` method. |
109-
| dismiss | - | Dismisses the sheet. |
110-
111-
### Static Methods
112-
113-
You can also call the above methods statically without having access to a sheet's `ref`. This is particularly useful when you want to present a sheet from anywhere.
114-
115-
The API is similar to the ref methods except for the required `name` prop.
116-
117-
```ts
118-
TrueSheet.present('SHEET-NAME')
119-
TrueSheet.dismiss('SHEET-NAME')
120-
TrueSheet.resize('SHEET-NAME', 1)
121-
```
122-
123-
Example:
124-
```tsx
125-
// Define the sheet as usual
126-
<TrueSheet name="my-sheet">
127-
// ...
128-
</TrueSheet>
129-
```
130-
```tsx
131-
// Somewhere in your screen
132-
const presentMySheet = async () => {
133-
await TrueSheet.present('my-sheet')
134-
console.log('🎉')
135-
}
136-
137-
return (
138-
<Button onPress={presentMySheet} />
139-
)
140-
```
141-
142-
## Events
143-
144-
```tsx
145-
const handleSizeChange = (info: SizeInfo) => {
146-
console.log(info)
147-
}
148-
149-
return (
150-
<TrueSheet onSizeChange={handleSizeChange} sizes={['auto', '80%']} ref={sheet}>
151-
// ...
152-
</TrueSheet>
153-
)
154-
```
155-
156-
| Name | Parameters | Description |
157-
| - | - | - |
158-
| onPresent | [`SizeInfo`](#sizeinfo) | Called when the sheet has been presented. Comes with the size index and value. |
159-
| onDismiss | - | Called when the sheet has been dismissed. |
160-
| onSizeChange | [`SizeInfo`](#sizeinfo) | Called when the size of the sheet has changed. Either by dragging or presenting programatically. Comes with the size index and value. |
161-
162-
## Types
163-
164-
### `SheetSize`
165-
166-
```tsx
167-
<TrueSheet sizes={['auto', '80%', 'large']}>
168-
// ...
169-
</TrueSheet>
170-
```
171-
172-
| Value | Description | 🍎 | 🤖 |
173-
| - | - | - | - |
174-
| `"auto"` | Auto resize based on content height. | **_16+_** ||
175-
| `"small"` | Translates to 25% | **_16+_** ||
176-
| `"medium"` | Translates to 50% | **_15+_** ||
177-
| `"large"` | Translates to 100% |||
178-
| `"${number}%"` | Fixed height in % | **_16+_** ||
179-
| `number` | Fixed height | **_16+_** ||
180-
181-
> [!NOTE]
182-
> `auto` is not guaranteed to be accurate if your content depends on various rendering logic. Experiment with it and try to keep your content size as fixed as possible.
183-
>
184-
> Alternatively, you can programmatically call [`resize`](#methods) to adjust the sheet size on-the-fly.
185-
186-
### `TrueSheetGrabberProps`
187-
188-
Grabber props to be used for android grabber or handle.
189-
190-
| Prop | Type | Default | Description |
191-
| - | - | - | - |
192-
| visible | `boolean` | `true` | Is grabber visible. |
193-
| color | `ColorValue` | `"rgba(73,69,79,0.4)"` | Grabber color according to M3 specs. |
194-
| height | `number` | `4` | Grabber height according to M3 specs. |
195-
| width | `number` | `32` | Grabber width according to M3 specs. |
196-
| topOffset | `number` | `0` | Grabber top position offset. |
197-
198-
### `BlurTint`
199-
200-
Blur tint that is mapped into native values in IOS.
201-
202-
```tsx
203-
<TrueSheet blurTint="dark">
204-
// ...
205-
</TrueSheet>
206-
```
207-
208-
| Value |
209-
| - |
210-
| `"light"` |
211-
| `"dark"` |
212-
| `"default"` |
213-
| `"extraLight"` |
214-
| `"regular"` |
215-
| `"prominent"` |
216-
| `"systemUltraThinMaterial"` |
217-
| `"systemThinMaterial"` |
218-
| `"systemMaterial"` |
219-
| `"systemThickMaterial"` |
220-
| `"systemChromeMaterial"` |
221-
| `"systemUltraThinMaterialLight"` |
222-
| `"systemThinMaterialLight"` |
223-
| `"systemMaterialLight"` |
224-
| `"systemThickMaterialLight"` |
225-
| `"systemChromeMaterialLight"` |
226-
| `"systemUltraThinMaterialDark"` |
227-
| `"systemThinMaterialDark"` |
228-
| `"systemMaterialDark"` |
229-
| `"systemThickMaterialDark"` |
230-
| `"systemChromeMaterialDark"` |
231-
232-
### `SizeInfo`
233-
234-
`Object` that comes with some events.
235-
236-
```tsx
237-
{
238-
index: 1,
239-
value: 69
240-
}
241-
```
242-
243-
| Property | Type | Description |
244-
| - | - | - |
245-
| index | `number` | The size index from the provided sizes. See `sizes` prop. |
246-
| value | `number` | The actual height value of the size. |
247-
248-
## Testing
249-
250-
When using `jest`, simply mock the entire package.
251-
252-
```tsx
253-
jest.mock('@lodev09/react-native-true-sheet')
254-
```
255-
256-
## Troubleshooting
257-
258-
### Presenting a sheet on top of an existing sheet on **IOS**
259-
260-
On IOS, presenting a sheet on top of an existing sheet will cause error.
261-
262-
```console
263-
Attempt to present <TrueSheet.TrueSheetViewController: 0x11829f800> on <UIViewController: 0x10900eb10> (from <RNSScreen: 0x117dbf400>) which is already presenting <TrueSheet.TrueSheetViewController: 0x11a0b9200>
264-
```
265-
266-
There are _two_ ways to resolve this.
267-
268-
1. Dismiss the "parent" sheet first
269-
```tsx
270-
const presentSheet2 = async () => {
271-
await sheet1.current?.dismiss() // Wait for sheet 1 to dismiss ✅
272-
await sheet2.current?.present() // Sheet 2 will now present 🎉
273-
}
274-
275-
return (
276-
<>
277-
<TrueSheet ref={sheet1}>
278-
<Button onPress={presentSheet2} title="Present Sheet 2" />
279-
// ...
280-
</TrueSheet>
281-
282-
<TrueSheet ref={sheet2}>
283-
// ...
284-
</TrueSheet>
285-
</>
286-
)
287-
```
288-
2. Define the 2nd sheet within the "parent" sheet. IOS handles this automatically by default 😎.
289-
```tsx
290-
const presentSheet2 = async () => {
291-
await sheet2.current?.present() // Sheet 2 will now present 🎉
292-
}
293-
294-
return (
295-
<TrueSheet ref={sheet1}>
296-
<Button onPress={presentSheet2} title="Present Sheet 2" />
297-
298-
// ...
299-
300-
<TrueSheet ref={sheet2}>
301-
// ...
302-
</TrueSheet>
303-
</TrueSheet>
304-
)
305-
```
306-
307-
### Handling `ScrollView` on **Android**
308-
309-
On Android, `nestedScrollEnabled` needs to be enabled so that scrolling works when the sheet is expanded to its `maxHeight`.
310-
311-
```tsx
312-
<TrueSheet ref={sheet}>
313-
<ScrollView nestedScrollEnabled>
314-
// ...
315-
</ScrollView>
316-
</TrueSheet>
317-
```
318-
319-
### Using `react-native-gesture-handler` on **Android**
320-
321-
On Android, RNGH does not work 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`.
322-
323-
Example:
324-
```tsx
325-
import { GestureHandlerRootView } from 'react-native-gesture-handler'
326-
```
327-
```tsx
328-
return (
329-
<TrueSheet ref={sheet}>
330-
<GestureHandlerRootView>
331-
// ...
332-
</GestureHandlerRootView>
333-
</TrueSheet>
334-
)
335-
```
336-
337-
### Integrating `@react-navigation/native` on **IOS**
338-
339-
On IOS, navigating to a [React Navigation](https://reactnavigation.org) screen from within the Sheet can cause issues. To resolve this, dismiss the sheet before navigating!
340-
341-
Example:
342-
```tsx
343-
const sheet = useRef<TrueSheet>(null)
344-
345-
const navigate = async () => {
346-
await sheet.current?.dismiss() // wait for the sheet to dismiss ✅
347-
navigation.navigate('SomeScreen') // navigate to the screen 🎉
348-
}
349-
350-
return (
351-
<TrueSheet ref={sheet}>
352-
<Button onPress={navigate} title="Navigate to SomeScreen" />
353-
// ...
354-
</TrueSheet>
355-
)
356-
```
357-
358-
### Weird layout render
359-
360-
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.
361-
36265
## v1 Roadmap
36366

36467
- [ ] Inline sheet

docs/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

docs/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Website
2+
3+
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
4+
5+
### Installation
6+
7+
```
8+
$ yarn
9+
```
10+
11+
### Local Development
12+
13+
```
14+
$ yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
### Build
20+
21+
```
22+
$ yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
### Deployment
28+
29+
Using SSH:
30+
31+
```
32+
$ USE_SSH=true yarn deploy
33+
```
34+
35+
Not using SSH:
36+
37+
```
38+
$ GIT_USER=<Your GitHub username> yarn deploy
39+
```
40+
41+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

docs/babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
}

docs/blog/authors.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lodev09:
2+
name: Jovanni Lo
3+
title: Lead React Native Developer
4+
url: https://github.com/lodev09
5+
image_url: https://github.com/lodev09.png

0 commit comments

Comments
 (0)