Fix: emoji picker closes when hitting spacebar (#4422) (#4441)

Co-authored-by: Hailey <me@haileyok.com>
zio/stable
Michał Gołda 2024-07-12 04:42:41 +02:00 committed by GitHub
parent a71134f467
commit cd9bba4b69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 21 deletions

View File

@ -1,11 +1,13 @@
import React from 'react' import React from 'react'
import Picker from '@emoji-mart/react'
import { import {
StyleSheet, GestureResponderEvent,
TouchableWithoutFeedback, TouchableWithoutFeedback,
useWindowDimensions, useWindowDimensions,
View, View,
} from 'react-native' } from 'react-native'
import Picker from '@emoji-mart/react'
import {atoms as a} from '#/alf'
import {textInputWebEmitter} from '../TextInput.web' import {textInputWebEmitter} from '../TextInput.web'
const HEIGHT_OFFSET = 40 const HEIGHT_OFFSET = 40
@ -96,12 +98,29 @@ export function EmojiPicker({state, close}: IProps) {
if (!state.isOpen) return null if (!state.isOpen) return null
const onPressBackdrop = (e: GestureResponderEvent) => {
// @ts-ignore web only
if (e.nativeEvent?.pointerId === -1) return
close()
}
return ( return (
<TouchableWithoutFeedback <TouchableWithoutFeedback
accessibilityRole="button" accessibilityRole="button"
onPress={close} onPress={onPressBackdrop}
accessibilityViewIsModal> accessibilityViewIsModal>
<View style={styles.mask}> <View
style={[
a.fixed,
a.w_full,
a.h_full,
a.align_center,
{
top: 0,
left: 0,
right: 0,
},
]}>
{/* eslint-disable-next-line react-native-a11y/has-valid-accessibility-descriptors */} {/* eslint-disable-next-line react-native-a11y/has-valid-accessibility-descriptors */}
<TouchableWithoutFeedback onPress={e => e.stopPropagation()}> <TouchableWithoutFeedback onPress={e => e.stopPropagation()}>
<View style={[{position: 'absolute'}, position]}> <View style={[{position: 'absolute'}, position]}>
@ -118,20 +137,3 @@ export function EmojiPicker({state, close}: IProps) {
</TouchableWithoutFeedback> </TouchableWithoutFeedback>
) )
} }
const styles = StyleSheet.create({
mask: {
// @ts-ignore web ony
position: 'fixed',
top: 0,
left: 0,
right: 0,
width: '100%',
height: '100%',
alignItems: 'center',
},
picker: {
marginHorizontal: 'auto',
paddingRight: 50,
},
})