diff options
author | Ollie H <renahlee@outlook.com> | 2023-05-15 13:18:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-15 15:18:39 -0500 |
commit | 628d8773255d403347b0cbb98afa6681768d428e (patch) | |
tree | 364177969bc142dd71e871b9261c6304d2c19a42 /src/view/com/util/post-ctrls/RepostButton.tsx | |
parent | 0a0afdf2c2c90c5460784935e9d1324dadf61d48 (diff) | |
download | voidsky-628d8773255d403347b0cbb98afa6681768d428e.tar.zst |
Use dropdown for web reposting and quote posting (#607)
* Use dropdown for web reposting and quote posting * Remove collateral damage * Tune the repost dropdown positioning * Move postctrls into their own folder * Factor out repost button into native/web build --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/view/com/util/post-ctrls/RepostButton.tsx')
-rw-r--r-- | src/view/com/util/post-ctrls/RepostButton.tsx | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/view/com/util/post-ctrls/RepostButton.tsx b/src/view/com/util/post-ctrls/RepostButton.tsx new file mode 100644 index 000000000..e6de4cb19 --- /dev/null +++ b/src/view/com/util/post-ctrls/RepostButton.tsx @@ -0,0 +1,95 @@ +import React, {useCallback} from 'react' +import {StyleProp, StyleSheet, TouchableOpacity, ViewStyle} from 'react-native' +import {RepostIcon} from 'lib/icons' +import {s, colors} from 'lib/styles' +import {useTheme} from 'lib/ThemeContext' +import {Text} from '../text/Text' +import {useStores} from 'state/index' + +const HITSLOP = {top: 5, left: 5, bottom: 5, right: 5} + +interface Props { + isReposted: boolean + repostCount?: number + big?: boolean + onRepost: () => void + onQuote: () => void +} + +export const RepostButton = ({ + isReposted, + repostCount, + big, + onRepost, + onQuote, +}: Props) => { + const store = useStores() + const theme = useTheme() + + const defaultControlColor = React.useMemo( + () => ({ + color: theme.palette.default.postCtrl, + }), + [theme], + ) + + const onPressToggleRepostWrapper = useCallback(() => { + store.shell.openModal({ + name: 'repost', + onRepost: onRepost, + onQuote: onQuote, + isReposted, + }) + }, [onRepost, onQuote, isReposted, store.shell]) + + return ( + <TouchableOpacity + testID="repostBtn" + hitSlop={HITSLOP} + onPress={onPressToggleRepostWrapper} + style={styles.control} + accessibilityRole="button" + accessibilityLabel={isReposted ? 'Undo repost' : 'Repost'} + accessibilityHint={ + isReposted + ? `Remove your repost of the post` + : `Repost or quote post the post` + }> + <RepostIcon + style={ + isReposted + ? (styles.reposted as StyleProp<ViewStyle>) + : defaultControlColor + } + strokeWidth={2.4} + size={big ? 24 : 20} + /> + {typeof repostCount !== 'undefined' ? ( + <Text + testID="repostCount" + style={ + isReposted + ? [s.bold, s.green3, s.f15, s.ml5] + : [defaultControlColor, s.f15, s.ml5] + }> + {repostCount} + </Text> + ) : undefined} + </TouchableOpacity> + ) +} + +const styles = StyleSheet.create({ + control: { + flexDirection: 'row', + alignItems: 'center', + padding: 5, + margin: -5, + }, + reposted: { + color: colors.green3, + }, + repostCount: { + color: 'currentColor', + }, +}) |