While playing with React Native, I came across a problem, and I'm not sure how to solve it. I have a main NavigatorIOSview where the content is pushand popis located around different views. I initially configured it so that the network request will be launched in componentDidMount. However, it began that the βpressingβ of navigation (animation of the transition to the next screen) will be delayed until the actual request is completed (although it uses fetch, promises and, when loading async/await). I managed to compensate for most of these problems by wrapping the network request code in the call setTimeout(fn, 0), but I'm not sure if this is the right way to handle this. Both requestAnimationFrameand InteractionManager.runAfterInteractionsare not working, and even setTimeoutis completed. Are there any better ways to do this?
Just to illustrate, this is roughly how my code (pseudocode) works:
Screen 1 :
<TouchableHighlight onPress={() => this.navigator.push({ data })} />
Screen 2 :
componentDidMount() {
this.startLoading();
}
startLoading() {
this.setState({ items: [], loading: true });
this.load().then(items => this.setState({ items, loading: false }));
}
async load() {
const contents = await fetch(this.props.url);
return items;
}
source
share