@@ -90,9 +90,21 @@ export const MenuItem = forwardRef((props: Partial<MenuItemProps>, ref) => {
9090 useEffect ( ( ) => {
9191 setShowPopup ( show )
9292 } , [ show ] )
93+
94+ const getParentOffset = useCallback ( ( ) => {
95+ setTimeout ( async ( ) => {
96+ const p = parent . menuRef . current
97+ const rect = await getRectByTaro ( p )
98+ setPosition ( {
99+ height : rect . height ,
100+ top : rect . top ,
101+ } )
102+ } , 100 )
103+ } , [ parent . menuRef ] )
104+
93105 useEffect ( ( ) => {
94106 getParentOffset ( )
95- } , [ showPopup ] )
107+ } , [ showPopup , getParentOffset ] )
96108
97109 const windowHeight = useMemo ( ( ) => getSystemInfoSync ( ) . windowHeight , [ ] )
98110 const updateItemOffset = useCallback ( ( ) => {
@@ -106,7 +118,8 @@ export const MenuItem = forwardRef((props: Partial<MenuItemProps>, ref) => {
106118 } )
107119 }
108120 } )
109- } , [ direction , windowHeight ] )
121+ } , [ direction , windowHeight , parent . lockScroll , parent . menuRef ] )
122+
110123 usePageScroll ( updateItemOffset )
111124
112125 useImperativeHandle < any , any > ( ref , ( ) => ( {
@@ -136,16 +149,7 @@ export const MenuItem = forwardRef((props: Partial<MenuItemProps>, ref) => {
136149 top : 0 ,
137150 height : 0 ,
138151 } )
139- const getParentOffset = ( ) => {
140- setTimeout ( async ( ) => {
141- const p = parent . menuRef . current
142- const rect = await getRectByTaro ( p )
143- setPosition ( {
144- height : rect . height ,
145- top : rect . top ,
146- } )
147- } , 100 )
148- }
152+
149153 const isShow = ( ) => {
150154 if ( showPopup ) return { }
151155 return { display : 'none' }
0 commit comments