tooot/src/components/Hashtag.tsx

53 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import { useNavigation } from '@react-navigation/native'
import { StackNavigationProp } from '@react-navigation/stack'
2021-01-16 00:00:31 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2021-01-24 02:25:43 +01:00
import React, { useCallback } from 'react'
2021-01-16 00:00:31 +01:00
import { Pressable, StyleSheet, Text } from 'react-native'
2021-01-24 02:25:43 +01:00
import analytics from './analytics'
2021-01-16 00:00:31 +01:00
export interface Props {
2021-01-24 02:25:43 +01:00
hashtag: Mastodon.Tag
onPress?: () => void
origin?: string
2021-01-16 00:00:31 +01:00
}
2021-01-24 02:25:43 +01:00
const ComponentHashtag: React.FC<Props> = ({
hashtag,
onPress: customOnPress,
origin
}) => {
2021-01-16 00:00:31 +01:00
const { theme } = useTheme()
2021-01-24 02:25:43 +01:00
const navigation = useNavigation<
StackNavigationProp<Nav.LocalStackParamList>
>()
const onPress = useCallback(() => {
analytics('search_account_press', { page: origin })
navigation.push('Screen-Shared-Hashtag', { hashtag: hashtag.name })
}, [])
2021-01-16 00:00:31 +01:00
return (
<Pressable
style={[styles.itemDefault, { borderBottomColor: theme.border }]}
2021-01-24 02:25:43 +01:00
onPress={customOnPress || onPress}
2021-01-16 00:00:31 +01:00
>
<Text style={[styles.itemHashtag, { color: theme.primary }]}>
2021-01-24 02:25:43 +01:00
#{hashtag.name}
2021-01-16 00:00:31 +01:00
</Text>
</Pressable>
)
}
const styles = StyleSheet.create({
itemDefault: {
padding: StyleConstants.Spacing.S * 1.5,
borderBottomWidth: StyleSheet.hairlineWidth
},
itemHashtag: {
...StyleConstants.FontStyle.M
}
})
export default ComponentHashtag