I tried many ways
async functionsetTimetoutand some other methods, all fail.
(I am not a React/React Native expert)
<TabViewAnimated
...(other props, not important)
onIndexChange={this._handleIndexChange} // HERE
/>
(it have 3 scene)
Normally, onIndexChange should look like this:
_handleIndexChange(index){
this.setState({ index });
}
(and this work perfectly of course)
when switch to scene 2 and 3 (not scene 1) it send 1 HTTP request.
now the code looks like this:
_handleIndexChange(index){
this.setState({ index });
if (index == 1 || index == 2) { // index start with 0, so scene 2 and 3 actually need to use number 1 and 2
if (is_login) {
get_user_info(); // it send http request
}
}
}
(here just some pseudo-code to demonstrate what I mean ,
is_login and get_user_info() I didn't provide detail here, they are not important)
Tab Switch still smooth,
like this: https://www.youtube.com/watch?v=iMAT05gJTHE&feature=youtu.be
Tab Switch feel laggy,
and sometimes just stop working (the App didn't crash or freeze, swipe gesture still work, just bottom tab indicator not responsive anymore)
like this: https://www.youtube.com/watch?v=-SXvKnwsstU&feature=youtu.be
Appreciate any help, Thanks! :smile:
You shouldn't do expensive calculation in onIndexChange. If you want to do something when tab is being switched, you'll need to delay it till the animation is complete. You can do that with InteractionManager.runAfterInteractions
@satya164 Thank you very much! would try!
@satya164 Hi, is it possible to provide code example on how to use react-native-tab-view + InteractionManager.runAfterInteractions?
after read the InteractionManager.runAfterInteractions document I still quite confused how to use it with react-native-tab-view
Thanks!
_handleIndexChange(index){
this.setState({ index });
InteractionManager.runAfterInteractions(() => {
if (this.state.index == 1 || this.state.index == 2) { // index start with 0, so scene 2 and 3 actually need to use number 1 and 2
if (is_login) {
get_user_info(); // it send http request
}
}
});
}
@satya164 Thank you very much!
Most helpful comment