@@ -34,21 +34,6 @@ const EmojiPicker = forwardRef((props, ref) => {
34
34
const onEmojiSelected = useRef ( ( ) => { } ) ;
35
35
const emojiSearchInput = useRef ( ) ;
36
36
37
- useEffect ( ( ) => {
38
- if ( isEmojiPickerVisible ) {
39
- Keyboard . dismiss ( ) ;
40
- }
41
-
42
- const emojiPopoverDimensionListener = Dimensions . addEventListener ( 'change' , ( ) => {
43
- calculateAnchorPosition ( emojiPopoverAnchor . current ) . then ( ( value ) => {
44
- setEmojiPopoverAnchorPosition ( value ) ;
45
- } ) ;
46
- } ) ;
47
- return ( ) => {
48
- emojiPopoverDimensionListener . remove ( ) ;
49
- } ;
50
- } , [ isEmojiPickerVisible ] ) ;
51
-
52
37
/**
53
38
* Show the emoji picker menu.
54
39
*
@@ -110,9 +95,7 @@ const EmojiPicker = forwardRef((props, ref) => {
110
95
const selectEmoji = ( emoji , emojiObject ) => {
111
96
// Prevent fast click / multiple emoji selection;
112
97
// The first click will hide the emoji picker by calling the hideEmojiPicker() function
113
- // and in that function the emojiPopoverAnchor ref to will be set to null (synchronously)
114
- // thus we rely on that prop to prevent fast click / multiple emoji selection
115
- if ( ! emojiPopoverAnchor . current ) {
98
+ if ( ! isEmojiPickerVisible ) {
116
99
return ;
117
100
}
118
101
@@ -130,7 +113,31 @@ const EmojiPicker = forwardRef((props, ref) => {
130
113
*/
131
114
const isActiveReportAction = ( actionID ) => Boolean ( actionID ) && reportAction . reportActionID === actionID ;
132
115
133
- useImperativeHandle ( ref , ( ) => ( { showEmojiPicker, isActiveReportAction, hideEmojiPicker, isEmojiPickerVisible} ) ) ;
116
+ const resetEmojiPopoverAnchor = ( ) => ( emojiPopoverAnchor . current = null ) ;
117
+
118
+ useImperativeHandle ( ref , ( ) => ( { showEmojiPicker, isActiveReportAction, hideEmojiPicker, isEmojiPickerVisible, resetEmojiPopoverAnchor} ) ) ;
119
+
120
+ useEffect ( ( ) => {
121
+ if ( isEmojiPickerVisible ) {
122
+ Keyboard . dismiss ( ) ;
123
+ }
124
+
125
+ const emojiPopoverDimensionListener = Dimensions . addEventListener ( 'change' , ( ) => {
126
+ if ( ! emojiPopoverAnchor . current ) {
127
+ // In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
128
+ if ( isEmojiPickerVisible && ! props . isSmallScreenWidth ) {
129
+ hideEmojiPicker ( ) ;
130
+ }
131
+ return ;
132
+ }
133
+ calculateAnchorPosition ( emojiPopoverAnchor . current ) . then ( ( value ) => {
134
+ setEmojiPopoverAnchorPosition ( value ) ;
135
+ } ) ;
136
+ } ) ;
137
+ return ( ) => {
138
+ emojiPopoverDimensionListener . remove ( ) ;
139
+ } ;
140
+ } , [ isEmojiPickerVisible , props . isSmallScreenWidth ] ) ;
134
141
135
142
// There is no way to disable animations, and they are really laggy, because there are so many
136
143
// emojis. The best alternative is to set it to 1ms so it just "pops" in and out
0 commit comments