Utilizing the NetInfo component in react-native to monitor network state and listen to changes using NetInfo.addEventListener() function. However, I am facing an issue where the state does not update when switching between wifi and internet connections.
import React, {Component, PropTypes} from 'react';
import {
Platform,
View,
Text,
Image,
StyleSheet,
AsyncStorage,
BackHandler,
StatusBar ,
NetInfo,
Alert
} from 'react-native';
// Other imports and configurations
export default class SplashScreen extends ComponentBase {
constructor(props){
super(props);
this.state = {
timePassed: false,
deviceId:"",
id:"",
index:2,
};
}
// Other methods and lifecycle functions
async componentDidMount() {
NetInfo.getConnectionInfo().then((connectionInfo) => {
console.log('Initial, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
});
function handleFirstConnectivityChange(connectionInfo) {
console.log('First change, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
NetInfo.removeEventListener(
'connectionChange',
handleFirstConnectivityChange
);
}
NetInfo.addEventListener(
'connectionChange',
handleFirstConnectivityChange
);
firebaseNotification.analytics().setCurrentScreen("SplashScreen");
const value = await AsyncStorage.getItem('SignInStatus');
console.log("value is", value);
// Notification handling logic
tracker.trackScreenView('SplashScreen')
}
// Render method with conditional output based on timePassed state
const styles = StyleSheet.create(
{
MainContainer:
{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
SplashScreen_RootView:
{
justifyContent: 'center',
flex:1,
position: 'absolute',
width: '100%',
height: '100%',
},
SplashScreen_ChildView:
{
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#1F0242',
flex:1,
},
TouchableOpacity_Style:{
width:25,
height: 25,
top:9,
right:9,
position: 'absolute'
}
});
Despite including the code in the componentDidMount() method, only the initial connection info is logged and not the listener via NetInfo.addEventListener(). Seeking assistance to resolve this issue.