Skip to content

Update deprecated RN lifecycle methods and fix prop type typo. #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/Basic/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ class Row extends Component {
};
}

componentWillReceiveProps(nextProps) {
if (this.props.active !== nextProps.active) {
componentDidUpdate(prevProps) {
if (this.props.active !== prevProps.active) {
Animated.timing(this._active, {
duration: 300,
easing: Easing.bounce,
toValue: Number(nextProps.active),
toValue: Number(this.props.active),
}).start();
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/Horizontal/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ class Row extends Component {
};
}

componentWillReceiveProps(nextProps) {
if (this.props.active !== nextProps.active) {
componentDidUpdate(prevProps) {
if (this.props.active !== prevProps.active) {
Animated.timing(this._active, {
duration: 300,
easing: Easing.bounce,
toValue: Number(nextProps.active),
toValue: Number(this.props.active),
}).start();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export default class Row extends Component {
},
});

componentWillReceiveProps(nextProps) {
if (!this._active && !shallowEqual(this._location, nextProps.location)) {
const animated = !this._active && nextProps.animated;
this._relocate(nextProps.location, animated);
componentDidUpdate() {
if (!this._active && !shallowEqual(this._location, this.props.location)) {
const animated = !this._active && this.props.animated;
this._relocate(this.props.location, animated);
}
}

Expand Down
46 changes: 21 additions & 25 deletions src/SortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class SortableList extends Component {
manuallyActivateRows: PropTypes.bool,
keyboardShouldPersistTaps: PropTypes.oneOf(['never', 'always', 'handled']),
scrollEventThrottle: PropTypes.number,
decelerationRate: PropTypes.oneOf([PropTypes.string, PropTypes.number]),
decelerationRate: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
pagingEnabled: PropTypes.bool,
nestedScrollEnabled: PropTypes.bool,
disableIntervalMomentum: PropTypes.bool,
Expand Down Expand Up @@ -81,14 +81,15 @@ export default class SortableList extends Component {
rowsLayouts: null,
containerLayout: null,
data: this.props.data,
isMounting: true,
activeRowKey: null,
activeRowIndex: null,
releasedRowKey: null,
sortingEnabled: this.props.sortingEnabled,
scrollEnabled: this.props.scrollEnabled
};

componentWillMount() {
componentDidMount() {
this.state.order.forEach((key) => {
this._rowsLayouts[key] = new Promise((resolve) => {
this._resolveRowLayout[key] = resolve;
Expand All @@ -105,17 +106,18 @@ export default class SortableList extends Component {
this._resolveFooterLayout = resolve;
});
}
}

componentDidMount() {
this._onUpdateLayouts();

this.setState({ isMounting: false });
}

componentWillReceiveProps(nextProps) {
const {data, order} = this.state;
let {data: nextData, order: nextOrder} = nextProps;
componentDidUpdate(prevProps, prevState) {
const {data: currentData, order: currentOrder, scrollEnabled} = this.state;
const {data: prevData} = prevState;
let {data: nextData, order: nextOrder} = this.props;

if (data && nextData && !shallowEqual(data, nextData)) {
if (currentData && nextData && !shallowEqual(currentData, nextData)) {
nextOrder = nextOrder || Object.keys(nextData)
uniqueRowKey.id++;
this._rowsLayouts = {};
Expand All @@ -125,7 +127,7 @@ export default class SortableList extends Component {
});
});

if (Object.keys(nextData).length > Object.keys(data).length) {
if (Object.keys(nextData).length > Object.keys(currentData).length) {
this.setState({
animated: false,
data: nextData,
Expand All @@ -140,21 +142,13 @@ export default class SortableList extends Component {
});
}

} else if (order && nextOrder && !shallowEqual(order, nextOrder)) {
} else if (currentOrder && nextOrder && !shallowEqual(currentOrder, nextOrder)) {
this.setState({order: nextOrder});
}
}

componentDidUpdate(prevProps, prevState) {
const {data, scrollEnabled} = this.state;
const {data: prevData} = prevState;

if (data && prevData && !shallowEqual(data, prevData)) {
if (currentData && prevData && !shallowEqual(currentData, prevData)) {
this._onUpdateLayouts();
}
if (prevProps.scrollEnabled !== scrollEnabled) {
this.setState({scrollEnabled: prevProps.scrollEnabled})
}
}

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

render() {
if (this.state.isMounting ) return null;

let {
contentContainerStyle,
innerContainerStyle,
horizontal,
style,
showsVerticalScrollIndicator,
showsHorizontalScrollIndicator,
contentContainerStyle,
innerContainerStyle,
horizontal,
style,
showsVerticalScrollIndicator,
showsHorizontalScrollIndicator,
snapToAlignment,
scrollEventThrottle,
decelerationRate,
Expand Down