@@ -7,6 +7,8 @@ import type {
7
7
AnimatedViewStyleProp ,
8
8
} from '../../TypeDefinition' ;
9
9
10
+ import getSceneIndicesForInterpolationInputRange from '../../utils/getSceneIndicesForInterpolationInputRange' ;
11
+
10
12
/**
11
13
* Utility that builds the style for the card in the cards stack.
12
14
*
@@ -51,33 +53,25 @@ function forHorizontal(
51
53
if ( ! layout . isMeasured ) {
52
54
return forInitial ( props ) ;
53
55
}
56
+ const interpolate = getSceneIndicesForInterpolationInputRange ( props ) ;
54
57
55
- const index = scene . index ;
56
- const inputRange = [ index - 1 , index , index + 1 ] ;
58
+ if ( ! interpolate ) return { opacity : 0 } ;
57
59
58
- const width = layout . initWidth ;
59
- const outputRange = I18nManager . isRTL
60
- ? ( [ - width , 0 , width * 0.3 ] : Array < number > )
61
- : ( [ width , 0 , width * - 0.3 ] : Array < number > ) ;
62
-
63
- // Add [index - 1, index - 0.99] to the interpolated opacity for screen transition.
64
- // This makes the screen's shadow to disappear smoothly.
60
+ const { first, last } = interpolate ;
61
+ const index = scene . index ;
65
62
const opacity = position . interpolate ( {
66
- inputRange : ( [
67
- index - 1 ,
68
- index - 0.99 ,
69
- index ,
70
- index + 0.99 ,
71
- index + 1 ,
72
- ] : Array < number > ) ,
63
+ inputRange : [ first , first + 0.01 , index , last - 0.01 , last ] ,
73
64
outputRange : ( [ 0 , 1 , 1 , 0.85 , 0 ] : Array < number > ) ,
74
65
} ) ;
75
66
76
- const translateY = 0 ;
67
+ const width = layout . initWidth ;
77
68
const translateX = position . interpolate ( {
78
- inputRange,
79
- outputRange,
69
+ inputRange : ( [ first , index , last ] : Array < number > ) ,
70
+ outputRange : I18nManager . isRTL
71
+ ? ( [ - width , 0 , width * 0.3 ] : Array < number > )
72
+ : ( [ width , 0 , width * - 0.3 ] : Array < number > ) ,
80
73
} ) ;
74
+ const translateY = 0 ;
81
75
82
76
return {
83
77
opacity,
@@ -96,26 +90,23 @@ function forVertical(
96
90
if ( ! layout . isMeasured ) {
97
91
return forInitial ( props ) ;
98
92
}
93
+ const interpolate = getSceneIndicesForInterpolationInputRange ( props ) ;
99
94
100
- const index = scene . index ;
101
- const height = layout . initHeight ;
95
+ if ( ! interpolate ) return { opacity : 0 } ;
102
96
97
+ const { first, last } = interpolate ;
98
+ const index = scene . index ;
103
99
const opacity = position . interpolate ( {
104
- inputRange : ( [
105
- index - 1 ,
106
- index - 0.99 ,
107
- index ,
108
- index + 0.99 ,
109
- index + 1 ,
110
- ] : Array < number > ) ,
100
+ inputRange : [ first , first + 0.01 , index , last - 0.01 , last ] ,
111
101
outputRange : ( [ 0 , 1 , 1 , 0.85 , 0 ] : Array < number > ) ,
112
102
} ) ;
113
103
114
- const translateX = 0 ;
104
+ const height = layout . initHeight ;
115
105
const translateY = position . interpolate ( {
116
- inputRange : ( [ index - 1 , index , index + 1 ] : Array < number > ) ,
106
+ inputRange : ( [ first , index , last ] : Array < number > ) ,
117
107
outputRange : ( [ height , 0 , 0 ] : Array < number > ) ,
118
108
} ) ;
109
+ const translateX = 0 ;
119
110
120
111
return {
121
112
opacity,
@@ -134,27 +125,56 @@ function forFadeFromBottomAndroid(
134
125
if ( ! layout . isMeasured ) {
135
126
return forInitial ( props ) ;
136
127
}
128
+ const interpolate = getSceneIndicesForInterpolationInputRange ( props ) ;
129
+
130
+ if ( ! interpolate ) return { opacity : 0 } ;
137
131
132
+ const { first, last } = interpolate ;
138
133
const index = scene . index ;
139
- const inputRange = [ index - 1 , index , index + 0.99 , index + 1 ] ;
134
+ const inputRange = ( [ first , index , last - 0.01 , last ] : Array < number > ) ;
140
135
141
136
const opacity = position . interpolate ( {
142
137
inputRange,
143
138
outputRange : ( [ 0 , 1 , 1 , 0 ] : Array < number > ) ,
144
139
} ) ;
145
140
146
- const translateX = 0 ;
147
141
const translateY = position . interpolate ( {
148
142
inputRange,
149
143
outputRange : ( [ 50 , 0 , 0 , 0 ] : Array < number > ) ,
150
144
} ) ;
145
+ const translateX = 0 ;
151
146
152
147
return {
153
148
opacity,
154
149
transform : [ { translateX } , { translateY } ] ,
155
150
} ;
156
151
}
157
152
153
+ /**
154
+ * fadeIn and fadeOut
155
+ */
156
+ function forFade ( props : NavigationSceneRendererProps ) : AnimatedViewStyleProp {
157
+ const { layout, position, scene } = props ;
158
+
159
+ if ( ! layout . isMeasured ) {
160
+ return forInitial ( props ) ;
161
+ }
162
+ const interpolate = getSceneIndicesForInterpolationInputRange ( props ) ;
163
+
164
+ if ( ! interpolate ) return { opacity : 0 } ;
165
+
166
+ const { first, last } = interpolate ;
167
+ const index = scene . index ;
168
+ const opacity = position . interpolate ( {
169
+ inputRange : ( [ first , index , last ] : Array < number > ) ,
170
+ outputRange : ( [ 0 , 1 , 1 ] : Array < number > ) ,
171
+ } ) ;
172
+
173
+ return {
174
+ opacity,
175
+ } ;
176
+ }
177
+
158
178
function canUseNativeDriver ( ) : boolean {
159
179
// The native driver can be enabled for this interpolator animating
160
180
// opacity, translateX, and translateY is supported by the native animation
@@ -166,5 +186,6 @@ export default {
166
186
forHorizontal,
167
187
forVertical,
168
188
forFadeFromBottomAndroid,
189
+ forFade,
169
190
canUseNativeDriver,
170
191
} ;
0 commit comments