diff --git a/packages/react-native-ui-lib/src/components/hint/hooks/useHintLayout.ts b/packages/react-native-ui-lib/src/components/hint/hooks/useHintLayout.ts index f70d98024f..8efa7267ce 100644 --- a/packages/react-native-ui-lib/src/components/hint/hooks/useHintLayout.ts +++ b/packages/react-native-ui-lib/src/components/hint/hooks/useHintLayout.ts @@ -1,4 +1,4 @@ -import {type ElementRef, useState, useCallback, useRef} from 'react'; +import {type ElementRef, useState, useCallback, useRef, useEffect} from 'react'; import type {LayoutChangeEvent, LayoutRectangle, View as RNView} from 'react-native'; import _ from 'lodash'; import {HintProps} from '../types'; @@ -11,6 +11,14 @@ export default function useHintLayout({onBackgroundPress, targetFrame}: UseHintL const [hintMessageWidth, setHintMessageWidth] = useState(); const targetRef = useRef | null>(null); + useEffect(() => { + if (targetFrame && !_.isEqual(targetFrame, targetLayoutState)) { + setTargetLayout(targetFrame); + setTargetLayoutInWindow(targetFrame); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [targetFrame]); + const onTargetLayout = useCallback(({nativeEvent: {layout}}: LayoutChangeEvent) => { if (!_.isEqual(targetLayoutState, layout)) { setTargetLayout(layout);