Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async componentDidMount() {
const { pingInterval } = this.props;
const handler = this.getConnectionChangeHandler();
NetInfo.isConnected.addEventListener('connectionChange', handler);
// On Android the listener does not fire on startup
if (Platform.OS === 'android') {
const netConnected = await NetInfo.isConnected.fetch();
handler(netConnected);
}
if (pingInterval > 0) {
connectivityInterval.setup(this.intervalHandler, pingInterval);
}
}
componentWillMount() {
if (this.props.checkNetwork) {
NetInfo.isConnected.addEventListener('connectionChange', this._handleConnectivityChange);
// componentWillUnmount unsets this._handleConnectivityChange in case the component unmounts before this fetch resolves
NetInfo.isConnected.fetch().done(this._handleConnectivityChange);
}
this._processSource(this.props.source, true);
}
componentDidMount() {
this._eventCounter = 0;
NetInfo.getConnectionInfo()
.then(connectionInfo => this.setState({ connectionInfo }))
.catch(console.warn);
this._ensureIsConnectionExpensiveIsUpToDate();
this._subscription = NetInfo.addEventListener(
'connectionChange',
this._handleConnectionChange
) as unknown as Subscription;
this._isConnectedSubscription = NetInfo.isConnected.addEventListener(
'connectionChange',
this._handleIsConnectedChange
) as unknown as Subscription;
}
componentDidMount() {
NetInfo.isConnected.addEventListener('connectionChange', this.props.setIsConnected);
},
componentWillUnmount() {
componentWillUnmount() {
NetInfo.isConnected.removeEventListener("connectionChange", this.sync);
}
componentDidMount() {
NetInfo.isConnected.fetch().then(this.sync);
NetInfo.isConnected.addEventListener("connectionChange", this.sync);
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('connectionChange', this.props.setIsConnected);
},
}),
return () => {
NetInfo.isConnected.removeEventListener('connectionChange', emit);
};
}
async netFetch(url, method = 'GET', params, json, header, text) {
let isConnected = await NetInfo.isConnected.fetch().done;
if (!isConnected) {
return {
result: false,
code: Code.NETWORK_ERROR,
msg: I18n('netError')
}
}
let headers = {};
if (header) {
headers = Object.assign({}, headers, header)
}
//授权码
if (!this.optionParams.authorizationCode) {
tryAgain = () => {
NetInfo.isConnected.fetch().then(isConnected => {
if (isConnected) {
this.props.navigation.pop();
}
});
};