TransitionConfigs.js.flow
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* @flow */
import { Animated, Easing, Platform } from 'react-native';
import type {
NavigationTransitionProps,
NavigationTransitionSpec,
TransitionConfig,
} from '../../TypeDefinition';
import CardStackStyleInterpolator from './CardStackStyleInterpolator';
const IOSTransitionSpec = ({
duration: 500,
easing: Easing.bezier(0.2833, 0.99, 0.31833, 0.99),
timing: Animated.timing,
}: NavigationTransitionSpec);
// Standard iOS navigation transition
const SlideFromRightIOS = ({
transitionSpec: IOSTransitionSpec,
screenInterpolator: CardStackStyleInterpolator.forHorizontal,
containerStyle: {
backgroundColor: '#000',
},
}: TransitionConfig);
// Standard iOS navigation transition for modals
const ModalSlideFromBottomIOS = ({
transitionSpec: IOSTransitionSpec,
screenInterpolator: CardStackStyleInterpolator.forVertical,
containerStyle: {
backgroundColor: '#000',
},
}: TransitionConfig);
// Standard Android navigation transition when opening an Activity
const FadeInFromBottomAndroid = ({
// See http://androidxref.com/7.1.1_r6/xref/frameworks/base/core/res/res/anim/activity_open_enter.xml
transitionSpec: {
duration: 350,
easing: Easing.out(Easing.poly(5)), // decelerate
timing: Animated.timing,
},
screenInterpolator: CardStackStyleInterpolator.forFadeFromBottomAndroid,
}: TransitionConfig);
// Standard Android navigation transition when closing an Activity
const FadeOutToBottomAndroid = ({
// See http://androidxref.com/7.1.1_r6/xref/frameworks/base/core/res/res/anim/activity_close_exit.xml
transitionSpec: {
duration: 230,
easing: Easing.in(Easing.poly(4)), // accelerate
timing: Animated.timing,
},
screenInterpolator: CardStackStyleInterpolator.forFadeFromBottomAndroid,
}: TransitionConfig);
function defaultTransitionConfig(
// props for the new screen
transitionProps: NavigationTransitionProps,
// props for the old screen
prevTransitionProps: ?NavigationTransitionProps,
// whether we're animating in/out a modal screen
isModal: boolean
): TransitionConfig {
if (Platform.OS === 'android') {
// Use the default Android animation no matter if the screen is a modal.
// Android doesn't have full-screen modals like iOS does, it has dialogs.
if (
prevTransitionProps &&
transitionProps.index < prevTransitionProps.index
) {
// Navigating back to the previous screen
return FadeOutToBottomAndroid;
}
return FadeInFromBottomAndroid;
}
// iOS and other platforms
if (isModal) {
return ModalSlideFromBottomIOS;
}
return SlideFromRightIOS;
}
function getTransitionConfig(
transitionConfigurer?: (
transitionProps: NavigationTransitionProps,
prevTransitionProps: ?NavigationTransitionProps,
isModal: boolean
) => TransitionConfig,
// props for the new screen
transitionProps: NavigationTransitionProps,
// props for the old screen
prevTransitionProps: ?NavigationTransitionProps,
isModal: boolean
): TransitionConfig {
const defaultConfig = defaultTransitionConfig(
transitionProps,
prevTransitionProps,
isModal
);
if (transitionConfigurer) {
return {
...defaultConfig,
...transitionConfigurer(transitionProps, prevTransitionProps, isModal),
};
}
return defaultConfig;
}
export default {
defaultTransitionConfig,
getTransitionConfig,
};