tooot/src/components/Hashtag.tsx

49 lines
1.2 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<
2021-01-30 01:29:15 +01:00
StackNavigationProp<Nav.TabLocalStackParamList>
2021-01-24 02:25:43 +01:00
>()
const onPress = useCallback(() => {
analytics('search_account_press', { page: origin })
2021-01-30 01:29:15 +01:00
navigation.push('Tab-Shared-Hashtag', { hashtag: hashtag.name })
2021-01-24 02:25:43 +01:00
}, [])
2021-01-16 00:00:31 +01:00
return (
2021-02-05 01:13:57 +01:00
<Pressable style={styles.itemDefault} onPress={customOnPress || onPress}>
<Text style={[styles.itemHashtag, { color: theme.primaryDefault }]}>
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: {
2021-02-05 01:13:57 +01:00
padding: StyleConstants.Spacing.S * 1.5
2021-01-16 00:00:31 +01:00
},
itemHashtag: {
...StyleConstants.FontStyle.M
}
})
export default ComponentHashtag