when app in production, avoid red error screen if bad happens.
how can make instead of throwing exception , showing error screen, app restarts , goes home page?
you need have listeners specific events , fire callback in event of listeners fire.
for example, have listener lack in internet connection using netinfo, app being opened/closed using appstateios. getinitialstate function sets 2 properties:
getinitialstate: function() { return { currentstate: appstateios.currentstate, isconnected: null } }, then have listeners , handlers:
componentwillmount: function() { netinfo.isconnected.fetch().done( (isconnected) => { this.setstate({isconnected}); } ); }, componentdidmount: function () { appstateios.addeventlistener('change', this.handleappstatechange); netinfo.isconnected.addeventlistener('change', this.handleconnectivitychange); }, componentwillunmount: function() { appstateios.removeeventlistener('change', this.handleappstatechange); netinfo.isconnected.removeeventlistener('change', this.handleconnectivitychange); }, handleappstatechange: function(state) { this.setstate({ currentstate: state }); }, handleconnectivitychange: function(connection) { this.setstate({ isconnected: connection }) }, my render method dependent on state:
render: function() { if (!this.state.isconnected) { return ( this.renderloading() ) } return ( <view style={styles.container}> <webview url={this.props.url} /> </view> ) },
Comments
Post a Comment