Search code examples
androidreact-nativecode-pushreact-native-code-push

Prevent React Native App running until it has been updated with code-push


I wanted to know if it is possible to prevent users from accessing any screen in app until code-push updates, Is this possible? if possible, could you please kindly show me an example, the goal is preventing the app to launch until update has been downloaded.


Solution

  • You use a state like loading to record if update has been downloaded. In render(), return the normal app content only when loading is false. see my code below.

    componentDidMount() {
      this.setState({loading: true});
      fetch(url).then(() => this.setState({loading: false})
    }
    
    render() {
      const {loading} = this.state;
      return (
        {loading && <Text>Loading</Text>}
        {!loading && <View>You normal app content</View>}
      )
    }