From 46fb88398ec7625c258cd62cb8560d72f3537fcb Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Tue, 25 May 2021 22:57:11 +0100 Subject: [PATCH] feat: added footer component (#457) * chore: added BottomSheetFooter * fix: added bottom inset to slide behavior * chore: added footer example --- example/src/Dev.tsx | 23 +++- .../src/screens/advanced/FooterExample.tsx | 106 ++++++++++++++ example/src/screens/screens.ts | 5 + src/components/bottomSheet/BottomSheet.tsx | 15 ++ src/components/bottomSheet/types.d.ts | 5 +- .../bottomSheetFooter/BottomSheetFooter.tsx | 130 ++++++++++++++++++ src/components/bottomSheetFooter/constants.ts | 8 ++ src/components/bottomSheetFooter/index.ts | 1 + src/components/bottomSheetFooter/types.d.ts | 36 +++++ .../createBottomSheetScrollableComponent.tsx | 17 ++- .../bottomSheetScrollable/styles.ts | 1 + src/contexts/internal.ts | 8 ++ src/index.ts | 1 + 13 files changed, 352 insertions(+), 4 deletions(-) create mode 100644 example/src/screens/advanced/FooterExample.tsx create mode 100644 src/components/bottomSheetFooter/BottomSheetFooter.tsx create mode 100644 src/components/bottomSheetFooter/constants.ts create mode 100644 src/components/bottomSheetFooter/index.ts create mode 100644 src/components/bottomSheetFooter/types.d.ts diff --git a/example/src/Dev.tsx b/example/src/Dev.tsx index cc6bcebe..4209756b 100644 --- a/example/src/Dev.tsx +++ b/example/src/Dev.tsx @@ -1,5 +1,5 @@ import React, { useCallback, useMemo, useRef, useState } from 'react'; -import { StyleSheet, View } from 'react-native'; +import { StyleSheet, Text, View } from 'react-native'; import { DarkTheme, NavigationContainer } from '@react-navigation/native'; import { createBottomTabNavigator, @@ -7,6 +7,7 @@ import { } from '@react-navigation/bottom-tabs'; import { BottomSheetFlatList, + BottomSheetFooter, BottomSheetModal, BottomSheetModalProvider, } from '@gorhom/bottom-sheet'; @@ -14,6 +15,7 @@ import Animated, { useAnimatedStyle, useSharedValue, } from 'react-native-reanimated'; +import { RectButton } from 'react-native-gesture-handler'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { createContactListMockData } from './utilities'; import ContactItem from './components/contactItem'; @@ -97,6 +99,11 @@ const App = () => { style={styles.flatlist} contentContainerStyle={styles.flatlistContainer} /> + + + this is a footer! + + {SNAP_POINTS.map(snapPoint => ( @@ -149,6 +156,20 @@ const styles = StyleSheet.create({ flatlistContainer: { paddingHorizontal: 24, }, + footer: { + justifyContent: 'center', + alignItems: 'center', + marginHorizontal: 12, + padding: 12, + marginBottom: 12, + borderRadius: 24, + backgroundColor: '#80f', + }, + footerText: { + fontSize: 16, + fontWeight: '600', + color: '#fff', + }, }); const Tab = createBottomTabNavigator(); diff --git a/example/src/screens/advanced/FooterExample.tsx b/example/src/screens/advanced/FooterExample.tsx new file mode 100644 index 00000000..9e65dea9 --- /dev/null +++ b/example/src/screens/advanced/FooterExample.tsx @@ -0,0 +1,106 @@ +import React, { useCallback, useMemo, useRef, useState } from 'react'; +import { View, StyleSheet, Text } from 'react-native'; +import BottomSheet, { BottomSheetFooter } from '@gorhom/bottom-sheet'; +import SearchHandle from '../../components/searchHandle'; +import Button from '../../components/button'; +import ContactList from '../../components/contactList'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; + +const FooterExample = () => { + // state + const [fadeBehavior, setFadeBehavior] = useState<'none' | 'fade'>('none'); + const [slideBehavior, setSlideBehavior] = useState<'none' | 'slide'>('none'); + const [scaleBehavior, setScaleBehavior] = useState<'none' | 'scale'>('none'); + + // hooks + const bottomSheetRef = useRef(null); + const { bottom: bottomSafeArea } = useSafeAreaInsets(); + + // variables + const snapPoints = useMemo(() => [80, 250], []); + const appearanceBehavior = useMemo( + () => [fadeBehavior, slideBehavior, scaleBehavior], + [fadeBehavior, slideBehavior, scaleBehavior] + ); + + // callbacks + const handleFadeBehavior = useCallback(() => { + setFadeBehavior(state => (state === 'none' ? 'fade' : 'none')); + }, []); + const handleScaleBehavior = useCallback(() => { + setScaleBehavior(state => (state === 'none' ? 'scale' : 'none')); + }, []); + const handleSlideBehavior = useCallback(() => { + setSlideBehavior(state => (state === 'none' ? 'slide' : 'none')); + }, []); + const handleExpandPress = useCallback(() => { + bottomSheetRef.current?.expand(); + }, []); + const handleCollapsePress = useCallback(() => { + bottomSheetRef.current?.collapse(); + }, []); + const handleClosePress = useCallback(() => { + bottomSheetRef.current?.close(); + }, []); + + // renders + return ( + +