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'
|
2022-12-28 23:41:36 +01:00
|
|
|
import EmojisContext from './Context'
|
2021-05-09 21:59:03 +02:00
|
|
|
|
2022-09-18 01:02:25 +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
|
|
|
|
}
|
|
|
|
|
2022-09-18 01:02:25 +02:00
|
|
|
return (
|
|
|
|
<Pressable
|
2022-09-20 22:23:01 +02:00
|
|
|
disabled={!emojis.current || !emojis.current.length}
|
2022-09-18 01:02:25 +02:00
|
|
|
onPress={() => {
|
2022-09-18 23:28:14 +02:00
|
|
|
if (emojisState.targetIndex === -1) {
|
2022-09-18 01:02:25 +02:00
|
|
|
Keyboard.dismiss()
|
2021-05-09 21:59:03 +02:00
|
|
|
}
|
2022-09-18 23:28:14 +02:00
|
|
|
emojisDispatch({ type: 'target', payload: focusedPropsIndex })
|
2022-09-18 01:02:25 +02:00
|
|
|
}}
|
|
|
|
hitSlop={StyleConstants.Spacing.S}
|
2022-09-18 16:49:18 +02:00
|
|
|
style={{
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
padding: StyleConstants.Spacing.Global.PagePadding / 2
|
|
|
|
}}
|
2022-09-18 01:02:25 +02:00
|
|
|
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>
|
2022-09-18 01:02:25 +02:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2021-05-09 21:59:03 +02:00
|
|
|
|
|
|
|
export default EmojisButton
|