Skip to content

Commit

Permalink
feat: use native driver for animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Denise-Ng committed Aug 18, 2021
1 parent 4eff141 commit 98eff07
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
8 changes: 4 additions & 4 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ target 'example' do
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!
post_install do |installer|
flipper_post_install(installer)
end
# use_flipper!
# post_install do |installer|
# flipper_post_install(installer)
# end
end

target 'example-tvOS' do
Expand Down
21 changes: 13 additions & 8 deletions lib/awesome-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/awesome-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-awesome-modal",
"version": "0.1.1",
"version": "0.1.2",
"description": "A flexible and reusable modal.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
28 changes: 13 additions & 15 deletions src/awesome-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AwesomeModal extends React.Component<IProps, IState> {
this.state = {
modalHeight: 0,
opacityAnimation: new Animated.Value(0),
translateYAnimation: new Animated.Value(DEVICE_HEIGHT * -1.5),
translateYAnimation: new Animated.Value(DEVICE_HEIGHT * 1.5),
modalYPosition: props.modalBottomMargin ?? 0 + yPositionBottomMargin,
deviceHeight: DEVICE_HEIGHT,
overlayIsVisible: true,
Expand All @@ -91,9 +91,8 @@ export class AwesomeModal extends React.Component<IProps, IState> {
this.onTouchOutside = this.onTouchOutside.bind(this)
this.close = this.close.bind(this)
this.onModalHeightChange = this.onModalHeightChange.bind(this)
this.onSafeAreaInsetsForRootViewChange = this.onSafeAreaInsetsForRootViewChange.bind(
this
)
this.onSafeAreaInsetsForRootViewChange =
this.onSafeAreaInsetsForRootViewChange.bind(this)
}

async componentDidMount() {
Expand Down Expand Up @@ -169,9 +168,9 @@ export class AwesomeModal extends React.Component<IProps, IState> {
useNativeDriver: true,
}),
Animated.timing(translateYAnimation, {
toValue: this.state.deviceHeight * -1.5,
toValue: this.state.deviceHeight * 1.5,
duration: 250,
useNativeDriver: false,
useNativeDriver: true,
}),
]).start(() => {
this.setState(() => {
Expand All @@ -194,12 +193,7 @@ export class AwesomeModal extends React.Component<IProps, IState> {
* the application.
*/
onModalHeightChange() {
const {
modalHeight,
opacityAnimation,
translateYAnimation,
modalYPosition,
} = this.state
const { modalHeight, opacityAnimation, translateYAnimation } = this.state

if (modalHeight !== 0) {
Animated.parallel([
Expand All @@ -211,8 +205,8 @@ export class AwesomeModal extends React.Component<IProps, IState> {
Animated.spring(translateYAnimation, {
toValue: this.props.isCentered
? (DEVICE_HEIGHT - modalHeight) / 2
: modalYPosition,
useNativeDriver: false,
: DEVICE_HEIGHT - modalHeight,
useNativeDriver: true,
}),
]).start()
}
Expand Down Expand Up @@ -345,7 +339,11 @@ export class AwesomeModal extends React.Component<IProps, IState> {
})
}}
style={[
{ bottom: this.state.translateYAnimation as any },
{
transform: [
{ translateY: this.state.translateYAnimation as any },
],
},
defaultModalContainerStyle,
modalContainerStyle,
]}
Expand Down

0 comments on commit 98eff07

Please sign in to comment.