tooot/src/components/Emojis/Button.tsx

55 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-09-20 22:23:01 +02:00
import { emojis } from '@components/Emojis'
2021-05-09 21:59:03 +02:00
import Icon from '@components/Icon'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { useContext } from 'react'
2022-09-18 16:49:18 +02:00
import { Keyboard, Pressable, View } from 'react-native'
import EmojisContext from './Context'
2021-05-09 21:59:03 +02:00
const EmojisButton: React.FC = () => {
const { colors } = useTheme()
const { emojisState, emojisDispatch } = useContext(EmojisContext)
2021-05-09 21:59:03 +02:00
2022-09-18 23:28:14 +02:00
const focusedPropsIndex = emojisState.inputProps?.findIndex(props => props.isFocused.current)
if (focusedPropsIndex === -1) {
return null
}
return (
<Pressable
2022-09-20 22:23:01 +02:00
disabled={!emojis.current || !emojis.current.length}
onPress={() => {
2022-09-18 23:28:14 +02:00
if (emojisState.targetIndex === -1) {
Keyboard.dismiss()
2021-05-09 21:59:03 +02:00
}
2022-09-18 23:28:14 +02:00
emojisDispatch({ type: 'target', payload: focusedPropsIndex })
}}
hitSlop={StyleConstants.Spacing.S}
2022-09-18 16:49:18 +02:00
style={{
alignSelf: 'flex-end',
padding: StyleConstants.Spacing.Global.PagePadding / 2
}}
children={
2022-09-18 16:49:18 +02:00
<View
style={{
borderWidth: 2,
borderColor: colors.primaryDefault,
padding: StyleConstants.Spacing.Global.PagePadding / 2,
borderRadius: 100
}}
>
<Icon
2022-09-20 22:23:01 +02:00
name={emojis.current && emojis.current.length ? 'Smile' : 'Meh'}
2022-09-18 16:49:18 +02:00
size={24}
color={
2022-09-20 22:23:01 +02:00
emojis.current && emojis.current.length ? colors.primaryDefault : colors.disabled
2022-09-18 16:49:18 +02:00
}
/>
</View>
}
/>
)
}
2021-05-09 21:59:03 +02:00
export default EmojisButton