@@ -45,6 +45,8 @@ type State = {
4545 rendered : boolean ;
4646} ;
4747
48+ const DEFAULT_DURATION = 220 ;
49+
4850/**
4951 * The Modal component is a simple way to present content above an enclosing view.
5052 * To render the `Modal` above other components, you'll need to wrap it with the [`Portal`](portal.html) component.
@@ -123,42 +125,40 @@ class Modal extends React.Component<Props, State> {
123125 } ;
124126
125127 private showModal = ( ) => {
126- const {
127- theme : {
128- animation : { scale } ,
129- } ,
130- } = this . props ;
131-
132128 BackHandler . removeEventListener ( 'hardwareBackPress' , this . handleBack ) ;
133129 BackHandler . addEventListener ( 'hardwareBackPress' , this . handleBack ) ;
134- Animated . timing ( this . state . opacity , {
130+
131+ const { opacity } = this . state ;
132+ const { scale } = this . props . theme . animation ;
133+
134+ Animated . timing ( opacity , {
135135 toValue : 1 ,
136- duration : scale * 280 ,
137- easing : Easing . ease ,
136+ duration : scale * DEFAULT_DURATION ,
137+ easing : Easing . out ( Easing . cubic ) ,
138138 useNativeDriver : true ,
139139 } ) . start ( ) ;
140140 } ;
141141
142142 private hideModal = ( ) => {
143- const {
144- theme : {
145- animation : { scale } ,
146- } ,
147- } = this . props ;
148-
149143 BackHandler . removeEventListener ( 'hardwareBackPress' , this . handleBack ) ;
150- Animated . timing ( this . state . opacity , {
144+
145+ const { opacity } = this . state ;
146+ const { scale } = this . props . theme . animation ;
147+
148+ Animated . timing ( opacity , {
151149 toValue : 0 ,
152- duration : scale * 280 ,
153- easing : Easing . ease ,
150+ duration : scale * DEFAULT_DURATION ,
151+ easing : Easing . out ( Easing . cubic ) ,
154152 useNativeDriver : true ,
155153 } ) . start ( ( { finished } ) => {
156154 if ( ! finished ) {
157155 return ;
158156 }
157+
159158 if ( this . props . visible && this . props . onDismiss ) {
160159 this . props . onDismiss ( ) ;
161160 }
161+
162162 if ( this . props . visible ) {
163163 this . showModal ( ) ;
164164 } else {
@@ -174,7 +174,9 @@ class Modal extends React.Component<Props, State> {
174174 }
175175
176176 render ( ) {
177- if ( ! this . state . rendered ) return null ;
177+ const { rendered, opacity } = this . state ;
178+
179+ if ( ! rendered ) return null ;
178180
179181 const { children, dismissable, theme, contentContainerStyle } = this . props ;
180182 const { colors } = theme ;
@@ -191,18 +193,16 @@ class Modal extends React.Component<Props, State> {
191193 < Animated . View
192194 style = { [
193195 styles . backdrop ,
194- { backgroundColor : colors . backdrop , opacity : this . state . opacity } ,
196+ { backgroundColor : colors . backdrop , opacity } ,
195197 ] }
196198 />
197199 </ TouchableWithoutFeedback >
198200 < SafeAreaView style = { styles . wrapper } >
199201 < Surface
200202 style = {
201- [
202- { opacity : this . state . opacity } ,
203- styles . content ,
204- contentContainerStyle ,
205- ] as StyleProp < ViewStyle >
203+ [ { opacity } , styles . content , contentContainerStyle ] as StyleProp <
204+ ViewStyle
205+ >
206206 }
207207 >
208208 { children }
0 commit comments