|
@@ -1,6 +1,6 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
|
-import React, { Component, type Node } from 'react';
|
|
3
|
+import React, { PureComponent, type Node } from 'react';
|
4
|
4
|
import { Animated, TouchableWithoutFeedback, View } from 'react-native';
|
5
|
5
|
|
6
|
6
|
import styles, { SIDEBAR_WIDTH } from './styles';
|
|
@@ -46,7 +46,18 @@ type State = {
|
46
|
46
|
/**
|
47
|
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
|
62
|
* Initializes a new {@code SideBar} instance.
|
52
|
63
|
*
|
|
@@ -74,12 +85,12 @@ export default class SideBar extends Component<Props, State> {
|
74
|
85
|
}
|
75
|
86
|
|
76
|
87
|
/**
|
77
|
|
- * Implements React's {@link Component#componentWillReceiveProps()}.
|
|
88
|
+ * Implements React's {@link Component#componentDidUpdate()}.
|
78
|
89
|
*
|
79
|
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,8 +159,6 @@ export default class SideBar extends Component<Props, State> {
|
148
|
159
|
* @returns {void}
|
149
|
160
|
*/
|
150
|
161
|
_setShow(show) {
|
151
|
|
- show && this.setState({ showOverlay: true });
|
152
|
|
-
|
153
|
162
|
Animated
|
154
|
163
|
.timing(
|
155
|
164
|
/* value */ this.state.sliderAnimation,
|