I used the NetInfo library to detect whether the internet connection is available. It is working perfectly , but the snackbar inside the NetInfo function is not shown when internet is changed from on to off. Snackbar is shown perfectly when started with no internet and also started with internet. When Internet is changed from off to on every time, snackbar is shown every time BUT not shown when changed from ON to OFF. All the logs shows perfectly in every conditions. If I place a alertbox instead of snackbar, everything is perfect.
handleConnectivityChange = (isConnected) => {
NetInfo.isConnected.fetch().done((isConnected) => {
console.log('Dashboard ConnectivityChanged');
console.log('IsConnectedValue:'+ isConnected );
if(isConnected == true)
{
console.log('Dashboard Connected');
Snackbar.show({
title: 'Connected to Internet',
duration: Snackbar.LENGTH_LONG,
action: {
title: 'DISMISS',
color: 'rgb(216,21,88)',
onPress: () => { /* Dismiss snackbar default */ },
},
});
}
else
{
console.log('Dashboard No Internet');
Snackbar.show({
title: 'No Internet Connection',
duration: Snackbar.LENGTH_LONG,
action: {
title: 'DISMISS',
color: 'rgb(216,21,88)',
onPress: () => { /* Dismiss snackbar default */ },
},
});
}
});
}