Browse Source

ref(sidebar): derive showOverlay state

- Derive the showOverlay state. When the sidebar should be hidden,
  the internal showOverlay state should remain true until the
  animation hides it. When the sidebar should show, the showOverlay
  state should become true immediately.
- Use PureComponent to prevent additional animation triggers
  instead of explicitly checking changes to the "show" prop.
master
Leonard Kim 7 years ago
parent
commit
f13cfe70f3
1 changed files with 16 additions and 7 deletions
  1. 16
    7
      react/features/base/react/components/native/SideBar.js

+ 16
- 7
react/features/base/react/components/native/SideBar.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import React, { Component, type Node } from 'react';
3
+import React, { PureComponent, type Node } from 'react';
4
 import { Animated, TouchableWithoutFeedback, View } from 'react-native';
4
 import { Animated, TouchableWithoutFeedback, View } from 'react-native';
5
 
5
 
6
 import styles, { SIDEBAR_WIDTH } from './styles';
6
 import styles, { SIDEBAR_WIDTH } from './styles';
46
 /**
46
 /**
47
  * A generic animated side bar to be used for left-side, hamburger-style menus.
47
  * A generic animated side bar to be used for left-side, hamburger-style menus.
48
  */
48
  */
49
-export default class SideBar extends Component<Props, State> {
49
+export default class SideBar extends PureComponent<Props, State> {
50
+    /**
51
+     * Implements React's {@link Component#getDerivedStateFromProps()}.
52
+     *
53
+     * @inheritdoc
54
+     */
55
+    static getDerivedStateFromProps(props: Props, prevState: State) {
56
+        return {
57
+            showOverlay: props.show || prevState.showOverlay
58
+        };
59
+    }
60
+
50
     /**
61
     /**
51
      * Initializes a new {@code SideBar} instance.
62
      * Initializes a new {@code SideBar} instance.
52
      *
63
      *
74
     }
85
     }
75
 
86
 
76
     /**
87
     /**
77
-     * Implements React's {@link Component#componentWillReceiveProps()}.
88
+     * Implements React's {@link Component#componentDidUpdate()}.
78
      *
89
      *
79
      * @inheritdoc
90
      * @inheritdoc
80
      */
91
      */
81
-    componentWillReceiveProps({ show }: Props) {
82
-        (show === this.props.show) || this._setShow(show);
92
+    componentDidUpdate() {
93
+        this._setShow(this.props.show);
83
     }
94
     }
84
 
95
 
85
     /**
96
     /**
148
      * @returns {void}
159
      * @returns {void}
149
      */
160
      */
150
     _setShow(show) {
161
     _setShow(show) {
151
-        show && this.setState({ showOverlay: true });
152
-
153
         Animated
162
         Animated
154
             .timing(
163
             .timing(
155
                 /* value */ this.state.sliderAnimation,
164
                 /* value */ this.state.sliderAnimation,

Loading…
Cancel
Save