@@ -216,15 +216,16 @@ const Menu = ({
216216 const prevVisible = React . useRef < boolean | null > ( null ) ;
217217 const anchorRef = React . useRef < View | null > ( null ) ;
218218 const menuRef = React . useRef < View | null > ( null ) ;
219+ const prevRendered = React . useRef ( false ) ;
219220
220- const keyboardDidShow = ( e : RNKeyboardEvent ) => {
221+ const keyboardDidShow = React . useCallback ( ( e : RNKeyboardEvent ) => {
221222 const keyboardHeight = e . endCoordinates . height ;
222223 keyboardHeightRef . current = keyboardHeight ;
223- } ;
224+ } , [ ] ) ;
224225
225- const keyboardDidHide = ( ) => {
226+ const keyboardDidHide = React . useCallback ( ( ) => {
226227 keyboardHeightRef . current = 0 ;
227- } ;
228+ } , [ ] ) ;
228229
229230 const keyboardDidShowListenerRef : React . MutableRefObject <
230231 EmitterSubscription | undefined
@@ -244,7 +245,6 @@ const Menu = ({
244245 if ( visible ) {
245246 onDismiss ?.( ) ;
246247 }
247- return true ;
248248 } , [ onDismiss , visible ] ) ;
249249
250250 const handleKeypress = React . useCallback (
@@ -362,6 +362,7 @@ const Menu = ({
362362 ] ) . start ( ( { finished } ) => {
363363 if ( finished ) {
364364 focusFirstDOMNode ( menuRef . current ) ;
365+ prevRendered . current = true ;
365366 }
366367 } ) ;
367368 } , [ anchor , attachListeners , measureAnchorLayout , theme ] ) ;
@@ -380,6 +381,7 @@ const Menu = ({
380381 if ( finished ) {
381382 setMenuLayout ( { width : 0 , height : 0 } ) ;
382383 setRendered ( false ) ;
384+ prevRendered . current = false ;
383385 focusFirstDOMNode ( anchorRef . current ) ;
384386 }
385387 } ) ;
@@ -390,16 +392,18 @@ const Menu = ({
390392 // Menu is rendered in Portal, which updates items asynchronously
391393 // We need to do the same here so that the ref is up-to-date
392394 await Promise . resolve ( ) . then ( ( ) => {
393- if ( display ) {
395+ if ( display && ! prevRendered . current ) {
394396 show ( ) ;
395397 } else {
396- hide ( ) ;
398+ if ( rendered ) {
399+ hide ( ) ;
400+ }
397401 }
398402
399403 return ;
400404 } ) ;
401405 } ,
402- [ show , hide ]
406+ [ hide , show , rendered ]
403407 ) ;
404408
405409 React . useEffect ( ( ) => {
@@ -421,7 +425,7 @@ const Menu = ({
421425 scaleAnimation . removeAllListeners ( ) ;
422426 opacityAnimation ?. removeAllListeners ( ) ;
423427 } ;
424- } , [ removeListeners ] ) ;
428+ } , [ removeListeners , keyboardDidHide , keyboardDidShow ] ) ;
425429
426430 React . useEffect ( ( ) => {
427431 if ( prevVisible . current !== visible ) {
0 commit comments