Skip to content

Commit

Permalink
Use componentDidUpdate instead of componentWillReceiveProps on Backdr…
Browse files Browse the repository at this point in the history
…op component
  • Loading branch information
jacklam718 committed Sep 15, 2019
1 parent 7b68324 commit b26b780
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/components/Backdrop.js

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

23 changes: 12 additions & 11 deletions src/components/Backdrop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import React, { Component } from 'react';
import { StyleSheet, TouchableOpacity, Animated, Dimensions } from 'react-native';
import { StyleSheet, TouchableOpacity, Animated } from 'react-native';
import type { BackdropProps } from '../type';

export default class Backdrop extends Component<BackdropProps> {
Expand All @@ -14,10 +14,15 @@ export default class Backdrop extends Component<BackdropProps> {
onPress: () => {},
};

componentWillReceiveProps(nextProps: BackdropProps) {
const { visible, useNativeDriver, animationDuration: duration } = this.props;
if (visible !== nextProps.visible) {
const toValue = nextProps.visible ? nextProps.opacity : 0;
componentDidUpdate(prevProps: BackdropProps) {
const {
visible,
useNativeDriver,
opacity,
animationDuration: duration,
} = this.props;
if (prevProps.visible !== visible) {
const toValue = visible ? opacity : 0;
Animated.timing(this.opacity, {
toValue,
duration,
Expand All @@ -35,17 +40,13 @@ export default class Backdrop extends Component<BackdropProps> {
render() {
const { onPress, pointerEvents, backgroundColor } = this.props;
const { opacity } = this;
const { width, height } = Dimensions.get('window');
return (
<Animated.View
pointerEvents={pointerEvents}
style={{
width: width * 3,
height: height * 3,
position: 'absolute',
style={StyleSheet.flatten([StyleSheet.absoluteFill, {
backgroundColor,
opacity,
}}
}])}
>
<TouchableOpacity
onPress={onPress}
Expand Down

0 comments on commit b26b780

Please sign in to comment.