From ba262fe284f9a847861b9c003f1b971d18b6caae Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Fri, 29 Sep 2023 10:53:15 +0200 Subject: [PATCH 1/8] Update to latest react-native-permissions 3.x version --- ios/Podfile | 31 ++++++++++++++++++------------- ios/Podfile.lock | 30 +++--------------------------- package-lock.json | 11 +++++++---- package.json | 2 +- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/ios/Podfile b/ios/Podfile index b30510572448..6aee4b94df04 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -2,17 +2,29 @@ # This value is used by $RNMapboxMaps $RNMapboxMapsImpl = 'mapbox' -# Resolve react_native_pods.rb with node to allow for hoisting -require Pod::Executable.execute_command('node', ['-p', - 'require.resolve( - "react-native/scripts/react_native_pods.rb", - {paths: [process.argv[1]]}, - )', __dir__]).strip +def node_require(script) + # Resolve script with node to allow for hoisting + require Pod::Executable.execute_command('node', ['-p', + "require.resolve( + '#{script}', + {paths: [process.argv[1]]}, + )", __dir__]).strip +end + +node_require('react-native/scripts/react_native_pods.rb') +node_require('react-native-permissions/scripts/setup.rb') # Our min supported iOS version is higher than the default (min_ios_version_supported) to support libraires such as Airship platform :ios, 13 prepare_react_native_project! +setup_permissions([ + 'Camera', + 'LocationAccuracy', + 'LocationAlways', + 'LocationWhenInUse' +]) + # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded # @@ -51,8 +63,6 @@ pre_install do |installer| end target 'NewExpensify' do - permissions_path = '../node_modules/react-native-permissions/ios' - project 'NewExpensify', 'DebugDevelopment' => :debug, 'DebugAdHoc' => :debug, @@ -61,11 +71,6 @@ target 'NewExpensify' do 'ReleaseAdHoc' => :release, 'ReleaseProduction' => :release - pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy" - pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways" - pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse" - pod 'Permission-Camera', :path => "#{permissions_path}/Camera" - config = use_native_modules! # Flags change depending on the env values. diff --git a/ios/Podfile.lock b/ios/Podfile.lock index ba53d939e46c..d7b12a27f261 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -256,14 +256,6 @@ PODS: - Onfido (= 27.4.0) - React - OpenSSL-Universal (1.1.1100) - - Permission-Camera (3.6.1): - - RNPermissions - - Permission-LocationAccuracy (3.6.1): - - RNPermissions - - Permission-LocationAlways (3.6.1): - - RNPermissions - - Permission-LocationWhenInUse (3.6.1): - - RNPermissions - Plaid (4.1.0) - PromisesObjC (2.2.0) - RCT-Folly (2021.07.22.00): @@ -779,7 +771,7 @@ PODS: - React - React-Core - Turf - - RNPermissions (3.6.1): + - RNPermissions (3.9.2): - React-Core - RNReactNativeHapticFeedback (1.14.0): - React-Core @@ -865,10 +857,6 @@ DEPENDENCIES: - lottie-react-native (from `../node_modules/lottie-react-native`) - "onfido-react-native-sdk (from `../node_modules/@onfido/react-native-sdk`)" - OpenSSL-Universal (= 1.1.1100) - - Permission-Camera (from `../node_modules/react-native-permissions/ios/Camera`) - - Permission-LocationAccuracy (from `../node_modules/react-native-permissions/ios/LocationAccuracy`) - - Permission-LocationAlways (from `../node_modules/react-native-permissions/ios/LocationAlways`) - - Permission-LocationWhenInUse (from `../node_modules/react-native-permissions/ios/LocationWhenInUse`) - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) @@ -1015,14 +1003,6 @@ EXTERNAL SOURCES: :path: "../node_modules/lottie-react-native" onfido-react-native-sdk: :path: "../node_modules/@onfido/react-native-sdk" - Permission-Camera: - :path: "../node_modules/react-native-permissions/ios/Camera" - Permission-LocationAccuracy: - :path: "../node_modules/react-native-permissions/ios/LocationAccuracy" - Permission-LocationAlways: - :path: "../node_modules/react-native-permissions/ios/LocationAlways" - Permission-LocationWhenInUse: - :path: "../node_modules/react-native-permissions/ios/LocationWhenInUse" RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTRequired: @@ -1222,10 +1202,6 @@ SPEC CHECKSUMS: Onfido: e36f284b865adcf99d9c905590a64ac09d4a576b onfido-react-native-sdk: 4ecde1a97435dcff9f00a878e3f8d1eb14fabbdc OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c - Permission-Camera: bf6791b17c7f614b6826019fcfdcc286d3a107f6 - Permission-LocationAccuracy: 76df17de5c6b8bc2eee34e61ee92cdd7a864c73d - Permission-LocationAlways: 8d99b025c9f73c696e0cdb367e42525f2e9a26f2 - Permission-LocationWhenInUse: 3ba99e45c852763f730eabecec2870c2382b7bd4 Plaid: 7d340abeadb46c7aa1a91f896c5b22395a31fcf2 PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 @@ -1296,7 +1272,7 @@ SPEC CHECKSUMS: RNGoogleSignin: ccaa4a81582cf713eea562c5dd9dc1961a715fd0 RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81 rnmapbox-maps: 6f638ec002aa6e906a6f766d69cd45f968d98e64 - RNPermissions: dcdb7b99796bbeda6975a6e79ad519c41b251b1c + RNPermissions: cac1c6ac961d288daa26bbe02966ff364e77bd3a RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87 RNScreens: d037903436160a4b039d32606668350d2a808806 @@ -1309,6 +1285,6 @@ SPEC CHECKSUMS: Yoga: 3efc43e0d48686ce2e8c60f99d4e6bd349aff981 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: 2daf34c870819a933f3fefe426801d54b2ff2a14 +PODFILE CHECKSUM: ff769666b7221c15936ebc5576a8c8e467dc6879 COCOAPODS: 1.12.1 diff --git a/package-lock.json b/package-lock.json index bc94fb780a1b..4d32b574ff88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,7 +94,7 @@ "react-native-pager-view": "^6.2.0", "react-native-pdf": "^6.7.1", "react-native-performance": "^5.1.0", - "react-native-permissions": "^3.0.1", + "react-native-permissions": "^3.9.2", "react-native-picker-select": "git+https://github.com/Expensify/react-native-picker-select.git#eae05855286dc699954415cc1d629bfd8e8e47e2", "react-native-plaid-link-sdk": "^10.0.0", "react-native-qrcode-svg": "^6.2.0", @@ -41280,8 +41280,9 @@ } }, "node_modules/react-native-permissions": { - "version": "3.6.1", - "license": "MIT", + "version": "3.9.2", + "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.9.2.tgz", + "integrity": "sha512-mBGoRDKi4twYH+UsPomPdi0dLpV6dGLmKzLpIgB5cLK/dzfM8Sr02Kch1xghVwT13ZkyCyd8DpcL4HgBJ4GQQg==", "peerDependencies": { "react": ">=16.13.1", "react-native": ">=0.63.3", @@ -77305,7 +77306,9 @@ "requires": {} }, "react-native-permissions": { - "version": "3.6.1", + "version": "3.9.2", + "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.9.2.tgz", + "integrity": "sha512-mBGoRDKi4twYH+UsPomPdi0dLpV6dGLmKzLpIgB5cLK/dzfM8Sr02Kch1xghVwT13ZkyCyd8DpcL4HgBJ4GQQg==", "requires": {} }, "react-native-picker-select": { diff --git a/package.json b/package.json index f7f385f7620c..e2d6c9df0031 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "react-native-pager-view": "^6.2.0", "react-native-pdf": "^6.7.1", "react-native-performance": "^5.1.0", - "react-native-permissions": "^3.0.1", + "react-native-permissions": "^3.9.2", "react-native-picker-select": "git+https://github.com/Expensify/react-native-picker-select.git#eae05855286dc699954415cc1d629bfd8e8e47e2", "react-native-plaid-link-sdk": "^10.0.0", "react-native-qrcode-svg": "^6.2.0", From 084d469953c868992bf83708c54ab6719634a192 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Fri, 29 Sep 2023 14:56:10 +0200 Subject: [PATCH 2/8] Fix camera permission status check --- src/pages/iou/ReceiptSelector/index.native.js | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/pages/iou/ReceiptSelector/index.native.js b/src/pages/iou/ReceiptSelector/index.native.js index 4de4e9bb9148..025b889214d0 100644 --- a/src/pages/iou/ReceiptSelector/index.native.js +++ b/src/pages/iou/ReceiptSelector/index.native.js @@ -94,9 +94,7 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) const camera = useRef(null); const [flash, setFlash] = useState(false); - const [permissions, setPermissions] = useState('granted'); - const isAndroidBlockedPermissionRef = useRef(false); - const appState = useRef(AppState.currentState); + const [cameraPermissionStatus, setCameraPermissionStatus] = useState(undefined); const iouType = lodashGet(route, 'params.iouType', ''); const reportID = lodashGet(route, 'params.reportID', ''); @@ -106,16 +104,23 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) const CameraComponent = isInTabNavigator ? TabNavigationAwareCamera : NavigationAwareCamera; - // We want to listen to if the app has come back from background and refresh the permissions status to show camera when permissions were granted useEffect(() => { - const subscription = AppState.addEventListener('change', (nextAppState) => { - if (appState.current.match(/inactive|background/) && nextAppState === 'active') { - CameraPermission.getCameraPermissionStatus().then((permissionStatus) => { - setPermissions(permissionStatus); - }); + const refreshCameraPermissionStatus = () => { + CameraPermission.getCameraPermissionStatus() + .then(setCameraPermissionStatus) + .catch(() => setCameraPermissionStatus(RESULTS.UNAVAILABLE)); + }; + + // Check initial camera permission status + refreshCameraPermissionStatus(); + + // Refresh permission stasus when app gain focus + const subscription = AppState.addEventListener('change', (appState) => { + if (appState !== 'active') { + return; } - appState.current = nextAppState; + refreshCameraPermissionStatus(); }); return () => { @@ -155,14 +160,13 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) const askForPermissions = () => { // There's no way we can check for the BLOCKED status without requesting the permission first // https://github.com/zoontek/react-native-permissions/blob/a836e114ce3a180b2b23916292c79841a267d828/README.md?plain=1#L670 - if (permissions === RESULTS.BLOCKED || isAndroidBlockedPermissionRef.current) { - Linking.openSettings(); - } else if (permissions === RESULTS.DENIED) { - CameraPermission.requestCameraPermission().then((permissionStatus) => { - setPermissions(permissionStatus); - isAndroidBlockedPermissionRef.current = permissionStatus === RESULTS.BLOCKED; - }); - } + CameraPermission.requestCameraPermission().then((status) => { + setCameraPermissionStatus(status); + + if (status === RESULTS.BLOCKED) { + Linking.openSettings(); + } + }); }; /** @@ -231,13 +235,14 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) }); }, [flash, iouType, iou, report, reportID, translate, transactionID, route.path]); - CameraPermission.getCameraPermissionStatus().then((permissionStatus) => { - setPermissions(permissionStatus); - }); + // Wait for camera permission status to render + if (cameraPermissionStatus == null) { + return null; + } return ( - {permissions !== RESULTS.GRANTED && ( + {cameraPermissionStatus !== RESULTS.GRANTED && ( )} - {permissions === RESULTS.GRANTED && device == null && ( + {cameraPermissionStatus === RESULTS.GRANTED && device == null && ( )} - {permissions === RESULTS.GRANTED && device != null && ( + {cameraPermissionStatus === RESULTS.GRANTED && device != null && ( Date: Fri, 29 Sep 2023 14:59:43 +0200 Subject: [PATCH 3/8] Fix typo --- src/pages/iou/ReceiptSelector/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/ReceiptSelector/index.native.js b/src/pages/iou/ReceiptSelector/index.native.js index 025b889214d0..a7487e90717e 100644 --- a/src/pages/iou/ReceiptSelector/index.native.js +++ b/src/pages/iou/ReceiptSelector/index.native.js @@ -114,7 +114,7 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) // Check initial camera permission status refreshCameraPermissionStatus(); - // Refresh permission stasus when app gain focus + // Refresh permission status when app gain focus const subscription = AppState.addEventListener('change', (appState) => { if (appState !== 'active') { return; From c04db17ad994c216b9ea2e9eadfe02f71fbf69f1 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Mon, 2 Oct 2023 16:03:17 +0200 Subject: [PATCH 4/8] Display an alert when permission is blocked --- src/pages/iou/ReceiptSelector/index.native.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pages/iou/ReceiptSelector/index.native.js b/src/pages/iou/ReceiptSelector/index.native.js index a7487e90717e..c9ca26185252 100644 --- a/src/pages/iou/ReceiptSelector/index.native.js +++ b/src/pages/iou/ReceiptSelector/index.native.js @@ -160,13 +160,17 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) const askForPermissions = () => { // There's no way we can check for the BLOCKED status without requesting the permission first // https://github.com/zoontek/react-native-permissions/blob/a836e114ce3a180b2b23916292c79841a267d828/README.md?plain=1#L670 - CameraPermission.requestCameraPermission().then((status) => { - setCameraPermissionStatus(status); + CameraPermission.requestCameraPermission() + .then((status) => { + setCameraPermissionStatus(status); - if (status === RESULTS.BLOCKED) { - Linking.openSettings(); - } - }); + if (status === RESULTS.BLOCKED) { + showPermissionsAlert(); + } + }) + .catch(() => { + setCameraPermissionStatus(RESULTS.UNAVAILABLE); + }); }; /** From 4b3b73551d3b14c23aa3c6543f70cf555d50649d Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 4 Oct 2023 13:24:19 +0200 Subject: [PATCH 5/8] Update react-native-permissions to 3.9.3 --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d32b574ff88..4eaa399a8d90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,7 +94,7 @@ "react-native-pager-view": "^6.2.0", "react-native-pdf": "^6.7.1", "react-native-performance": "^5.1.0", - "react-native-permissions": "^3.9.2", + "react-native-permissions": "^3.9.3", "react-native-picker-select": "git+https://github.com/Expensify/react-native-picker-select.git#eae05855286dc699954415cc1d629bfd8e8e47e2", "react-native-plaid-link-sdk": "^10.0.0", "react-native-qrcode-svg": "^6.2.0", @@ -41280,9 +41280,9 @@ } }, "node_modules/react-native-permissions": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.9.2.tgz", - "integrity": "sha512-mBGoRDKi4twYH+UsPomPdi0dLpV6dGLmKzLpIgB5cLK/dzfM8Sr02Kch1xghVwT13ZkyCyd8DpcL4HgBJ4GQQg==", + "version": "3.9.3", + "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.9.3.tgz", + "integrity": "sha512-2UqG2Em4xHxLq0E1XynXMdQ//XZltxVUjTn/i4fPIZuuZ0cQ+ydAQmLXqDPxOXvG0sICwc3oe0orJmQdqpa1sQ==", "peerDependencies": { "react": ">=16.13.1", "react-native": ">=0.63.3", @@ -77306,9 +77306,9 @@ "requires": {} }, "react-native-permissions": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.9.2.tgz", - "integrity": "sha512-mBGoRDKi4twYH+UsPomPdi0dLpV6dGLmKzLpIgB5cLK/dzfM8Sr02Kch1xghVwT13ZkyCyd8DpcL4HgBJ4GQQg==", + "version": "3.9.3", + "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.9.3.tgz", + "integrity": "sha512-2UqG2Em4xHxLq0E1XynXMdQ//XZltxVUjTn/i4fPIZuuZ0cQ+ydAQmLXqDPxOXvG0sICwc3oe0orJmQdqpa1sQ==", "requires": {} }, "react-native-picker-select": { diff --git a/package.json b/package.json index e2d6c9df0031..e03c72ed0211 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "react-native-pager-view": "^6.2.0", "react-native-pdf": "^6.7.1", "react-native-performance": "^5.1.0", - "react-native-permissions": "^3.9.2", + "react-native-permissions": "^3.9.3", "react-native-picker-select": "git+https://github.com/Expensify/react-native-picker-select.git#eae05855286dc699954415cc1d629bfd8e8e47e2", "react-native-plaid-link-sdk": "^10.0.0", "react-native-qrcode-svg": "^6.2.0", From 6513c02ef4be12ba37668efeee318f323cd879e3 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 4 Oct 2023 14:17:48 +0200 Subject: [PATCH 6/8] Update Podfile.lock --- ios/Podfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index d7b12a27f261..2a181b680a58 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -771,7 +771,7 @@ PODS: - React - React-Core - Turf - - RNPermissions (3.9.2): + - RNPermissions (3.9.3): - React-Core - RNReactNativeHapticFeedback (1.14.0): - React-Core @@ -1272,7 +1272,7 @@ SPEC CHECKSUMS: RNGoogleSignin: ccaa4a81582cf713eea562c5dd9dc1961a715fd0 RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81 rnmapbox-maps: 6f638ec002aa6e906a6f766d69cd45f968d98e64 - RNPermissions: cac1c6ac961d288daa26bbe02966ff364e77bd3a + RNPermissions: 9b086c8f05b2e2faa587fdc31f4c5ab4509728aa RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87 RNScreens: d037903436160a4b039d32606668350d2a808806 @@ -1287,4 +1287,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: ff769666b7221c15936ebc5576a8c8e467dc6879 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 From 187a389dde3a939f26bde63ca46b4e514cf7a8c6 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Mon, 9 Oct 2023 10:50:26 +0200 Subject: [PATCH 7/8] Fix cocoapods version --- ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2a181b680a58..f2efbfb16dc8 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1287,4 +1287,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: ff769666b7221c15936ebc5576a8c8e467dc6879 -COCOAPODS: 1.13.0 +COCOAPODS: 1.12.1 From 60e025412474384f3d06572ce55acade26fda391 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 11 Oct 2023 00:58:36 +0200 Subject: [PATCH 8/8] Fix linting --- src/pages/iou/ReceiptSelector/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/ReceiptSelector/index.native.js b/src/pages/iou/ReceiptSelector/index.native.js index 655769da3ccf..d509fbce176d 100644 --- a/src/pages/iou/ReceiptSelector/index.native.js +++ b/src/pages/iou/ReceiptSelector/index.native.js @@ -331,7 +331,7 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator}) accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON} accessibilityLabel={translate('receipt.flash')} style={[styles.alignItemsEnd]} - disabled={permissions !== RESULTS.GRANTED} + disabled={cameraPermissionStatus !== RESULTS.GRANTED} onPress={() => setFlash((prevFlash) => !prevFlash)} >