Skip to content

Commit 9425c85

Browse files
authored
Fix/incubator dialog fader visibility and more (#2379)
* Improve fade view's code and fix not being shown sometimes * Change imports * Do not set pointerEvents by default (allow via props)
1 parent 87641d8 commit 9425c85

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

src/incubator/Dialog/dialog.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"type": "ViewStyle",
1414
"description": "The Dialog`s container style (it is set to {position: 'absolute'})"
1515
},
16+
{
17+
"name": "containerProps",
18+
"type": "ViewProps",
19+
"description": "Extra props for the container"
20+
},
1621
{
1722
"name": "onDismiss",
1823
"type": "(props?: DialogProps) => void",

src/incubator/Dialog/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {StyleSheet, View as RNView} from 'react-native';
44
import hoistStatics from 'hoist-non-react-statics';
55
import {useAnimatedStyle, useDerivedValue} from 'react-native-reanimated';
66
import {PanGestureHandler} from 'react-native-gesture-handler';
7-
import {Spacings, Colors, BorderRadiuses} from 'style';
7+
import {Spacings, Colors, BorderRadiuses} from '../../style';
88
import {asBaseComponent} from '../../commons/new';
9-
import {useDidUpdate} from 'hooks';
9+
import {useDidUpdate} from '../../hooks';
1010
import View from '../../components/view';
1111
import Modal from '../../components/modal';
1212
import {extractAlignmentsValues} from '../../commons/modifiers';
@@ -34,6 +34,7 @@ const Dialog = (props: DialogProps, ref: ForwardedRef<DialogImperativeMethods>)
3434
visible: propsVisibility = false,
3535
headerProps,
3636
containerStyle,
37+
containerProps,
3738
width,
3839
height,
3940
onDismiss,
@@ -163,7 +164,7 @@ const Dialog = (props: DialogProps, ref: ForwardedRef<DialogImperativeMethods>)
163164
const renderDialog = () => {
164165
return (
165166
<PanGestureHandler onGestureEvent={isEmpty(directions) ? undefined : panGestureEvent}>
166-
<View pointerEvents={'box-none'} reanimated style={style} onLayout={onLayout} ref={setRef} testID={testID}>
167+
<View {...containerProps} reanimated style={style} onLayout={onLayout} ref={setRef} testID={testID}>
167168
{headerProps && <DialogHeader {...headerProps}/>}
168169
{children}
169170
</View>

src/incubator/Dialog/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export interface _DialogProps extends AlignmentModifiers, Pick<ViewProps, 'useSa
7777
* The Dialog`s container style (it is set to {position: 'absolute'})
7878
*/
7979
containerStyle?: StyleProp<ViewStyle>;
80+
/**
81+
* Extra props for the container
82+
*/
83+
containerProps?: Omit<ViewProps, 'reanimated' | 'animated' | 'style' | 'onLayout' | 'ref' | 'testID'>;
8084
/**
8185
* The dialog width.
8286
*/

src/incubator/Dialog/useAnimatedTransition.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable react-hooks/exhaustive-deps */
22
import {useEffect, useCallback} from 'react';
33
import {
4-
runOnJS,
54
useSharedValue,
65
withSpring,
76
withTiming,
@@ -113,21 +112,15 @@ export default function useAnimatedTransition(props: AnimatedTransitionProps) {
113112
const animateIn = useCallback(() => {
114113
'worklet';
115114
if (enterFrom) {
116-
if (onAnimationStart) {
117-
runOnJS(onAnimationStart)('enter');
118-
}
119-
115+
onAnimationStart?.('enter');
120116
translateTo({x: 0, y: 0}, withSpring, ENTER_ANIMATION_CONFIG, enterFrom, onEnterAnimationEnd, delay?.enter);
121117
}
122118
}, [onEnterAnimationEnd, delay?.enter]);
123119

124120
const animateOut = useCallback(() => {
125121
'worklet';
126122
if (exitTo) {
127-
if (onAnimationStart) {
128-
runOnJS(onAnimationStart)('exit');
129-
}
130-
123+
onAnimationStart?.('exit');
131124
translateTo(getLocation(exitTo), withTiming, EXIT_ANIMATION_CONFIG, exitTo, onExitAnimationEnd, delay?.exit);
132125
}
133126
}, [hiddenLocation, exitTo, onExitAnimationEnd, delay?.exit]);

src/incubator/Dialog/useFadeView.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react-hooks/exhaustive-deps */
22
import React, {useCallback} from 'react';
33
import {useSharedValue, withTiming, useAnimatedStyle} from 'react-native-reanimated';
4-
import {Colors} from 'style';
4+
import {Colors} from '../../style';
55
import View from '../../components/view';
66
import {ModalProps} from '../../components/modal';
77
import {TransitionViewAnimationType} from './useAnimatedTransition';
@@ -19,19 +19,23 @@ export interface FadeViewMethods {
1919

2020
const useFadeView = (props: FadeViewProps) => {
2121
const {visible, overlayBackgroundColor = DEFAULT_OVERLAY_BACKGROUND_COLORS, testID} = props;
22-
const fadeOpacity = useSharedValue<number>(Number(visible));
22+
const fadeOpacity = useSharedValue<0 | 1>(visible ? 1 : 0);
2323

2424
const hideNow = useCallback(() => {
2525
fadeOpacity.value = 0;
2626
}, []);
2727

2828
const fade = useCallback((type: AnimationType) => {
29-
fadeOpacity.value = withTiming(Number(type === 'enter'), {duration: 300});
29+
'worklet';
30+
const newValue = type === 'enter' ? 1 : 0;
31+
if (fadeOpacity.value !== newValue) {
32+
fadeOpacity.value = newValue;
33+
}
3034
}, []);
3135

3236
const fadeStyle = useAnimatedStyle(() => {
3337
return {
34-
opacity: fadeOpacity.value,
38+
opacity: withTiming(fadeOpacity.value, {duration: 300}),
3539
backgroundColor: overlayBackgroundColor
3640
};
3741
}, [overlayBackgroundColor]);

0 commit comments

Comments
 (0)