From 60bfb612ab99e4550f74dabd558b4afc2ce5c948 Mon Sep 17 00:00:00 2001 From: christianwenifr Date: Sat, 20 May 2023 19:30:34 +0700 Subject: [PATCH] fix: buttons attachment not responsive ios --- src/components/PopoverMenu/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/PopoverMenu/index.js b/src/components/PopoverMenu/index.js index 5b5eadffcdce..17982c0d5684 100644 --- a/src/components/PopoverMenu/index.js +++ b/src/components/PopoverMenu/index.js @@ -1,5 +1,5 @@ import _ from 'underscore'; -import React from 'react'; +import React, {useState} from 'react'; import PropTypes from 'prop-types'; import {View} from 'react-native'; import PopoverWithMeasuredContent from '../PopoverWithMeasuredContent'; @@ -40,11 +40,12 @@ const defaultProps = { const PopoverMenu = (props) => { const {isSmallScreenWidth} = useWindowDimensions(); + const [selectedItemIndex, setSelectedItemIndex] = useState(null); const selectItem = (index) => { const selectedItem = props.menuItems[index]; props.onItemSelected(selectedItem); - selectedItem.onSelected(); + setSelectedItemIndex(index); }; const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: -1, maxIndex: props.menuItems.length - 1}); @@ -66,7 +67,13 @@ const PopoverMenu = (props) => { anchorAlignment={props.anchorOrigin} onClose={props.onClose} isVisible={props.isVisible} - onModalHide={() => setFocusedIndex(-1)} + onModalHide={() => { + setFocusedIndex(-1); + if (selectedItemIndex !== null) { + props.menuItems[selectedItemIndex].onSelected(); + setSelectedItemIndex(null); + } + }} animationIn={props.animationIn} animationOut={props.animationOut} animationInTiming={props.animationInTiming}