Skip to content

Commit

Permalink
animatedScaleComponent: Remove use of display property.
Browse files Browse the repository at this point in the history
It works same as it works in CSS. There is no use of such
property in animation component, as they result in a sudden change.

It was used to make size 0 whenever component is not supposed to show.
But if there is nothing to show then it's size will be automatically
0.

This will not cause any issue. It has been used in unread notice and
autocomplete popup. Refer previous commit, which is a better
alternative for this in unread notice.

For autocomplete, when it is not suppossed to pop, it's children will
be null and nothing will be rendered. Thus taking no space (refer
0baca8f). Part of #2943.
  • Loading branch information
jainkuniya committed Feb 24, 2019
1 parent a4a69ec commit 9b45beb
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/animation/AnimatedScaleComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,23 @@ type Props = {|
style?: Style,
|};

type State = {|
visible: boolean,
|};

export default class AnimatedScaleComponent extends PureComponent<Props, State> {
state = {
visible: this.props.visible,
};

export default class AnimatedScaleComponent extends PureComponent<Props> {
animatedValue = new Animated.Value(this.props.visible ? 1 : 0);

componentWillReceiveProps(nextProps: Props) {
if (nextProps.visible) {
this.setState({ visible: true });
}
Animated.timing(this.animatedValue, {
toValue: nextProps.visible ? 1 : 0,
duration: 300,
useNativeDriver: true,
easing: Easing.elastic(),
}).start(() => this.setState({ visible: nextProps.visible }));
}).start();
}

render() {
const { children, style } = this.props;
const { visible } = this.state;
const animatedStyle = {
transform: [{ scale: this.animatedValue }],
opacity: this.animatedValue,
display: visible ? 'flex' : 'none',
};

return (
Expand Down

0 comments on commit 9b45beb

Please sign in to comment.