Skip to content

Commit

Permalink
docs: added gesture handler view to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Oct 19, 2024
1 parent ace0da7 commit 2628425
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 35 deletions.
12 changes: 7 additions & 5 deletions website/docs/components/bottomsheetbackdrop.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ Pressing the backdrop will call the `onPress` function, it will be called before
```tsx
import React, { useCallback, useMemo, useRef } from "react";
import { View, Text, StyleSheet } from "react-native";
import BottomSheet, { BottomSheetBackdrop } from "@gorhom/bottom-sheet";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetView, BottomSheetBackdrop } from "@gorhom/bottom-sheet";

const App = () => {
// ref
Expand All @@ -113,19 +114,20 @@ const App = () => {
[]
);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
backdropComponent={renderBackdrop}
enableDynamicSizing={false}
onChange={handleSheetChanges}
>
<View style={styles.contentContainer}>
<BottomSheetView style={styles.contentContainer}>
<Text>Awesome 🎉</Text>
</View>
</BottomSheetView>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
5 changes: 3 additions & 2 deletions website/docs/components/bottomsheetflashlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This needed when bottom sheet used with multiple scrollables to allow bottom she
```tsx
import React, { useCallback, useRef, useMemo } from "react";
import { StyleSheet, View, Text, Button } from "react-native";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetFlashList } from "@gorhom/bottom-sheet";


Expand Down Expand Up @@ -63,7 +64,7 @@ const App = () => {
);
}, []);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button title="Snap To 50%" onPress={() => handleSnapPress(1)} />
<Button title="Snap To 25%" onPress={() => handleSnapPress(0)} />
<Button title="Close" onPress={() => handleClosePress()} />
Expand All @@ -79,7 +80,7 @@ const App = () => {
estimatedItemSize={43.3}
/>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
6 changes: 4 additions & 2 deletions website/docs/components/bottomsheetflatlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These props will be ignored if they were passed, because of the internal integra
```tsx
import React, { useCallback, useRef, useMemo } from "react";
import { StyleSheet, View, Text, Button } from "react-native";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetFlatList } from "@gorhom/bottom-sheet";

const App = () => {
Expand Down Expand Up @@ -71,14 +72,15 @@ const App = () => {
[]
);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button title="Snap To 90%" onPress={() => handleSnapPress(2)} />
<Button title="Snap To 50%" onPress={() => handleSnapPress(1)} />
<Button title="Snap To 25%" onPress={() => handleSnapPress(0)} />
<Button title="Close" onPress={() => handleClosePress()} />
<BottomSheet
ref={sheetRef}
snapPoints={snapPoints}
enableDynamicSizing={false}
onChange={handleSheetChange}
>
<BottomSheetFlatList
Expand All @@ -88,7 +90,7 @@ const App = () => {
contentContainerStyle={styles.contentContainer}
/>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
5 changes: 3 additions & 2 deletions website/docs/components/bottomsheetfooter.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Component to be placed in the footer.
```tsx
import React, { useCallback, useMemo, useRef } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetFooter } from '@gorhom/bottom-sheet';

