Skip to content

Commit

Permalink
Refine Bottom Sheets in/out transition (#14831)
Browse files Browse the repository at this point in the history
As specified in wordpress-mobile/gutenberg-mobile#595
I did my best to adjust to the specs there, and for the most part the animations
matches what was requested.

One limitation is that due to how react-native-modal is implemented, we don't
know the view's height when it's about to be presented, and so it starts the
"slide in" animation not from the bottom edge, but from a lower point, since it
uses the window height to displace the view and not the view's height. The
result is an animation that appears slower than specified, since the view has
to traverse a longer distance in the same time, and there is a delay before the
view starts appearing.

This is mildly annoying, but I could not find a way to make it work without
rewriting react-native-modal.
  • Loading branch information
koke authored Apr 16, 2019
1 parent b496ebc commit 626778e
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { Text, View, Platform, PanResponder, Dimensions } from 'react-native';
import { Text, View, Platform, PanResponder, Dimensions, Easing } from 'react-native';
import Modal from 'react-native-modal';
import SafeArea from 'react-native-safe-area';

Expand Down Expand Up @@ -94,14 +94,39 @@ class BottomSheet extends Component {
</View>
);

const { height } = Dimensions.get( 'window' );
const easing = Easing.bezier( 0.450, 0.000, 0.160, 1.020 );

const animationIn = {
easing,
from: {
translateY: height,
},
to: {
translateY: 0,
},
};

const animationOut = {
easing,
from: {
translateY: 0,
},
to: {
translateY: height,
},
};

return (
<Modal
isVisible={ isVisible }
style={ styles.bottomModal }
animationInTiming={ 500 }
animationOutTiming={ 500 }
backdropTransitionInTiming={ 500 }
backdropTransitionOutTiming={ 500 }
animationIn={ animationIn }
animationInTiming={ 600 }
animationOut={ animationOut }
animationOutTiming={ 250 }
backdropTransitionInTiming={ 50 }
backdropTransitionOutTiming={ 50 }
backdropOpacity={ 0.2 }
onBackdropPress={ this.props.onClose }
onBackButtonPress={ this.props.onClose }
Expand Down

0 comments on commit 626778e

Please sign in to comment.