diff --git a/docs/custom-handle.md b/docs/custom-handle.md deleted file mode 100644 index 396da3321..000000000 --- a/docs/custom-handle.md +++ /dev/null @@ -1,159 +0,0 @@ -# Custom Handle - -The library allows you to override the handle and create your own wonderful interactive animation. - -When you provide your own handle component, it will receive an animated value - `animatedPositionIndex` - that indicates the current position of the sheet. - -Here is an example of a custom handle component: - -```tsx -import React, { useMemo } from 'react'; -import { StyleProp, StyleSheet, ViewStyle } from 'react-native'; -import { BottomSheetHandleProps } from '@gorhom/bottom-sheet'; -import Animated, { - Extrapolate, - interpolate, - useAnimatedStyle, - useDerivedValue, -} from 'react-native-reanimated'; -import { toRad } from 'react-native-redash'; - -// @ts-ignore -export const transformOrigin = ({ x, y }, ...transformations) => { - 'worklet'; - return [ - { translateX: x }, - { translateY: y }, - ...transformations, - { translateX: x * -1 }, - { translateY: y * -1 }, - ]; -}; - -interface HandleProps extends BottomSheetHandleProps { - style?: StyleProp; -} - -const Handle: React.FC = ({ style, animatedPositionIndex }) => { - //#region animations - const indicatorTransformOriginY = useDerivedValue(() => - interpolate( - animatedPositionIndex.value, - [0, 1, 2], - [-1, 0, 1], - Extrapolate.CLAMP - ) - ); - //#endregion - - //#region styles - const containerStyle = useMemo(() => [styles.header, style], [style]); - const containerAnimatedStyle = useAnimatedStyle(() => { - const borderTopRadius = interpolate( - animatedPositionIndex.value, - [1, 2], - [20, 0], - Extrapolate.CLAMP - ); - return { - borderTopLeftRadius: borderTopRadius, - borderTopRightRadius: borderTopRadius, - }; - }); - const leftIndicatorAnimatedStyle = useAnimatedStyle(() => { - const leftIndicatorRotate = interpolate( - animatedPositionIndex.value, - [0, 1, 2], - [toRad(-30), 0, toRad(30)], - Extrapolate.CLAMP - ); - return { - transform: transformOrigin( - { x: 0, y: indicatorTransformOriginY.value }, - { - rotate: `${leftIndicatorRotate}rad`, - }, - { - translateX: -5, - } - ), - }; - }); - const rightIndicatorStyle = useMemo( - () => ({ - ...styles.indicator, - ...styles.rightIndicator, - }), - [] - ); - const rightIndicatorAnimatedStyle = useAnimatedStyle(() => { - const rightIndicatorRotate = interpolate( - animatedPositionIndex.value, - [0, 1, 2], - [toRad(30), 0, toRad(-30)], - Extrapolate.CLAMP - ); - return { - transform: transformOrigin( - { x: 0, y: indicatorTransformOriginY.value }, - { - rotate: `${rightIndicatorRotate}rad`, - }, - { - translateX: 5, - } - ), - }; - }); - //#endregion - - // render - return ( - - - - - ); -}; - -export default Handle; - -const styles = StyleSheet.create({ - header: { - alignContent: 'center', - alignItems: 'center', - justifyContent: 'center', - backgroundColor: 'white', - paddingVertical: 14, - shadowColor: 'black', - shadowOffset: { - width: 0, - height: -20, - }, - shadowOpacity: 0.1, - shadowRadius: 10, - elevation: 16, - borderBottomWidth: 1, - borderBottomColor: '#fff', - }, - indicator: { - position: 'absolute', - width: 10, - height: 4, - backgroundColor: '#999', - }, - leftIndicator: { - borderTopStartRadius: 2, - borderBottomStartRadius: 2, - }, - rightIndicator: { - borderTopEndRadius: 2, - borderBottomEndRadius: 2, - }, -}); - -``` \ No newline at end of file diff --git a/docs/flatlist.md b/docs/flatlist.md deleted file mode 100644 index 21e622d03..000000000 --- a/docs/flatlist.md +++ /dev/null @@ -1,93 +0,0 @@ -# Bottom Sheet FlatList - -Is an extended component of `FlatList` from `react-native`, with bottom sheet integrations. - -## Props - -#### `focusHook` - -This needed when bottom sheet used with multiple scrollables to allow bottom sheet detect the current scrollable ref, especially when used with `React Navigation`. You will need to provide `useFocusEffect` from `@react-navigation/native`. - -> `required:` NO | `type:` (effect: EffectCallback, deps?: DependencyList) => void | `default: ` React.useEffect - -## Example - -```tsx -import React, { useCallback, useRef, useMemo } from 'react'; -import { StyleSheet, View, Text, Button } from 'react-native'; -import BottomSheet, { BottomSheetFlatList } from '@gorhom/bottom-sheet'; - -const App = () => { - // hooks - const sheetRef = useRef(null); - - // variables - const data = useMemo( - () => - Array(50) - .fill(0) - .map((_, index) => `index-${index}`), - [] - ); - const snapPoints = useMemo(() => ['25%', '50%', '90%'], []); - - // callbacks - const handleSheetChange = useCallback(index => { - console.log('handleSheetChange', index); - }, []); - const handleSnapPress = useCallback(index => { - sheetRef.current?.snapTo(index); - }, []); - const handleClosePress = useCallback(() => { - sheetRef.current?.close(); - }, []); - - // render - const renderItem = useCallback( - ({ item }) => ( - - {item} - - ), - [] - ); - return ( - -