mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

create netinfo lib

+36
+36
src/lib/net-info.ts
··· 1 + import NetInfo, { 2 + NetInfoState, 3 + NetInfoSubscription, 4 + } from '@react-native-community/netinfo' 5 + 6 + type NetworkStateChangeListener = (state: NetInfoState) => void 7 + 8 + class NetInfoAPI { 9 + private subscription: NetInfoSubscription | null = null 10 + private listeners: NetworkStateChangeListener[] = [] 11 + 12 + constructor() { 13 + this.subscribe() 14 + } 15 + 16 + private subscribe() { 17 + this.subscription = NetInfo.addEventListener(this.handleNetworkStateChange) 18 + } 19 + 20 + private handleNetworkStateChange = (state: NetInfoState) => { 21 + this.listeners.forEach(listener => listener(state)) 22 + } 23 + 24 + public addListener(listener: NetworkStateChangeListener) { 25 + this.listeners.push(listener) 26 + } 27 + 28 + public removeListener(listener: NetworkStateChangeListener) { 29 + const index = this.listeners.indexOf(listener) 30 + if (index !== -1) { 31 + this.listeners.splice(index, 1) 32 + } 33 + } 34 + } 35 + 36 + export const netInfoAPI = new NetInfoAPI()