From 86db8186931b79d0d77c2ffdc5b3273960d461a2 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 17:06:53 -0700 Subject: [PATCH 01/12] Create temporary shim for NetInfo --- .../chat/MainApplication.java | 1 + android/settings.gradle | 2 ++ ios/Podfile | 1 + ios/Podfile.lock | 12 +++++----- package-lock.json | 6 ++--- package.json | 2 +- src/lib/NetInfo/index.js | 22 +++++++++++++++++++ src/lib/NetInfo/index.native.js | 3 +++ src/lib/Network.js | 8 +++++++ src/page/HomePage/SidebarView.js | 7 +++--- src/style/StyleSheet.js | 9 +++++++- 11 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 src/lib/NetInfo/index.js create mode 100644 src/lib/NetInfo/index.native.js diff --git a/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java b/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java index eeab3873a09fc..552390ea07830 100644 --- a/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java +++ b/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java @@ -4,6 +4,7 @@ import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; +import com.reactnativecommunity.netinfo.NetInfoPackage; import com.lugg.ReactNativeConfig.ReactNativeConfigPackage; import com.reactnativecommunity.asyncstorage.AsyncStoragePackage; import com.facebook.react.ReactInstanceManager; diff --git a/android/settings.gradle b/android/settings.gradle index 3deca494c3607..a2f3e5189908c 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'ReactNativeChat' +include ':@react-native-community_netinfo' +project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android') include ':react-native-config' project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android') include ':@react-native-community_async-storage' diff --git a/ios/Podfile b/ios/Podfile index 0bc36d16e8c67..31d6f48f09e00 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -8,6 +8,7 @@ target 'ReactNativeChat' do use_react_native!(:path => config["reactNativePath"]) + target 'ReactNativeChatTests' do inherit! :complete # Pods for testing diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 1b6f81bf7db21..2212816a26c5b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -240,7 +240,7 @@ PODS: - react-native-config/App (= 1.3.3) - react-native-config/App (1.3.3): - React - - react-native-netinfo (5.9.5): + - react-native-netinfo (5.9.6): - React - react-native-safe-area-context (3.1.4): - React @@ -473,9 +473,9 @@ SPEC CHECKSUMS: React-jsiexecutor: 8ca588cc921e70590820ce72b8789b02c67cce38 React-jsinspector: b14e62ebe7a66e9231e9581279909f2fc3db6606 react-native-config: 9a061347e0136fdb32d43a34d60999297d672361 - react-native-netinfo: 7f3f3ed9e8f0e7ab3e7cac00cbfdc6997e25ecaf - react-native-safe-area-context: 0ed9288ed4409beabb0817b54efc047286fc84da - react-native-webview: 797f50d16bb271c4270bc742040a64c79ec7147c + react-native-netinfo: 38a1e0b3e89b48e4b5833ed475d8df5f049f6f90 + react-native-safe-area-context: eb91fe1fb3f7b87d9c30a7f0808407d8569d539d + react-native-webview: df9ff59f76e991aefa7174831a0af48ddbac5f1b React-RCTActionSheet: 910163b6b09685a35c4ebbc52b66d1bfbbe39fc5 React-RCTAnimation: 9a883bbe1e9d2e158d4fb53765ed64c8dc2200c6 React-RCTBlob: 39cf0ece1927996c4466510e25d2105f67010e13 @@ -486,10 +486,10 @@ SPEC CHECKSUMS: React-RCTText: 1b6773e776e4b33f90468c20fe3b16ca3e224bb8 React-RCTVibration: 4d2e726957f4087449739b595f107c0d4b6c2d2d ReactCommon: a0a1edbebcac5e91338371b72ffc66aa822792ce - RNCAsyncStorage: db711e29e5e0500d9bd21aa0c2e397efa45302b1 + RNCAsyncStorage: d059c3ee71738c39834a627476322a5a8cd5bf36 Yoga: 7740b94929bbacbddda59bf115b5317e9a161598 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: 7f6bb9c130ea13236f8249f800f75d671c1833fa +PODFILE CHECKSUM: c2a1bd5a4b33274bbce4e5f7d986f3b4891a117e COCOAPODS: 1.9.3 diff --git a/package-lock.json b/package-lock.json index d6a6fa60e5bcc..1b37f7cb32fca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1795,9 +1795,9 @@ "dev": true }, "@react-native-community/netinfo": { - "version": "5.9.5", - "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-5.9.5.tgz", - "integrity": "sha512-PbSsRmhRwYIMdeVJTf9gJtvW0TVq/hmgz1xyjsrTIsQ7QS7wbMEiv1Eb/M/y6AEEsdUped5Axm5xykq9TGISHg==" + "version": "5.9.6", + "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-5.9.6.tgz", + "integrity": "sha512-cEkA1Apg8+VjnDdeDZRHI+2RqouiPKgYnewouRkvF4ettH9ZS4Cmi/nANQKIpIu2L+czboxM3fCZ44nc7IM9VQ==" }, "@sindresorhus/is": { "version": "0.14.0", diff --git a/package.json b/package.json index 89557eb3e2dbd..b4747ebe81fb3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@react-native-community/async-storage": "^1.11.0", - "@react-native-community/netinfo": "^5.9.5", + "@react-native-community/netinfo": "^5.9.6", "babel-plugin-transform-remove-console": "^6.9.4", "dotenv": "^8.2.0", "electron-serve": "^1.0.0", diff --git a/src/lib/NetInfo/index.js b/src/lib/NetInfo/index.js new file mode 100644 index 0000000000000..a7764966334a2 --- /dev/null +++ b/src/lib/NetInfo/index.js @@ -0,0 +1,22 @@ +// @TODO open an issue and get this working for React Native for Web instead of using this shim. It should be supported but for some reason it is not working. + +const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; +const unsubscribe = connection ? connection.removeEventListener('change', () => {}) : () => { + window.removeEventListener('offline', () => {}); + window.removeEventListener('online', () => {}); +}; + +function addEventListener(callback) { + if (connection) { + connection.addEventListener('change', () => callback(navigator.onLine)); + } else { + window.addEventListener('offline', () => callback(false)); + window.addEventListener('online', () => callback(true)); + } + + return unsubscribe; +} + +export default { + addEventListener, +}; diff --git a/src/lib/NetInfo/index.native.js b/src/lib/NetInfo/index.native.js new file mode 100644 index 0000000000000..93af543cc6360 --- /dev/null +++ b/src/lib/NetInfo/index.native.js @@ -0,0 +1,3 @@ +import NetInfo from '@react-native-community/netinfo'; + +export default NetInfo; diff --git a/src/lib/Network.js b/src/lib/Network.js index dfe1d52334fc8..20a437f3b2042 100644 --- a/src/lib/Network.js +++ b/src/lib/Network.js @@ -7,6 +7,7 @@ import Str from './Str'; import Guid from './Guid'; import {registerSocketEventCallback} from './Pusher/pusher'; import redirectToSignIn from './actions/ActionsSignInRedirect'; +import NetInfo from './NetInfo'; let isAppOffline = false; @@ -18,6 +19,12 @@ let reauthenticating = false; // Queue for network requests so we don't lose actions done by the user while offline const networkRequestQueue = []; + +// Subscribe +NetInfo.addEventListener(connected => { + Ion.merge(IONKEYS.NETWORK, {isOffline: !connected}); +}); + /** * Events that happen on the pusher socket are used to determine if the app is online or offline. The offline setting * is stored in Ion so the rest of the app has access to it. @@ -26,6 +33,7 @@ const networkRequestQueue = []; * @params {object} data */ registerSocketEventCallback((eventName, data) => { + console.log(eventName, data); let isCurrentlyOffline = false; switch (eventName) { case 'connected': diff --git a/src/page/HomePage/SidebarView.js b/src/page/HomePage/SidebarView.js index 11cdec18ed285..9ce392890787d 100644 --- a/src/page/HomePage/SidebarView.js +++ b/src/page/HomePage/SidebarView.js @@ -1,4 +1,5 @@ import React from 'react'; +import get from 'lodash.get'; import _ from 'underscore'; import { View, @@ -53,6 +54,8 @@ class SidebarView extends React.Component { render() { const reports = this.state && this.state.reports; this.updateUnreadReportIndicator(); + const isOffline = get(this.state, 'isOffline', true); + const indicatorStyles = [styles.statusIndicator, isOffline ? styles.statusIndicatorOffline : styles.statusIndicatorOnline]; return ( @@ -83,9 +86,7 @@ class SidebarView extends React.Component { source={{uri: this.state && this.state.avatarURL}} style={[styles.historyItemAvatar]} /> - {this.state && this.state.isOffline && ( - - )} + {this.state && this.state.userDisplayName && ( diff --git a/src/style/StyleSheet.js b/src/style/StyleSheet.js index e8f69dda85360..53b6f60012dc5 100644 --- a/src/style/StyleSheet.js +++ b/src/style/StyleSheet.js @@ -233,7 +233,6 @@ const styles = { }, statusIndicator: { - backgroundColor: colors.icon, borderColor: colors.heading, borderRadius: 7, borderWidth: 2, @@ -245,6 +244,14 @@ const styles = { zIndex: 10, }, + statusIndicatorOnline: { + backgroundColor: colors.green, + }, + + statusIndicatorOffline: { + backgroundColor: colors.icon, + }, + sidebarFooterUsername: { color: '#FFFFFF', fontSize: 15, From 0eb60d4e285cddb467ec311773ce0351c10b8411 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 17:25:35 -0700 Subject: [PATCH 02/12] Just change indicator for now --- src/lib/Network.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/Network.js b/src/lib/Network.js index 20a437f3b2042..c8f567a892be2 100644 --- a/src/lib/Network.js +++ b/src/lib/Network.js @@ -7,7 +7,8 @@ import Str from './Str'; import Guid from './Guid'; import {registerSocketEventCallback} from './Pusher/pusher'; import redirectToSignIn from './actions/ActionsSignInRedirect'; -import NetInfo from './NetInfo'; + +// import NetInfo from './NetInfo'; let isAppOffline = false; @@ -21,9 +22,9 @@ const networkRequestQueue = []; // Subscribe -NetInfo.addEventListener(connected => { - Ion.merge(IONKEYS.NETWORK, {isOffline: !connected}); -}); +// NetInfo.addEventListener((connected) => { +// Ion.merge(IONKEYS.NETWORK, {isOffline: !connected}); +// }); /** * Events that happen on the pusher socket are used to determine if the app is online or offline. The offline setting From 9769ba6b90f1c8b0398eb645cecf632877c89821 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 17:27:45 -0700 Subject: [PATCH 03/12] bump down this lib hmm --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4747ebe81fb3..89557eb3e2dbd 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@react-native-community/async-storage": "^1.11.0", - "@react-native-community/netinfo": "^5.9.6", + "@react-native-community/netinfo": "^5.9.5", "babel-plugin-transform-remove-console": "^6.9.4", "dotenv": "^8.2.0", "electron-serve": "^1.0.0", From 4efa3c64dc28922c3129843dc723057857c4f5bd Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 17:29:48 -0700 Subject: [PATCH 04/12] undo things --- .../expensifyreactnative/chat/MainApplication.java | 1 - android/settings.gradle | 2 -- ios/Podfile | 1 - ios/Podfile.lock | 12 ++++++------ package-lock.json | 6 +++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java b/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java index 552390ea07830..eeab3873a09fc 100644 --- a/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java +++ b/android/app/src/main/java/com/expensifyreactnative/chat/MainApplication.java @@ -4,7 +4,6 @@ import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; -import com.reactnativecommunity.netinfo.NetInfoPackage; import com.lugg.ReactNativeConfig.ReactNativeConfigPackage; import com.reactnativecommunity.asyncstorage.AsyncStoragePackage; import com.facebook.react.ReactInstanceManager; diff --git a/android/settings.gradle b/android/settings.gradle index a2f3e5189908c..3deca494c3607 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,6 +1,4 @@ rootProject.name = 'ReactNativeChat' -include ':@react-native-community_netinfo' -project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android') include ':react-native-config' project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android') include ':@react-native-community_async-storage' diff --git a/ios/Podfile b/ios/Podfile index 31d6f48f09e00..0bc36d16e8c67 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -8,7 +8,6 @@ target 'ReactNativeChat' do use_react_native!(:path => config["reactNativePath"]) - target 'ReactNativeChatTests' do inherit! :complete # Pods for testing diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2212816a26c5b..1b6f81bf7db21 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -240,7 +240,7 @@ PODS: - react-native-config/App (= 1.3.3) - react-native-config/App (1.3.3): - React - - react-native-netinfo (5.9.6): + - react-native-netinfo (5.9.5): - React - react-native-safe-area-context (3.1.4): - React @@ -473,9 +473,9 @@ SPEC CHECKSUMS: React-jsiexecutor: 8ca588cc921e70590820ce72b8789b02c67cce38 React-jsinspector: b14e62ebe7a66e9231e9581279909f2fc3db6606 react-native-config: 9a061347e0136fdb32d43a34d60999297d672361 - react-native-netinfo: 38a1e0b3e89b48e4b5833ed475d8df5f049f6f90 - react-native-safe-area-context: eb91fe1fb3f7b87d9c30a7f0808407d8569d539d - react-native-webview: df9ff59f76e991aefa7174831a0af48ddbac5f1b + react-native-netinfo: 7f3f3ed9e8f0e7ab3e7cac00cbfdc6997e25ecaf + react-native-safe-area-context: 0ed9288ed4409beabb0817b54efc047286fc84da + react-native-webview: 797f50d16bb271c4270bc742040a64c79ec7147c React-RCTActionSheet: 910163b6b09685a35c4ebbc52b66d1bfbbe39fc5 React-RCTAnimation: 9a883bbe1e9d2e158d4fb53765ed64c8dc2200c6 React-RCTBlob: 39cf0ece1927996c4466510e25d2105f67010e13 @@ -486,10 +486,10 @@ SPEC CHECKSUMS: React-RCTText: 1b6773e776e4b33f90468c20fe3b16ca3e224bb8 React-RCTVibration: 4d2e726957f4087449739b595f107c0d4b6c2d2d ReactCommon: a0a1edbebcac5e91338371b72ffc66aa822792ce - RNCAsyncStorage: d059c3ee71738c39834a627476322a5a8cd5bf36 + RNCAsyncStorage: db711e29e5e0500d9bd21aa0c2e397efa45302b1 Yoga: 7740b94929bbacbddda59bf115b5317e9a161598 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: c2a1bd5a4b33274bbce4e5f7d986f3b4891a117e +PODFILE CHECKSUM: 7f6bb9c130ea13236f8249f800f75d671c1833fa COCOAPODS: 1.9.3 diff --git a/package-lock.json b/package-lock.json index 1b37f7cb32fca..d6a6fa60e5bcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1795,9 +1795,9 @@ "dev": true }, "@react-native-community/netinfo": { - "version": "5.9.6", - "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-5.9.6.tgz", - "integrity": "sha512-cEkA1Apg8+VjnDdeDZRHI+2RqouiPKgYnewouRkvF4ettH9ZS4Cmi/nANQKIpIu2L+czboxM3fCZ44nc7IM9VQ==" + "version": "5.9.5", + "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-5.9.5.tgz", + "integrity": "sha512-PbSsRmhRwYIMdeVJTf9gJtvW0TVq/hmgz1xyjsrTIsQ7QS7wbMEiv1Eb/M/y6AEEsdUped5Axm5xykq9TGISHg==" }, "@sindresorhus/is": { "version": "0.14.0", From f02922f8e874418be5ce6b25f35b24b7ad3f23dd Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 18:11:09 -0700 Subject: [PATCH 05/12] Fix NetInfo callback --- android/app/src/debug/AndroidManifest.xml | 2 +- android/app/src/main/AndroidManifest.xml | 1 + src/lib/NetInfo/index.js | 6 +++--- src/lib/Network.js | 12 +++++------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index fa26aa56e1c14..6dc098f4797a0 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -3,6 +3,6 @@ xmlns:tools="http://schemas.android.com/tools"> - + diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index cefe08dd125c2..5f8a5ca5adbb8 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ package="com.expensifyreactnative.chat"> + function addEventListener(callback) { if (connection) { - connection.addEventListener('change', () => callback(navigator.onLine)); + connection.addEventListener('change', () => callback({isConnected: navigator.onLine})); } else { - window.addEventListener('offline', () => callback(false)); - window.addEventListener('online', () => callback(true)); + window.addEventListener('offline', () => callback({isConnected: false})); + window.addEventListener('online', () => callback({isConnected: true})); } return unsubscribe; diff --git a/src/lib/Network.js b/src/lib/Network.js index c8f567a892be2..c82a041a5e4df 100644 --- a/src/lib/Network.js +++ b/src/lib/Network.js @@ -7,8 +7,7 @@ import Str from './Str'; import Guid from './Guid'; import {registerSocketEventCallback} from './Pusher/pusher'; import redirectToSignIn from './actions/ActionsSignInRedirect'; - -// import NetInfo from './NetInfo'; +import NetInfo from './NetInfo'; let isAppOffline = false; @@ -21,10 +20,10 @@ let reauthenticating = false; const networkRequestQueue = []; -// Subscribe -// NetInfo.addEventListener((connected) => { -// Ion.merge(IONKEYS.NETWORK, {isOffline: !connected}); -// }); +// Subscribe to the +NetInfo.addEventListener((state) => { + Ion.merge(IONKEYS.NETWORK, {isOffline: !state.isConnected}); +}); /** * Events that happen on the pusher socket are used to determine if the app is online or offline. The offline setting @@ -34,7 +33,6 @@ const networkRequestQueue = []; * @params {object} data */ registerSocketEventCallback((eventName, data) => { - console.log(eventName, data); let isCurrentlyOffline = false; switch (eventName) { case 'connected': From 434b0c1142d606435a83fdd6608b48c1b616a4f4 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 18:18:21 -0700 Subject: [PATCH 06/12] fix comment --- src/lib/Network.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/Network.js b/src/lib/Network.js index c82a041a5e4df..6f48ec7b6d10b 100644 --- a/src/lib/Network.js +++ b/src/lib/Network.js @@ -20,7 +20,8 @@ let reauthenticating = false; const networkRequestQueue = []; -// Subscribe to the +// Subscribe to the state change event via NetInfo so we can update +// whether a user has internet connectivity or not NetInfo.addEventListener((state) => { Ion.merge(IONKEYS.NETWORK, {isOffline: !state.isConnected}); }); From 105634a6c3fa2c183b0b165de120b3b1760ff44c Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 18:37:01 -0700 Subject: [PATCH 07/12] update netinfo --- ios/Podfile.lock | 10 +++++----- package-lock.json | 6 +++--- package.json | 2 +- src/lib/NetInfo/index.js | 22 ---------------------- src/lib/NetInfo/index.native.js | 3 --- src/lib/Network.js | 3 +-- 6 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 src/lib/NetInfo/index.js delete mode 100644 src/lib/NetInfo/index.native.js diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 1b6f81bf7db21..56c878ab25621 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -240,7 +240,7 @@ PODS: - react-native-config/App (= 1.3.3) - react-native-config/App (1.3.3): - React - - react-native-netinfo (5.9.5): + - react-native-netinfo (5.9.6): - React - react-native-safe-area-context (3.1.4): - React @@ -473,9 +473,9 @@ SPEC CHECKSUMS: React-jsiexecutor: 8ca588cc921e70590820ce72b8789b02c67cce38 React-jsinspector: b14e62ebe7a66e9231e9581279909f2fc3db6606 react-native-config: 9a061347e0136fdb32d43a34d60999297d672361 - react-native-netinfo: 7f3f3ed9e8f0e7ab3e7cac00cbfdc6997e25ecaf - react-native-safe-area-context: 0ed9288ed4409beabb0817b54efc047286fc84da - react-native-webview: 797f50d16bb271c4270bc742040a64c79ec7147c + react-native-netinfo: d2c312fa4b151214e1d5c8456ddb5f28ff24a576 + react-native-safe-area-context: eb91fe1fb3f7b87d9c30a7f0808407d8569d539d + react-native-webview: df9ff59f76e991aefa7174831a0af48ddbac5f1b React-RCTActionSheet: 910163b6b09685a35c4ebbc52b66d1bfbbe39fc5 React-RCTAnimation: 9a883bbe1e9d2e158d4fb53765ed64c8dc2200c6 React-RCTBlob: 39cf0ece1927996c4466510e25d2105f67010e13 @@ -486,7 +486,7 @@ SPEC CHECKSUMS: React-RCTText: 1b6773e776e4b33f90468c20fe3b16ca3e224bb8 React-RCTVibration: 4d2e726957f4087449739b595f107c0d4b6c2d2d ReactCommon: a0a1edbebcac5e91338371b72ffc66aa822792ce - RNCAsyncStorage: db711e29e5e0500d9bd21aa0c2e397efa45302b1 + RNCAsyncStorage: d059c3ee71738c39834a627476322a5a8cd5bf36 Yoga: 7740b94929bbacbddda59bf115b5317e9a161598 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/package-lock.json b/package-lock.json index d6a6fa60e5bcc..1b37f7cb32fca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1795,9 +1795,9 @@ "dev": true }, "@react-native-community/netinfo": { - "version": "5.9.5", - "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-5.9.5.tgz", - "integrity": "sha512-PbSsRmhRwYIMdeVJTf9gJtvW0TVq/hmgz1xyjsrTIsQ7QS7wbMEiv1Eb/M/y6AEEsdUped5Axm5xykq9TGISHg==" + "version": "5.9.6", + "resolved": "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-5.9.6.tgz", + "integrity": "sha512-cEkA1Apg8+VjnDdeDZRHI+2RqouiPKgYnewouRkvF4ettH9ZS4Cmi/nANQKIpIu2L+czboxM3fCZ44nc7IM9VQ==" }, "@sindresorhus/is": { "version": "0.14.0", diff --git a/package.json b/package.json index 89557eb3e2dbd..b4747ebe81fb3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@react-native-community/async-storage": "^1.11.0", - "@react-native-community/netinfo": "^5.9.5", + "@react-native-community/netinfo": "^5.9.6", "babel-plugin-transform-remove-console": "^6.9.4", "dotenv": "^8.2.0", "electron-serve": "^1.0.0", diff --git a/src/lib/NetInfo/index.js b/src/lib/NetInfo/index.js deleted file mode 100644 index 3e188d26f9982..0000000000000 --- a/src/lib/NetInfo/index.js +++ /dev/null @@ -1,22 +0,0 @@ -// @TODO open an issue and get this working for React Native for Web instead of using this shim. It should be supported but for some reason it is not working. - -const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; -const unsubscribe = connection ? connection.removeEventListener('change', () => {}) : () => { - window.removeEventListener('offline', () => {}); - window.removeEventListener('online', () => {}); -}; - -function addEventListener(callback) { - if (connection) { - connection.addEventListener('change', () => callback({isConnected: navigator.onLine})); - } else { - window.addEventListener('offline', () => callback({isConnected: false})); - window.addEventListener('online', () => callback({isConnected: true})); - } - - return unsubscribe; -} - -export default { - addEventListener, -}; diff --git a/src/lib/NetInfo/index.native.js b/src/lib/NetInfo/index.native.js deleted file mode 100644 index 93af543cc6360..0000000000000 --- a/src/lib/NetInfo/index.native.js +++ /dev/null @@ -1,3 +0,0 @@ -import NetInfo from '@react-native-community/netinfo'; - -export default NetInfo; diff --git a/src/lib/Network.js b/src/lib/Network.js index 6f48ec7b6d10b..b8a8f3c71d542 100644 --- a/src/lib/Network.js +++ b/src/lib/Network.js @@ -1,4 +1,5 @@ import _ from 'underscore'; +import NetInfo from '@react-native-community/netinfo'; import Ion from './Ion'; import CONFIG from '../CONFIG'; import IONKEYS from '../IONKEYS'; @@ -7,7 +8,6 @@ import Str from './Str'; import Guid from './Guid'; import {registerSocketEventCallback} from './Pusher/pusher'; import redirectToSignIn from './actions/ActionsSignInRedirect'; -import NetInfo from './NetInfo'; let isAppOffline = false; @@ -19,7 +19,6 @@ let reauthenticating = false; // Queue for network requests so we don't lose actions done by the user while offline const networkRequestQueue = []; - // Subscribe to the state change event via NetInfo so we can update // whether a user has internet connectivity or not NetInfo.addEventListener((state) => { From 93765f16325f701e00c68e325dee30e5b827d3f0 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 19:04:10 -0700 Subject: [PATCH 08/12] add web.js extensions so that modules with react-native-web support can work --- webpack.common.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.common.js b/webpack.common.js index 3f2e400c021d5..cddb1e55e8174 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -69,5 +69,6 @@ module.exports = { 'react-native-config': 'react-web-config', 'react-native$': 'react-native-web', }, + extensions: [ '.web.js', '.js' ], }, }; From cdc80cd3909b3bf417f2904df315a885b8c14e09 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 19:08:43 -0700 Subject: [PATCH 09/12] fix long line --- src/page/HomePage/SidebarView.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/page/HomePage/SidebarView.js b/src/page/HomePage/SidebarView.js index 9ce392890787d..6f2e4f0b57e54 100644 --- a/src/page/HomePage/SidebarView.js +++ b/src/page/HomePage/SidebarView.js @@ -55,7 +55,10 @@ class SidebarView extends React.Component { const reports = this.state && this.state.reports; this.updateUnreadReportIndicator(); const isOffline = get(this.state, 'isOffline', true); - const indicatorStyles = [styles.statusIndicator, isOffline ? styles.statusIndicatorOffline : styles.statusIndicatorOnline]; + const indicatorStyles = [ + styles.statusIndicator, + isOffline ? styles.statusIndicatorOffline : styles.statusIndicatorOnline + ]; return ( From 8178b7cba48ac8f77d338207a2446ca509008302 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 19:39:52 -0700 Subject: [PATCH 10/12] add comment --- webpack.common.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/webpack.common.js b/webpack.common.js index cddb1e55e8174..eff32f2f09a69 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -69,6 +69,9 @@ module.exports = { 'react-native-config': 'react-web-config', 'react-native$': 'react-native-web', }, + + // React Native libraries may have web-specific module implementations that appear with the extension `.web.js` + // without this, web will try to use native implementations and break in not very obvious ways extensions: [ '.web.js', '.js' ], }, }; From bb5d8ef799b30321ac0aed90ca12e68bced2f211 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 19 Aug 2020 19:41:25 -0700 Subject: [PATCH 11/12] more comment --- src/lib/Network.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/Network.js b/src/lib/Network.js index b8a8f3c71d542..a607afae29ad1 100644 --- a/src/lib/Network.js +++ b/src/lib/Network.js @@ -20,7 +20,8 @@ let reauthenticating = false; const networkRequestQueue = []; // Subscribe to the state change event via NetInfo so we can update -// whether a user has internet connectivity or not +// whether a user has internet connectivity or not. This is more reliable +// than the Pusher `disconnected` event which takes about 10-15 seconds to emit NetInfo.addEventListener((state) => { Ion.merge(IONKEYS.NETWORK, {isOffline: !state.isConnected}); }); From 6cb5fd6818f812dbd422c8b73a7ce3ec2041ec8f Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 20 Aug 2020 19:08:59 -0700 Subject: [PATCH 12/12] fix eslint --- src/page/HomePage/SidebarView.js | 1 - webpack.common.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/page/HomePage/SidebarView.js b/src/page/HomePage/SidebarView.js index b03c6968d8942..d52369876028e 100644 --- a/src/page/HomePage/SidebarView.js +++ b/src/page/HomePage/SidebarView.js @@ -1,5 +1,4 @@ import React from 'react'; -import get from 'lodash.get'; import _ from 'underscore'; import { View, diff --git a/webpack.common.js b/webpack.common.js index eff32f2f09a69..979dcb1c50d04 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -72,6 +72,6 @@ module.exports = { // React Native libraries may have web-specific module implementations that appear with the extension `.web.js` // without this, web will try to use native implementations and break in not very obvious ways - extensions: [ '.web.js', '.js' ], + extensions: ['.web.js', '.js'], }, };