Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow control panning gestures #88

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: updated examples
  • Loading branch information
gorhom committed Nov 27, 2020
commit 45b60af910b7ad40f06ecb62797187487ba49302
17 changes: 1 addition & 16 deletions example/src/screens/advanced/CustomHandleExample.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import React, { useCallback, useMemo, useRef } from 'react';
import { View, StyleSheet, Text } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';
import Handle from '../../components/handle';
import Button from '../../components/button';
import ContactList from '../../components/contactList';

const CustomHandleExample = () => {
// state
const [enabled, setEnabled] = useState(true);

// hooks
const bottomSheetRef = useRef<BottomSheet>(null);

// variables
const snapPoints = useMemo(() => [150, 300, 450], []);
const enableButtonText = useMemo(() => (enabled ? 'Disable' : 'Enable'), [
enabled,
]);

// callbacks
const handleSnapPress = useCallback(index => {
Expand All @@ -31,9 +25,6 @@ const CustomHandleExample = () => {
const handleClosePress = useCallback(() => {
bottomSheetRef.current?.close();
}, []);
const handleEnablePress = useCallback(() => {
setEnabled(state => !state);
}, []);

// renders
const renderHeader = useCallback(() => {
Expand Down Expand Up @@ -76,14 +67,8 @@ const CustomHandleExample = () => {
style={styles.buttonContainer}
onPress={handleClosePress}
/>
<Button
label={enableButtonText}
style={styles.buttonContainer}
onPress={handleEnablePress}
/>
<BottomSheet
ref={bottomSheetRef}
enabled={enabled}
snapPoints={snapPoints}
initialSnapIndex={1}
handleComponent={Handle}
Expand Down
17 changes: 1 addition & 16 deletions example/src/screens/advanced/NavigatorExample.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import React, { useCallback, useMemo, useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import {
createStackNavigator,
Expand Down Expand Up @@ -69,17 +69,11 @@ const Navigator = () => {
};

const NavigatorExample = () => {
// state
const [enabled, setEnabled] = useState(true);

// hooks
const bottomSheetRef = useRef<BottomSheet>(null);

// variables
const snapPoints = useMemo(() => ['25%', '50%', '90%'], []);
const enableButtonText = useMemo(() => (enabled ? 'Disable' : 'Enable'), [
enabled,
]);

// callbacks
const handleSheetChange = useCallback(index => {
Expand All @@ -97,9 +91,6 @@ const NavigatorExample = () => {
const handleClosePress = useCallback(() => {
bottomSheetRef.current?.close();
}, []);
const handleEnablePress = useCallback(() => {
setEnabled(state => !state);
}, []);

// renders
return (
Expand Down Expand Up @@ -134,14 +125,8 @@ const NavigatorExample = () => {
style={styles.buttonContainer}
onPress={handleClosePress}
/>
<Button
label={enableButtonText}
style={styles.buttonContainer}
onPress={handleEnablePress}
/>
<BottomSheet
ref={bottomSheetRef}
enabled={enabled}
snapPoints={snapPoints}
initialSnapIndex={1}
onChange={handleSheetChange}
Expand Down
8 changes: 0 additions & 8 deletions example/src/screens/static/BasicExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useSafeArea } from 'react-native-safe-area-context';

const BasicExample = () => {
// state
const [enabled, setEnabled] = useState(true);
const [dynamicSnapPoint, setDynamicSnapPoint] = useState(450);

// hooks
Expand Down Expand Up @@ -61,16 +60,9 @@ const BasicExample = () => {
style={styles.buttonContainer}
onPress={() => handleClosePress()}
/>

<Button
label={`${enabled ? 'Disable' : 'Enable'}`}
style={styles.buttonContainer}
onPress={() => setEnabled(state => !state)}
/>
<ReText text={concat('Position from bottom: ', position)} />
<BottomSheet
ref={bottomSheetRef}
enabled={enabled}
snapPoints={snapPoints}
initialSnapIndex={1}
topInset={topSafeArea}
Expand Down
45 changes: 36 additions & 9 deletions example/src/screens/static/BasicExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,34 @@ interface ExampleScreenProps {
const createExampleScreen = ({ type, count = 20 }: ExampleScreenProps) =>
memo(() => {
// state
const [enabled, setEnabled] = useState(true);
const [
enableContentPanningGesture,
setEnableContentPanningGesture,
] = useState(true);
const [
enableHandlePanningGesture,
setEnableHandlePanningGesture,
] = useState(true);

// hooks
const bottomSheetRef = useRef<BottomSheet>(null);

// variables
const snapPoints = useMemo(() => ['25%', '50%', '90%'], []);
const enableButtonText = useMemo(() => (enabled ? 'Disable' : 'Enable'), [
enabled,
]);
const enableContentPanningGestureButtonText = useMemo(
() =>
enableContentPanningGesture
? 'Disable Content Panning Gesture'
: 'Enable Content Panning Gesture',
[enableContentPanningGesture]
);
const enableHandlePanningGestureButtonText = useMemo(
() =>
enableHandlePanningGesture
? 'Disable Handle Panning Gesture'
: 'Enable Handle Panning Gesture',
[enableHandlePanningGesture]
);

// callbacks
const handleSheetChange = useCallback(index => {
Expand All @@ -40,8 +58,11 @@ const createExampleScreen = ({ type, count = 20 }: ExampleScreenProps) =>
const handleClosePress = useCallback(() => {
bottomSheetRef.current?.close();
}, []);
const handleEnablePress = useCallback(() => {
setEnabled(state => !state);
const handleEnableContentPanningGesturePress = useCallback(() => {
setEnableContentPanningGesture(state => !state);
}, []);
const handleEnableHandlePanningGesturePress = useCallback(() => {
setEnableHandlePanningGesture(state => !state);
}, []);

return (
Expand Down Expand Up @@ -77,16 +98,22 @@ const createExampleScreen = ({ type, count = 20 }: ExampleScreenProps) =>
onPress={handleClosePress}
/>
<Button
label={enableButtonText}
label={enableContentPanningGestureButtonText}
style={styles.buttonContainer}
onPress={handleEnableContentPanningGesturePress}
/>
<Button
label={enableHandlePanningGestureButtonText}
style={styles.buttonContainer}
onPress={handleEnablePress}
onPress={handleEnableHandlePanningGesturePress}
/>
<BottomSheet
ref={bottomSheetRef}
enabled={enabled}
snapPoints={snapPoints}
initialSnapIndex={1}
animateOnMount={true}
enableContentPanningGesture={enableContentPanningGesture}
enableHandlePanningGesture={enableHandlePanningGesture}
onChange={handleSheetChange}
>
<ContactList key={`${type}.list`} type={type} count={count} />
Expand Down