tooot/src/components/Emojis/Button.tsx

55 lines
1.6 KiB
TypeScript

import Icon from '@components/Icon'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { useContext } from 'react'
import { Keyboard, Pressable, View } from 'react-native'
import EmojisContext from './helpers/EmojisContext'
const EmojisButton: React.FC = () => {
const { colors } = useTheme()
const { emojisState, emojisDispatch } = useContext(EmojisContext)
return (
<Pressable
disabled={!emojisState.emojis || !emojisState.emojis.length}
onPress={() => {
const targetProps = emojisState.inputProps?.find(props => props.ref.current?.isFocused())
if (!targetProps) {
return
}
if (emojisState.targetProps === null) {
Keyboard.dismiss()
}
emojisDispatch({ type: 'target', payload: targetProps })
}}
hitSlop={StyleConstants.Spacing.S}
style={{
alignSelf: 'flex-end',
padding: StyleConstants.Spacing.Global.PagePadding / 2
}}
children={
<View
style={{
borderWidth: 2,
borderColor: colors.primaryDefault,
padding: StyleConstants.Spacing.Global.PagePadding / 2,
borderRadius: 100
}}
>
<Icon
name={emojisState.emojis && emojisState.emojis.length ? 'Smile' : 'Meh'}
size={24}
color={
emojisState.emojis && emojisState.emojis.length
? colors.primaryDefault
: colors.disabled
}
/>
</View>
}
/>
)
}
export default EmojisButton