Skip to content

Commit b8253e4

Browse files
Update deprecated RN lifecycle methods. (#216)
Also fixed typo: `oneOf` —> `oneOfType`.
1 parent 9b18675 commit b8253e4

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

examples/Basic/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ class Row extends Component {
120120
};
121121
}
122122

123-
componentWillReceiveProps(nextProps) {
124-
if (this.props.active !== nextProps.active) {
123+
componentDidUpdate(prevProps) {
124+
if (this.props.active !== prevProps.active) {
125125
Animated.timing(this._active, {
126126
duration: 300,
127127
easing: Easing.bounce,
128-
toValue: Number(nextProps.active),
128+
toValue: Number(this.props.active),
129129
}).start();
130130
}
131131
}

examples/Horizontal/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ class Row extends Component {
121121
};
122122
}
123123

124-
componentWillReceiveProps(nextProps) {
125-
if (this.props.active !== nextProps.active) {
124+
componentDidUpdate(prevProps) {
125+
if (this.props.active !== prevProps.active) {
126126
Animated.timing(this._active, {
127127
duration: 300,
128128
easing: Easing.bounce,
129-
toValue: Number(nextProps.active),
129+
toValue: Number(this.props.active),
130130
}).start();
131131
}
132132
}

src/Row.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export default class Row extends Component {
142142
},
143143
});
144144

145-
componentWillReceiveProps(nextProps) {
146-
if (!this._active && !shallowEqual(this._location, nextProps.location)) {
147-
const animated = !this._active && nextProps.animated;
148-
this._relocate(nextProps.location, animated);
145+
componentDidUpdate() {
146+
if (!this._active && !shallowEqual(this._location, this.props.location)) {
147+
const animated = !this._active && this.props.animated;
148+
this._relocate(this.props.location, animated);
149149
}
150150
}
151151

src/SortableList.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ export default class SortableList extends Component {
8181
rowsLayouts: null,
8282
containerLayout: null,
8383
data: this.props.data,
84+
isMounting: true,
8485
activeRowKey: null,
8586
activeRowIndex: null,
8687
releasedRowKey: null,
8788
sortingEnabled: this.props.sortingEnabled,
8889
scrollEnabled: this.props.scrollEnabled
8990
};
9091

91-
componentWillMount() {
92+
componentDidMount() {
9293
this.state.order.forEach((key) => {
9394
this._rowsLayouts[key] = new Promise((resolve) => {
9495
this._resolveRowLayout[key] = resolve;
@@ -105,17 +106,18 @@ export default class SortableList extends Component {
105106
this._resolveFooterLayout = resolve;
106107
});
107108
}
108-
}
109109

110-
componentDidMount() {
111110
this._onUpdateLayouts();
111+
112+
this.setState({ isMounting: false });
112113
}
113114

114-
componentWillReceiveProps(nextProps) {
115-
const {data, order} = this.state;
116-
let {data: nextData, order: nextOrder} = nextProps;
115+
componentDidUpdate(prevProps, prevState) {
116+
const {data: currentData, order: currentOrder, scrollEnabled} = this.state;
117+
const {data: prevData} = prevState;
118+
let {data: nextData, order: nextOrder} = this.props;
117119

118-
if (data && nextData && !shallowEqual(data, nextData)) {
120+
if (currentData && nextData && !shallowEqual(currentData, nextData)) {
119121
nextOrder = nextOrder || Object.keys(nextData)
120122
uniqueRowKey.id++;
121123
this._rowsLayouts = {};
@@ -125,7 +127,7 @@ export default class SortableList extends Component {
125127
});
126128
});
127129

128-
if (Object.keys(nextData).length > Object.keys(data).length) {
130+
if (Object.keys(nextData).length > Object.keys(currentData).length) {
129131
this.setState({
130132
animated: false,
131133
data: nextData,
@@ -140,21 +142,13 @@ export default class SortableList extends Component {
140142
});
141143
}
142144

143-
} else if (order && nextOrder && !shallowEqual(order, nextOrder)) {
145+
} else if (currentOrder && nextOrder && !shallowEqual(currentOrder, nextOrder)) {
144146
this.setState({order: nextOrder});
145147
}
146-
}
147-
148-
componentDidUpdate(prevProps, prevState) {
149-
const {data, scrollEnabled} = this.state;
150-
const {data: prevData} = prevState;
151148

152-
if (data && prevData && !shallowEqual(data, prevData)) {
149+
if (currentData && prevData && !shallowEqual(currentData, prevData)) {
153150
this._onUpdateLayouts();
154151
}
155-
if (prevProps.scrollEnabled !== scrollEnabled) {
156-
this.setState({scrollEnabled: prevProps.scrollEnabled})
157-
}
158152
}
159153

160154
scrollBy({dx = 0, dy = 0, animated = false}) {
@@ -209,13 +203,15 @@ export default class SortableList extends Component {
209203
}
210204

211205
render() {
206+
if (this.state.isMounting ) return null;
207+
212208
let {
213-
contentContainerStyle,
214-
innerContainerStyle,
215-
horizontal,
216-
style,
217-
showsVerticalScrollIndicator,
218-
showsHorizontalScrollIndicator,
209+
contentContainerStyle,
210+
innerContainerStyle,
211+
horizontal,
212+
style,
213+
showsVerticalScrollIndicator,
214+
showsHorizontalScrollIndicator,
219215
snapToAlignment,
220216
scrollEventThrottle,
221217
decelerationRate,

0 commit comments

Comments
 (0)