Skip to content

Commit

Permalink
Merge pull request #1463 from cmgustavo/bug/react-native-permissions-…
Browse files Browse the repository at this point in the history
…upgrade-01

Chore: Upgrade react-native-permissions
  • Loading branch information
JohnathanWhite authored Nov 14, 2024
2 parents 0b2f4f9 + da5b232 commit 2ab2214
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 137 deletions.
7 changes: 5 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>


<!-- enable push notification for Android 13+ -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<permission
android:name="com.bitpay.wallet.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
Expand All @@ -41,7 +44,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver
android:name=".CustomBroadcastReceiver"
android:exported="false">
Expand Down
26 changes: 23 additions & 3 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
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

# Use it to require both react-native's and this package's scripts:
node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

#######
Expand All @@ -13,6 +25,16 @@ min_ios_version_supported = project.build_configurations.first.build_settings['I
platform :ios, min_ios_version_supported
prepare_react_native_project!

# Setup permissions you need
setup_permissions([
'AppTrackingTransparency',
'Bluetooth',
'Camera',
'FaceID',
'LocationWhenInUse',
'Notifications',
])

# 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
#
Expand All @@ -34,8 +56,6 @@ end
$VCEnableLocation=false

target 'BitPayApp' do
permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications/Permission-Notifications.podspec"
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text', :modular_headers => true

config = use_native_modules!
Expand Down
14 changes: 4 additions & 10 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ PODS:
- MMKVCore (1.3.9)
- MultiplatformBleAdapter (0.1.9)
- OpenSSL-Universal (1.1.1100)
- Permission-Notifications (3.7.2):
- RNPermissions
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -616,7 +614,7 @@ PODS:
- React-Core
- RNOS (1.2.6):
- React
- RNPermissions (3.7.2):
- RNPermissions (5.1.0):
- React-Core
- RNQuickAction (0.3.13):
- React
Expand Down Expand Up @@ -686,7 +684,6 @@ DEPENDENCIES:
- libevent (~> 2.1.12)
- MixpanelReactNative (from `../node_modules/mixpanel-react-native`)
- OpenSSL-Universal (= 1.1.1100)
- Permission-Notifications (from `../node_modules/react-native-permissions/ios/Notifications/Permission-Notifications.podspec`)
- 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`)
Expand Down Expand Up @@ -818,8 +815,6 @@ EXTERNAL SOURCES:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
MixpanelReactNative:
:path: "../node_modules/mixpanel-react-native"
Permission-Notifications:
:path: "../node_modules/react-native-permissions/ios/Notifications/Permission-Notifications.podspec"
RCT-Folly:
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
RCTRequired:
Expand Down Expand Up @@ -983,7 +978,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AppsFlyerFramework: 9f304d91cc80b6579b1206a59220383056b58b47
boost: 7dcd2de282d72e344012f7d6564d024930a6a440
boost: 57d2868c099736d80fcd648bf211b4431e51a558
braze-react-native-sdk: 7ec46f6d33f60946797e75fb06998c03861328d8
BrazeKit: 4afa5f9a89384d06515719b5d246b4676870f030
BrazeLocation: 8f8a54c4170d9ee6035495364f493614401acad0
Expand Down Expand Up @@ -1013,7 +1008,6 @@ SPEC CHECKSUMS:
MMKVCore: af055b00e27d88cd92fad301c5fecd1ff9b26dd9
MultiplatformBleAdapter: 5a6a897b006764392f9cef785e4360f54fb9477d
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Permission-Notifications: dbc8cb572cdfbc3c2941feecce4c7900bbdccea1
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: 01c639ec840ee03928b2d65f5cd5297d737b3834
RCTTypeSafety: 9623592521a1576363baf3d6ab8d164cfe9062bf
Expand Down Expand Up @@ -1083,7 +1077,7 @@ SPEC CHECKSUMS:
RNInAppBrowser: e36d6935517101ccba0e875bac8ad7b0cb655364
RNLocalize: 0df7970cfc60389f00eb62fd7c097dc75af3fb4f
RNOS: 6f2f9a70895bbbfbdad7196abd952e7b01d45027
RNPermissions: 2fbbcb7244357507f958d626d58eb15fb0013d85
RNPermissions: 5642e6521a29e7aed5049d00230ee0fa80a352e0
RNQuickAction: 6d404a869dc872cde841ad3147416a670d13fa93
RNRate: ef3bcff84f39bb1d1e41c5593d3eea4aab2bd73a
RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c
Expand All @@ -1099,6 +1093,6 @@ SPEC CHECKSUMS:
Yoga: ef534101bb891fb09bae657417f34d399c1efe38
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: d45587e182ed77c86769f50ab49373ff403ea395
PODFILE CHECKSUM: 49cdbbd02c0126946dd274f37d0abe09128f8378

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"react-native-modal": "13.0.1",
"react-native-os": "1.2.6",
"react-native-pager-view": "6.1.4",
"react-native-permissions": "3.7.2",
"react-native-permissions": "5.1.0",
"react-native-print": "0.11.0",
"react-native-progress": "5.0.0",
"react-native-prompt-android": "1.1.0",
Expand Down
33 changes: 8 additions & 25 deletions src/navigation/onboarding/screens/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {NativeStackScreenProps} from '@react-navigation/native-stack';
import React, {useLayoutEffect, useRef} from 'react';
import {Platform, ScrollView} from 'react-native';
import {requestNotifications, RESULTS} from 'react-native-permissions';
import {ScrollView} from 'react-native';
import {useAndroidBackHandler} from 'react-navigation-backhandler';
import styled from 'styled-components/native';
import Button from '../../../components/button/Button';
Expand Down Expand Up @@ -86,37 +85,21 @@ const NotificationsScreen = ({
}, [navigation, t]);

const onSetNotificationsPress = async (notificationsAccepted: boolean) => {
const setAndNavigate = async (accepted: boolean) => {
const setAndNavigate = (accepted: boolean) => {
haptic('impactLight');
const systemEnabled = await AppEffects.checkNotificationsPermissions();
if (systemEnabled) {
dispatch(AppEffects.setNotifications(accepted));
dispatch(AppEffects.setConfirmTxNotifications(accepted));
dispatch(AppEffects.setAnnouncementsNotifications(accepted));
}
await askForTrackingThenNavigate(() => navigation.navigate('Pin'));
dispatch(AppEffects.setNotifications(accepted));
dispatch(AppEffects.setConfirmTxNotifications(accepted));
dispatch(AppEffects.setAnnouncementsNotifications(accepted));
askForTrackingThenNavigate(() => navigation.navigate('Pin'));
};

if (!notificationsAccepted) {
setAndNavigate(false);
return;
}

if (Platform.OS === 'ios') {
try {
const {status: updatedStatus} = await requestNotifications([
'alert',
'badge',
'sound',
]);
setAndNavigate(updatedStatus === RESULTS.GRANTED);
return;
} catch (err) {
console.error(err);
}
}

setAndNavigate(true);
const accepted = await AppEffects.requestNotificationsPermissions();
setAndNavigate(accepted);
};

return (
Expand Down
28 changes: 12 additions & 16 deletions src/navigation/tabs/settings/components/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,23 @@ const Notifications = () => {

const setNotificationValue = useCallback(
async (accepted: boolean) => {
dispatch(AppEffects.setNotifications(accepted));
dispatch(AppEffects.setConfirmTxNotifications(accepted));
dispatch(AppEffects.setAnnouncementsNotifications(accepted));
const systemEnabled = await AppEffects.checkNotificationsPermissions();
if (systemEnabled) {
dispatch(AppEffects.setNotifications(accepted));
dispatch(AppEffects.setConfirmTxNotifications(accepted));
dispatch(AppEffects.setAnnouncementsNotifications(accepted));
} else {
if (accepted && Platform.OS === 'ios') {
const requestPermissions =
await AppEffects.requestNotificationsPermissions();
if (requestPermissions) {
dispatch(AppEffects.setNotifications(accepted));
} else {
openSettings();
dispatch(AppEffects.setNotifications(false));
dispatch(AppEffects.setConfirmTxNotifications(false));
dispatch(AppEffects.setAnnouncementsNotifications(false));
if (!systemEnabled) {
if (accepted) {
if (Platform.OS === 'ios') {
const requestPermissions =
await AppEffects.requestNotificationsPermissions();
if (requestPermissions) {
return;
}
}
} else {
dispatch(AppEffects.setNotifications(false));
dispatch(AppEffects.setConfirmTxNotifications(false));
dispatch(AppEffects.setAnnouncementsNotifications(false));
openSettings();
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState} from 'react';
import React, {useState, useEffect} from 'react';
import {useTranslation} from 'react-i18next';
import {selectSettingsNotificationState} from '../../../../../store/app/app.selectors';
import {View, DeviceEventEmitter} from 'react-native';
Expand Down Expand Up @@ -89,6 +89,12 @@ const PushNotifications = () => {
},
];

useEffect(() => {
setPushNotifications(notificationsState.pushNotifications);
setAnnouncements(notificationsState.announcements);
setConfirmedTx(notificationsState.confirmedTx);
}, [notificationsState]);

return (
<SettingsContainer>
<Settings>
Expand Down
4 changes: 3 additions & 1 deletion src/store/app/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,10 @@ export const unSubscribeEmailNotifications =
};

export const checkNotificationsPermissions = async (): Promise<boolean> => {
if (Platform.OS === 'android') {
return requestNotificationsPermissions();
}
const {status} = await checkNotifications().catch(() => ({status: null}));

return status === RESULTS.GRANTED;
};

Expand Down
Loading

0 comments on commit 2ab2214

Please sign in to comment.