Skip to content

Commit e922b0c

Browse files
Inbal-TishArnonZ
andauthored
TabBar & TabBarItem - replace 'componentWillReceiveProps' with 'componentDidUpdate'. (#913)
Co-authored-by: arnonz <[email protected]>
1 parent d9f704f commit e922b0c

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/components/tabBar/TabBarItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ class TabBarItem extends PureComponent<TabBarItemProps, State> {
111111
styles = createStyles();
112112
layout: any = undefined;
113113

114-
UNSAFE_componentWillReceiveProps(nextProps: TabBarItemProps) {
115-
if (this.props.selected !== nextProps.selected) {
116-
this.animate(nextProps.selected);
114+
componentDidUpdate(prevProps: TabBarItemProps) {
115+
if (prevProps.selected !== this.props.selected) {
116+
this.animate(this.props.selected);
117117
}
118118
}
119119

src/components/tabBar/index.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,19 @@ class TabBar extends Component<TabBarProps, State> {
104104
itemsRefs: any[] = [];
105105
scrollView?: any = undefined;
106106

107-
UNSAFE_componentWillReceiveProps(nextProps: TabBarProps) {
107+
componentDidUpdate(prevProps: TabBarProps, prevState: State) {
108108
// TODO: since we're implementing an uncontrolled component here, we should verify the selectedIndex has changed
109109
// between this.props and nextProps (basically the meaning of selectedIndex should be initialIndex)
110+
const {selectedIndex} = this.props;
110111
const isIndexManuallyChanged =
111-
nextProps.selectedIndex !== this.state.currentIndex && this.props.selectedIndex !== nextProps.selectedIndex;
112-
if (isIndexManuallyChanged && nextProps.selectedIndex !== undefined) {
113-
this.updateIndicator(nextProps.selectedIndex);
114-
}
115-
}
116-
117-
componentDidUpdate(prevProps: TabBarProps) {
118-
const prevChildrenCount = React.Children.count(prevProps.children);
119-
if (this.childrenCount < prevChildrenCount) {
120-
this.updateIndicator(0);
112+
selectedIndex !== prevState.currentIndex && prevProps.selectedIndex !== selectedIndex;
113+
if (isIndexManuallyChanged && selectedIndex !== undefined) {
114+
this.updateIndicator(selectedIndex);
115+
} else {
116+
const prevChildrenCount = React.Children.count(prevProps.children);
117+
if (this.childrenCount < prevChildrenCount) {
118+
this.updateIndicator(0);
119+
}
121120
}
122121
}
123122

0 commit comments

Comments
 (0)