diff --git a/example/package.json b/example/package.json index 0e246e4aa..8630dbe3c 100644 --- a/example/package.json +++ b/example/package.json @@ -14,6 +14,7 @@ "@gorhom/showcase-template": "^2.0.4", "@react-native-community/blur": "^3.6.0", "@react-native-community/masked-view": "0.1.11", + "@react-navigation/bottom-tabs": "^5.11.11", "@react-navigation/material-top-tabs": "^5.3.15", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.4", diff --git a/example/src/Dev.tsx b/example/src/Dev.tsx index 38c86a44d..cc6bcebe6 100644 --- a/example/src/Dev.tsx +++ b/example/src/Dev.tsx @@ -1,218 +1,164 @@ -/* eslint-disable no-console */ -/* eslint-disable @typescript-eslint/no-unused-vars */ import React, { useCallback, useMemo, useRef, useState } from 'react'; -import { View, StyleSheet, Dimensions, StatusBar } from 'react-native'; -import { createStackNavigator } from '@react-navigation/stack'; -import { useAnimatedStyle, useSharedValue } from 'react-native-reanimated'; +import { StyleSheet, View } from 'react-native'; +import { DarkTheme, NavigationContainer } from '@react-navigation/native'; import { - SafeAreaProvider, - useSafeAreaInsets, -} from 'react-native-safe-area-context'; -import BottomSheet from '@gorhom/bottom-sheet'; + createBottomTabNavigator, + useBottomTabBarHeight, +} from '@react-navigation/bottom-tabs'; +import { + BottomSheetFlatList, + BottomSheetModal, + BottomSheetModalProvider, +} from '@gorhom/bottom-sheet'; +import Animated, { + useAnimatedStyle, + useSharedValue, +} from 'react-native-reanimated'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { createContactListMockData } from './utilities'; +import ContactItem from './components/contactItem'; import SearchHandle from './components/searchHandle'; -import Button from './components/button'; -import ContactList from './components/contactList'; -import { NavigationContainer, useNavigation } from '@react-navigation/native'; +import { Button } from 'react-native'; + +const SNAP_POINTS = [150, 300]; +const DATA = createContactListMockData(30); -const { height: windowHeight } = Dimensions.get('window'); +const keyExtractor = (item: any, index: number) => `${item.name}.${index}`; -const BasicExample = () => { +const App = () => { //#region state - const shownHeader = useRef(true); - const [dynamicSnapPoint, setDynamicSnapPoint] = useState(300); + const bottomSheetRef = useRef(null); + const [filter, setFilter] = useState(''); //#endregion //#region hooks - const { setOptions } = useNavigation(); - const bottomSheetRef = useRef(null); - const { top: topSafeArea, bottom: bottomSafeArea } = useSafeAreaInsets(); + const { top: topSafeArea } = useSafeAreaInsets(); + const bottomSafeArea = useBottomTabBarHeight(); //#endregion - //#region variables - const snapPoints = useMemo(() => [150, 400, '100%'], []); - const animatedPosition = useSharedValue(0); - const animatedContainerHeight = useSharedValue(800); + //#region animated values + const data = useMemo( + () => + filter === '' ? DATA : DATA.filter(item => item.name.includes(filter)), + [filter] + ); + const animatedPosition = useSharedValue(0); //#endregion //#region styles - const containerStyle = useMemo( - () => ({ - ...styles.container, - paddingTop: topSafeArea, - }), - [topSafeArea] - ); - - const firstSnapPointLineStyle = useMemo( - () => [ - styles.line, - { - height: snapPoints[0], - }, - ], - [snapPoints] - ); - - const secondSnapPointLineStyle = useMemo( - () => [ - styles.line, - { - height: snapPoints[1], - }, - ], - [snapPoints] - ); - - const safeBottomLineStyle = useMemo( - () => [ - styles.line, - { - height: bottomSafeArea, - }, - ], - [bottomSafeArea] - ); - - const sheetLineAnimatedStyle = useAnimatedStyle(() => ({ - transform: [{ translateY: animatedPosition.value }], + const positionLineAnimatedStyle = useAnimatedStyle(() => ({ + top: animatedPosition.value, })); - const sheetLineStyle = useMemo( - () => [styles.sheetLine, sheetLineAnimatedStyle], - [sheetLineAnimatedStyle] - ); - //#endregion - - //#region callbacks - const handleSheetChanges = useCallback((index: number) => { - console.log('handleSheetChanges', index); - }, []); - const handleSnapPress = useCallback(index => { - bottomSheetRef.current?.snapToIndex(index); - }, []); - const handleSnapPosition = useCallback(position => { - bottomSheetRef.current?.snapToIndex(position); - }, []); - const handleClosePress = useCallback(() => { - bottomSheetRef.current?.close(); - }, []); - const handleIncreaseDynamicSnapPoint = useCallback(() => { - setDynamicSnapPoint(state => state + 50); - }, []); - const handleHideHeaderPress = useCallback(() => { - shownHeader.current = !shownHeader.current; - setOptions({ - headerShown: shownHeader.current, - }); - }, [setOptions]); //#endregion - // renders - return ( - - {/*