diff options
author | Hailey <me@haileyok.com> | 2024-05-19 19:25:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-19 19:25:49 -0700 |
commit | 52beb29a0d96d8de731400aa654ca4c905c2aa48 (patch) | |
tree | 35c4807da520d9f9acb2247036018576c87dbe97 /src/components/dms/NewMessagesPill.tsx | |
parent | 7de0b0a58cf173e5e341b515c8b960c48c659ec3 (diff) | |
download | voidsky-52beb29a0d96d8de731400aa654ca4c905c2aa48.tar.zst |
[🐴] Fully implement keyboard controller (#4106)
* Revert "[🐴] Ensure keyboard gets dismissed when leaving screen (#4104)" This reverts commit 3ca671d9aacb6137e10e2cf3cd9bc170af798389. * getting somewhere * remove some now nuneeded code * fully implement keyboard controller * onStartReached check * fix new messages pill alignment * scroll to end on press * simplify pill scroll logic * update comment * adjust logic on when to hide the pill * fix backgrounding jank * improve look of deleting messages * add double tap on messages * better onStartReached logic * nit * add hit slop to the gesture * better gestures for press and hold * nits
Diffstat (limited to 'src/components/dms/NewMessagesPill.tsx')
-rw-r--r-- | src/components/dms/NewMessagesPill.tsx | 100 |
1 files changed, 75 insertions, 25 deletions
diff --git a/src/components/dms/NewMessagesPill.tsx b/src/components/dms/NewMessagesPill.tsx index 4a0ba22c9..924f7c455 100644 --- a/src/components/dms/NewMessagesPill.tsx +++ b/src/components/dms/NewMessagesPill.tsx @@ -1,47 +1,97 @@ import React from 'react' -import {View} from 'react-native' -import Animated from 'react-native-reanimated' +import {Pressable, View} from 'react-native' +import Animated, { + runOnJS, + useAnimatedStyle, + useSharedValue, + withTiming, +} from 'react-native-reanimated' +import {useSafeAreaInsets} from 'react-native-safe-area-context' import {Trans} from '@lingui/macro' import { ScaleAndFadeIn, ScaleAndFadeOut, } from 'lib/custom-animations/ScaleAndFade' +import {useHaptics} from 'lib/haptics' +import {isAndroid, isIOS, isWeb} from 'platform/detection' import {atoms as a, useTheme} from '#/alf' import {Text} from '#/components/Typography' -export function NewMessagesPill() { +const AnimatedPressable = Animated.createAnimatedComponent(Pressable) + +export function NewMessagesPill({ + onPress: onPressInner, +}: { + onPress: () => void +}) { const t = useTheme() + const playHaptic = useHaptics() + const {bottom: bottomInset} = useSafeAreaInsets() + const bottomBarHeight = isIOS ? 42 : isAndroid ? 60 : 0 + const bottomOffset = isWeb ? 0 : bottomInset + bottomBarHeight + + const scale = useSharedValue(1) + + const onPressIn = React.useCallback(() => { + if (isWeb) return + scale.value = withTiming(1.075, {duration: 100}) + }, [scale]) + + const onPressOut = React.useCallback(() => { + if (isWeb) return + scale.value = withTiming(1, {duration: 100}) + }, [scale]) + + const onPress = React.useCallback(() => { + runOnJS(playHaptic)() + onPressInner?.() + }, [onPressInner, playHaptic]) - React.useEffect(() => {}, []) + const animatedStyle = useAnimatedStyle(() => ({ + transform: [{scale: scale.value}], + })) return ( - <Animated.View + <View style={[ - a.py_sm, - a.rounded_full, - a.shadow_sm, - a.border, - t.atoms.bg_contrast_50, - t.atoms.border_contrast_medium, + a.absolute, + a.w_full, + a.z_10, + a.align_center, { - position: 'absolute', - bottom: 70, - width: '40%', - left: '30%', - alignItems: 'center', - shadowOpacity: 0.125, - shadowRadius: 12, - shadowOffset: {width: 0, height: 5}, + bottom: bottomOffset + 70, + // Don't prevent scrolling in this area _except_ for in the pill itself + pointerEvents: 'box-none', }, - ]} - entering={ScaleAndFadeIn} - exiting={ScaleAndFadeOut}> - <View style={{flex: 1}}> + ]}> + <AnimatedPressable + style={[ + a.py_sm, + a.rounded_full, + a.shadow_sm, + a.border, + t.atoms.bg_contrast_50, + t.atoms.border_contrast_medium, + { + width: 160, + alignItems: 'center', + shadowOpacity: 0.125, + shadowRadius: 12, + shadowOffset: {width: 0, height: 5}, + pointerEvents: 'box-only', + }, + animatedStyle, + ]} + entering={ScaleAndFadeIn} + exiting={ScaleAndFadeOut} + onPress={onPress} + onPressIn={onPressIn} + onPressOut={onPressOut}> <Text style={[a.font_bold]}> <Trans>New messages</Trans> </Text> - </View> - </Animated.View> + </AnimatedPressable> + </View> ) } |