Improve style of reply bar (#5447)
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import {Pressable, PressableProps} from 'react-native'
|
||||||
|
import Animated, {
|
||||||
|
cancelAnimation,
|
||||||
|
runOnJS,
|
||||||
|
useAnimatedStyle,
|
||||||
|
useSharedValue,
|
||||||
|
withTiming,
|
||||||
|
} from 'react-native-reanimated'
|
||||||
|
|
||||||
|
import {isTouchDevice} from '#/lib/browser'
|
||||||
|
import {isNative} from '#/platform/detection'
|
||||||
|
|
||||||
|
const DEFAULT_TARGET_SCALE = isNative || isTouchDevice ? 0.98 : 1
|
||||||
|
|
||||||
|
export function PressableScale({
|
||||||
|
targetScale = DEFAULT_TARGET_SCALE,
|
||||||
|
children,
|
||||||
|
...rest
|
||||||
|
}: {targetScale?: number} & Exclude<
|
||||||
|
PressableProps,
|
||||||
|
'onPressIn' | 'onPressOut'
|
||||||
|
>) {
|
||||||
|
const scale = useSharedValue(1)
|
||||||
|
|
||||||
|
const style = useAnimatedStyle(() => ({
|
||||||
|
transform: [{scale: scale.value}],
|
||||||
|
}))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
onPressIn={e => {
|
||||||
|
'worklet'
|
||||||
|
if (rest.onPressIn) {
|
||||||
|
runOnJS(rest.onPressIn)(e)
|
||||||
|
}
|
||||||
|
cancelAnimation(scale)
|
||||||
|
scale.value = withTiming(targetScale, {duration: 100})
|
||||||
|
}}
|
||||||
|
onPressOut={e => {
|
||||||
|
'worklet'
|
||||||
|
if (rest.onPressOut) {
|
||||||
|
runOnJS(rest.onPressOut)(e)
|
||||||
|
}
|
||||||
|
cancelAnimation(scale)
|
||||||
|
scale.value = withTiming(1, {duration: 100})
|
||||||
|
}}
|
||||||
|
{...rest}>
|
||||||
|
<Animated.View style={style}>{children as React.ReactNode}</Animated.View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {StyleSheet, TouchableOpacity} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {PressableScale} from '#/lib/custom-animations/PressableScale'
|
||||||
|
import {useHaptics} from '#/lib/haptics'
|
||||||
|
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||||
|
import {useHapticsDisabled} from '#/state/preferences'
|
||||||
import {useProfileQuery} from '#/state/queries/profile'
|
import {useProfileQuery} from '#/state/queries/profile'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {UserAvatar} from '#/view/com/util/UserAvatar'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {Text} from '../util/text/Text'
|
import {Text} from '#/components/Typography'
|
||||||
import {UserAvatar} from '../util/UserAvatar'
|
|
||||||
|
|
||||||
export function PostThreadComposePrompt({
|
export function PostThreadComposePrompt({
|
||||||
onPressCompose,
|
onPressCompose,
|
||||||
@@ -17,47 +20,57 @@ export function PostThreadComposePrompt({
|
|||||||
}) {
|
}) {
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {data: profile} = useProfileQuery({did: currentAccount?.did})
|
const {data: profile} = useProfileQuery({did: currentAccount?.did})
|
||||||
const pal = usePalette('default')
|
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {isDesktop} = useWebMediaQueries()
|
const {isTabletOrDesktop} = useWebMediaQueries()
|
||||||
|
const t = useTheme()
|
||||||
|
const playHaptics = useHaptics()
|
||||||
|
const isHapticsDisabled = useHapticsDisabled()
|
||||||
|
|
||||||
|
const onPress = () => {
|
||||||
|
playHaptics('Light')
|
||||||
|
setTimeout(
|
||||||
|
() => {
|
||||||
|
onPressCompose()
|
||||||
|
},
|
||||||
|
isHapticsDisabled ? 0 : 75,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<PressableScale
|
||||||
testID="replyPromptBtn"
|
|
||||||
style={[pal.view, pal.border, styles.prompt]}
|
|
||||||
onPress={() => onPressCompose()}
|
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={_(msg`Compose reply`)}
|
accessibilityLabel={_(msg`Compose reply`)}
|
||||||
accessibilityHint={_(msg`Opens composer`)}>
|
accessibilityHint={_(msg`Opens composer`)}
|
||||||
<UserAvatar
|
style={[
|
||||||
avatar={profile?.avatar}
|
{paddingTop: 8, paddingBottom: isTabletOrDesktop ? 8 : 11},
|
||||||
size={38}
|
a.px_sm,
|
||||||
type={profile?.associated?.labeler ? 'labeler' : 'user'}
|
a.border_t,
|
||||||
/>
|
t.atoms.border_contrast_low,
|
||||||
<Text
|
t.atoms.bg,
|
||||||
type="xl"
|
]}
|
||||||
|
onPress={onPress}>
|
||||||
|
<View
|
||||||
style={[
|
style={[
|
||||||
pal.text,
|
a.flex_row,
|
||||||
isDesktop ? styles.labelDesktopWeb : styles.labelMobile,
|
a.align_center,
|
||||||
|
a.p_sm,
|
||||||
|
a.gap_sm,
|
||||||
|
a.rounded_full,
|
||||||
|
t.atoms.bg_contrast_25,
|
||||||
]}>
|
]}>
|
||||||
<Trans>Write your reply</Trans>
|
<UserAvatar
|
||||||
</Text>
|
size={22}
|
||||||
</TouchableOpacity>
|
avatar={profile?.avatar}
|
||||||
|
type={profile?.associated?.labeler ? 'labeler' : 'user'}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
isTabletOrDesktop ? a.text_md : a.text_sm,
|
||||||
|
t.atoms.text_contrast_medium,
|
||||||
|
]}>
|
||||||
|
<Trans>Write your reply</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</PressableScale>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
prompt: {
|
|
||||||
paddingHorizontal: 16,
|
|
||||||
paddingTop: 10,
|
|
||||||
paddingBottom: 10,
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
borderTopWidth: StyleSheet.hairlineWidth,
|
|
||||||
},
|
|
||||||
labelMobile: {
|
|
||||||
paddingLeft: 12,
|
|
||||||
},
|
|
||||||
labelDesktopWeb: {
|
|
||||||
paddingLeft: 12,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user