-
-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
329 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { | ||
BottomSheetFooter, | ||
BottomSheetFooterProps, | ||
useBottomSheet, | ||
} from '@gorhom/bottom-sheet'; | ||
import { RectButton } from 'react-native-gesture-handler'; | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
import Animated, { | ||
Extrapolate, | ||
interpolate, | ||
useAnimatedStyle, | ||
} from 'react-native-reanimated'; | ||
import { toRad } from 'react-native-redash'; | ||
|
||
const AnimatedRectButton = Animated.createAnimatedComponent(RectButton); | ||
|
||
interface CustomFooterProps extends BottomSheetFooterProps {} | ||
|
||
const CustomFooter = ({ animatedFooterPosition }: CustomFooterProps) => { | ||
//#region hooks | ||
const { bottom: bottomSafeArea } = useSafeAreaInsets(); | ||
const { expand, collapse, animatedIndex } = useBottomSheet(); | ||
//#endregion | ||
|
||
//#region styles | ||
const arrowAnimatedStyle = useAnimatedStyle(() => { | ||
const arrowRotate = interpolate( | ||
animatedIndex.value, | ||
[0, 1], | ||
[toRad(0), toRad(-180)], | ||
Extrapolate.CLAMP | ||
); | ||
return { | ||
transform: [{ rotate: `${arrowRotate}rad` }], | ||
}; | ||
}, []); | ||
const arrowStyle = useMemo( | ||
() => [arrowAnimatedStyle, styles.arrow], | ||
[arrowAnimatedStyle] | ||
); | ||
const containerAnimatedStyle = useAnimatedStyle( | ||
() => ({ | ||
opacity: interpolate( | ||
animatedIndex.value, | ||
[-0.85, 0], | ||
[0, 1], | ||
Extrapolate.CLAMP | ||
), | ||
}), | ||
[animatedIndex] | ||
); | ||
const containerStyle = useMemo( | ||
() => [containerAnimatedStyle, styles.container], | ||
[containerAnimatedStyle] | ||
); | ||
//#endregion | ||
|
||
const handleArrowPress = useCallback(() => { | ||
if (animatedIndex.value === 0) { | ||
expand(); | ||
} else { | ||
collapse(); | ||
} | ||
}, [expand, collapse, animatedIndex]); | ||
|
||
return ( | ||
<BottomSheetFooter | ||
bottomInset={bottomSafeArea} | ||
animatedFooterPosition={animatedFooterPosition} | ||
> | ||
<AnimatedRectButton style={containerStyle} onPress={handleArrowPress}> | ||
<Animated.Text style={arrowStyle}>⌃</Animated.Text> | ||
</AnimatedRectButton> | ||
</BottomSheetFooter> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
alignSelf: 'flex-end', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
marginHorizontal: 24, | ||
marginBottom: 12, | ||
width: 50, | ||
height: 50, | ||
borderRadius: 25, | ||
backgroundColor: '#80f', | ||
shadowOffset: { | ||
width: 0, | ||
height: 12, | ||
}, | ||
shadowOpacity: 0.25, | ||
shadowRadius: 8.0, | ||
|
||
elevation: 8, | ||
}, | ||
arrow: { | ||
fontSize: 20, | ||
height: 20, | ||
textAlignVertical: 'center', | ||
fontWeight: '900', | ||
color: '#fff', | ||
}, | ||
}); | ||
|
||
export default CustomFooter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './CustomFooter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.