const App = () => {
Expand All @@ -61,7 +62,7 @@ const App = () => {
[]
);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<BottomSheet
ref={bottomSheetRef}
index={1}
Expand All @@ -72,7 +73,7 @@ const App = () => {
<Text>Awesome 🎉</Text>
</View>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
6 changes: 4 additions & 2 deletions website/docs/components/bottomsheetscrollview.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These props will be ignored if they were passed, because of the internal integra
```tsx
import React, { useCallback, useRef, useMemo } from "react";
import { StyleSheet, View, Text, Button } from "react-native";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetScrollView } from "@gorhom/bottom-sheet";

const App = () => {
Expand Down Expand Up @@ -71,7 +72,7 @@ const App = () => {
[]
);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button title="Snap To 90%" onPress={() => handleSnapPress(2)} />
<Button title="Snap To 50%" onPress={() => handleSnapPress(1)} />
<Button title="Snap To 25%" onPress={() => handleSnapPress(0)} />
Expand All @@ -80,13 +81,14 @@ const App = () => {
ref={sheetRef}
index={1}
snapPoints={snapPoints}
enableDynamicSizing={false}
onChange={handleSheetChange}
>
<BottomSheetScrollView contentContainerStyle={styles.contentContainer}>
{data.map(renderItem)}
</BottomSheetScrollView>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
6 changes: 4 additions & 2 deletions website/docs/components/bottomsheetsectionlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These props will be ignored if they were passed, because of the internal integra
```tsx
import React, { useCallback, useRef, useMemo } from "react";
import { StyleSheet, View, Text, Button } from "react-native";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetSectionList } from "@gorhom/bottom-sheet";

const App = () => {
Expand Down Expand Up @@ -84,7 +85,7 @@ const App = () => {
[]
);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button title="Snap To 90%" onPress={() => handleSnapPress(2)} />
<Button title="Snap To 50%" onPress={() => handleSnapPress(1)} />
<Button title="Snap To 25%" onPress={() => handleSnapPress(0)} />
Expand All @@ -93,6 +94,7 @@ const App = () => {
ref={sheetRef}
index={1}
snapPoints={snapPoints}
enableDynamicSizing={false}
onChange={handleSheetChange}
>
<BottomSheetSectionList
Expand All @@ -103,7 +105,7 @@ const App = () => {
contentContainerStyle={styles.contentContainer}
/>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
12 changes: 7 additions & 5 deletions website/docs/components/bottomsheettextinput.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Inherits `TextInputProps` from `react-native`.
```tsx
import React, { useCallback, useMemo, useRef } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import BottomSheet, { BottomSheetTextInput } from '@gorhom/bottom-sheet';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetView, BottomSheetTextInput } from '@gorhom/bottom-sheet';

const App = () => {
// ref
Expand All @@ -34,20 +35,21 @@ const App = () => {

// renders
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
keyboardBehavior="fillParent"
enableDynamicSizing={false}
onChange={handleSheetChanges}
>
<BottomSheetTextInput style={styles.input} />
<View style={styles.contentContainer}>
<BottomSheetView style={styles.contentContainer}>
<Text>Awesome 🎉</Text>
</View>
</BottomSheetView>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
13 changes: 10 additions & 3 deletions website/docs/components/bottomsheetview.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This needed when bottom sheet used with multiple scrollables to allow bottom she
```tsx
import React, { useCallback, useRef, useMemo } from "react";
import { StyleSheet, View, Text, Button } from "react-native";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetView } from "@gorhom/bottom-sheet";

const App = () => {
Expand All @@ -48,21 +49,22 @@ const App = () => {

// render
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button title="Snap To 90%" onPress={() => handleSnapPress(2)} />
<Button title="Snap To 50%" onPress={() => handleSnapPress(1)} />
<Button title="Snap To 25%" onPress={() => handleSnapPress(0)} />
<Button title="Close" onPress={() => handleClosePress()} />
<BottomSheet
ref={sheetRef}
snapPoints={snapPoints}
enableDynamicSizing={false}
onChange={handleSheetChange}
>
<BottomSheetView>
<BottomSheetView style={styles.contentContainer}>
<Text>Awesome 🔥</Text>
</BottomSheetView>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand All @@ -71,6 +73,11 @@ const styles = StyleSheet.create({
flex: 1,
paddingTop: 200,
},
contentContainer: {
flex: 1,
padding: 36,
alignItems: 'center',
},
});

export default App;
Expand Down
6 changes: 4 additions & 2 deletions website/docs/components/bottomsheetvirtualizedlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These props will be ignored if they were passed, because of the internal integra
```tsx
import React, { useCallback, useRef, useMemo } from "react";
import { StyleSheet, View, Text, Button } from "react-native";
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetVirtualizedList } from "@gorhom/bottom-sheet";

const App = () => {
Expand Down Expand Up @@ -71,14 +72,15 @@ const App = () => {
[]
);
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button title="Snap To 90%" onPress={() => handleSnapPress(2)} />
<Button title="Snap To 50%" onPress={() => handleSnapPress(1)} />
<Button title="Snap To 25%" onPress={() => handleSnapPress(0)} />
<Button title="Close" onPress={() => handleClosePress()} />
<BottomSheet
ref={sheetRef}
snapPoints={snapPoints}
enableDynamicSizing={false}
onChange={handleSheetChange}
>
<BottomSheetVirtualizedList
Expand All @@ -90,7 +92,7 @@ const App = () => {
contentContainerStyle={styles.contentContainer}
/>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

Expand Down
10 changes: 3 additions & 7 deletions website/docs/modal/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Here is a simple usage of the **Bottom Sheet Modal**, with non-scrollable conten
```tsx
import React, { useCallback, useMemo, useRef } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import {
BottomSheetModal,
BottomSheetView,
Expand All @@ -21,9 +22,6 @@ const App = () => {
// ref
const bottomSheetModalRef = useRef<BottomSheetModal>(null);

// variables
const snapPoints = useMemo(() => ['25%', '50%'], []);

// callbacks
const handlePresentModalPress = useCallback(() => {
bottomSheetModalRef.current?.present();
Expand All @@ -35,23 +33,21 @@ const App = () => {
// renders
return (
<BottomSheetModalProvider>
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<Button
onPress={handlePresentModalPress}
title="Present Modal"
color="black"
/>
<BottomSheetModal
ref={bottomSheetModalRef}
index={1}
snapPoints={snapPoints}
onChange={handleSheetChanges}
>
<BottomSheetView style={styles.contentContainer}>
<Text>Awesome 🎉</Text>
</BottomSheetView>
</BottomSheetModal>
</View>
</GestureHandlerRootView>
</BottomSheetModalProvider>
);
};
Expand Down
7 changes: 4 additions & 3 deletions website/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Here is a simple usage of the **Bottom Sheet**, with non-scrollable content. For
```tsx
import React, { useCallback, useMemo, useRef } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetView } from '@gorhom/bottom-sheet';

const App = () => {
Expand All @@ -24,7 +25,7 @@ const App = () => {

// renders
return (
<View style={styles.container}>
<GestureHandlerRootView style={styles.container}>
<BottomSheet
ref={bottomSheetRef}
onChange={handleSheetChanges}
Expand All @@ -33,18 +34,18 @@ const App = () => {
<Text>Awesome 🎉</Text>
</BottomSheetView>
</BottomSheet>
</View>
</GestureHandlerRootView>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
backgroundColor: 'grey',
},
contentContainer: {
flex: 1,
padding: 36,
alignItems: 'center',
},
});
Expand Down

0 comments on commit 2628425

Please sign in to comment.