diff --git a/example/src/App.tsx b/example/src/App.tsx index 1c1502e00..ae75d818f 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -106,6 +106,15 @@ const App = () => { require('./screens/advanced/CustomHandleExample').default } /> + + require('./screens/advanced/CustomBackgroundExample').default + } + /> = ({ + style, + animatedIndex, +}) => { + //#region styles + const containerStyle = useMemo( + () => [ + styles.container, + style, + { + backgroundColor: interpolateColor(animatedIndex, { + inputRange: [0, 1], + outputRange: ['#ffffff', '#a8b5eb'], + }), + }, + ], + [style, animatedIndex] + ); + //#endregion + + // render + return ; +}; + +export default CustomBackground; + +const styles = StyleSheet.create({ + container: { + borderTopLeftRadius: 20, + borderTopRightRadius: 20, + backgroundColor: '#fff', + }, +}); diff --git a/example/src/components/customBackground/index.ts b/example/src/components/customBackground/index.ts new file mode 100644 index 000000000..fc615c874 --- /dev/null +++ b/example/src/components/customBackground/index.ts @@ -0,0 +1 @@ +export { default } from './CustomBackground'; diff --git a/example/src/screens/Root.tsx b/example/src/screens/Root.tsx index dff970d8b..67290edaf 100644 --- a/example/src/screens/Root.tsx +++ b/example/src/screens/Root.tsx @@ -58,6 +58,10 @@ const data = [ name: 'Custom Handle', slug: 'Advanced/CustomHandleExample', }, + { + name: 'Custom Background', + slug: 'Advanced/CustomBackgroundExample', + }, { name: 'Backdrop', slug: 'Advanced/BackdropExample', diff --git a/example/src/screens/advanced/CustomBackgroundExample.tsx b/example/src/screens/advanced/CustomBackgroundExample.tsx new file mode 100644 index 000000000..3e130f9a9 --- /dev/null +++ b/example/src/screens/advanced/CustomBackgroundExample.tsx @@ -0,0 +1,102 @@ +import React, { useCallback, useMemo, useRef } from 'react'; +import { View, StyleSheet, Text } from 'react-native'; +import BottomSheet from '@gorhom/bottom-sheet'; +import CustomBackground from '../../components/customBackground'; +import Button from '../../components/button'; +import ContactList from '../../components/contactList'; + +const CustomBackgroundExample = () => { + // hooks + const bottomSheetRef = useRef(null); + + // variables + const snapPoints = useMemo(() => [150, 450], []); + + // styles + + // callbacks + const handleSnapPress = useCallback(index => { + bottomSheetRef.current?.snapTo(index); + }, []); + const handleExpandPress = useCallback(() => { + bottomSheetRef.current?.expand(); + }, []); + const handleCollapsePress = useCallback(() => { + bottomSheetRef.current?.collapse(); + }, []); + const handleClosePress = useCallback(() => { + bottomSheetRef.current?.close(); + }, []); + + // renders + const renderHeader = useCallback(() => { + return ( + + Custom Background Example + + ); + }, []); + + return ( + +