Skip to content

Commit 585ffe1

Browse files
committed
Incubator.Dialog - fix hiding (#2299)
(cherry picked from commit 13a8c99)
1 parent da8ab93 commit 585ffe1

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/incubator/Dialog/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ const Dialog = (props: DialogProps) => {
6363
const onTransitionAnimationEnd = useCallback((type: TransitionViewAnimationType) => {
6464
if (type === 'exit') {
6565
setVisible(false);
66+
opacity.value = withTiming(0, {duration: 0});
6667
onDismiss?.();
6768
}
6869
},
70+
// eslint-disable-next-line react-hooks/exhaustive-deps
6971
[onDismiss, setVisible]);
7072

7173
const {setRef, onLayout, hiddenLocation} = useHiddenLocation<RNView>();

src/incubator/Dialog/useAnimatedTransition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default function useAnimatedTransition(props: AnimatedTransitionProps) {
8181
const location = getLocation(enterFrom);
8282
initPosition(location, enterFrom, animateIn);
8383
}
84-
}, [hiddenLocation.wasMeasured]);
84+
}, [hiddenLocation]);
8585

8686
const translateTo = useCallback((to: {x: number; y: number},
8787
animationDirection: TransitionViewDirection,

src/incubator/hooks/useHiddenLocation.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import {isEqual} from 'lodash';
12
import {useCallback, useRef, useState, RefCallback} from 'react';
2-
import {View} from 'react-native';
3+
import {View, LayoutChangeEvent, LayoutRectangle} from 'react-native';
34
import {Constants} from '../../commons/new';
45
import {PanningDirectionsEnum} from '../panView';
56

@@ -28,22 +29,20 @@ export default function useHiddenLocation<T extends View>() {
2829

2930
const [hiddenLocation, setHiddenLocation] = useState<HiddenLocation>(getHiddenLocation({}));
3031
const ref = useRef<T>();
32+
const layoutData = useRef<LayoutRectangle>();
3133
const wasMeasured = useRef(false);
3234

3335
const measure = useCallback(() => {
34-
if (!wasMeasured.current) {
35-
ref.current?.measureInWindow((x, y, width, height) => {
36-
if (!wasMeasured.current && width > 0 && height > 0) {
37-
wasMeasured.current = true;
38-
setHiddenLocation(getHiddenLocation({
39-
x,
40-
y,
41-
width,
42-
height,
43-
wasMeasured: true
44-
}));
45-
}
46-
});
36+
if (ref.current && layoutData.current && layoutData.current.width > 0 && layoutData.current.height > 0) {
37+
wasMeasured.current = true;
38+
const {x, y, width, height} = layoutData.current;
39+
setHiddenLocation(getHiddenLocation({
40+
x,
41+
y,
42+
width,
43+
height,
44+
wasMeasured: true
45+
}));
4746
}
4847
}, []);
4948

@@ -55,9 +54,13 @@ export default function useHiddenLocation<T extends View>() {
5554
},
5655
[measure]);
5756

58-
const onLayout = useCallback(() => {
59-
measure();
60-
}, [measure]);
57+
const onLayout = useCallback((event: LayoutChangeEvent) => {
58+
if (!isEqual(layoutData.current, event.nativeEvent.layout)) {
59+
layoutData.current = event.nativeEvent.layout;
60+
measure();
61+
}
62+
},
63+
[measure]);
6164

6265
return {setRef, onLayout, hiddenLocation};
6366
}

0 commit comments

Comments
 (0)