Skip to content

Commit 3347278

Browse files
authored
3.9.0 (#803)
1 parent a836e11 commit 3347278

File tree

13 files changed

+222
-155
lines changed

13 files changed

+222
-155
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.eslintrc.js
22
dist/
33
example/
4+
scripts/
45
fetchWindowsCapabilites.js
56
mock.js
67
node_modules

README.md

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,72 @@ $ yarn add react-native-permissions
2626

2727
### iOS
2828

29-
By default no permission handler is linked. To add one, update your `package.json` by adding the permissions used in your app, then run `npx react-native setup-ios-permissions` followed by `pod install` (`reactNativePermissionsIOS.json` is also supported).
30-
31-
_📌  Note that these commands must be re-executed each time you update this config, delete the `node_modules` directory or update this library. An useful trick to cover a lot of these cases is running them on `postinstall` and just run `yarn` or `npm install` manually when needed._
32-
33-
```json
34-
{
35-
"reactNativePermissionsIOS": [
36-
"AppTrackingTransparency",
37-
"BluetoothPeripheral",
38-
"Calendars",
39-
"Camera",
40-
"Contacts",
41-
"FaceID",
42-
"LocationAccuracy",
43-
"LocationAlways",
44-
"LocationWhenInUse",
45-
"MediaLibrary",
46-
"Microphone",
47-
"Motion",
48-
"Notifications",
49-
"PhotoLibrary",
50-
"PhotoLibraryAddOnly",
51-
"Reminders",
52-
"Siri",
53-
"SpeechRecognition",
54-
"StoreKit"
55-
],
56-
"devDependencies": {
57-
"pod-install": "0.1.38"
58-
},
59-
"scripts": {
60-
"postinstall": "react-native setup-ios-permissions && pod-install"
61-
}
62-
}
63-
```
64-
65-
Then update your `Info.plist` with wanted permissions usage descriptions:
29+
1. By default, no permissions are setuped. So first, require the `setup` script in your `Podfile`:
30+
31+
```diff
32+
# with react-native >= 0.72
33+
- # Resolve react_native_pods.rb with node to allow for hoisting
34+
- require Pod::Executable.execute_command('node', ['-p',
35+
- 'require.resolve(
36+
- "react-native/scripts/react_native_pods.rb",
37+
- {paths: [process.argv[1]]},
38+
- )', __dir__]).strip
39+
40+
+ def node_require(script)
41+
+ # Resolve script with node to allow for hoisting
42+
+ require Pod::Executable.execute_command('node', ['-p',
43+
+ "require.resolve(
44+
+ '#{script}',
45+
+ {paths: [process.argv[1]]},
46+
+ )", __dir__]).strip
47+
+ end
48+
49+
+ node_require('react-native/scripts/react_native_pods.rb')
50+
+ node_require('react-native-permissions/scripts/setup.rb')
51+
```
52+
53+
```diff
54+
# with react-native < 0.72
55+
require_relative '../node_modules/react-native/scripts/react_native_pods'
56+
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
57+
+ require_relative '../node_modules/react-native-permissions/scripts/setup'
58+
```
59+
60+
2. Then in the same file, add a `setup_permissions` call with the wanted permissions:
61+
62+
```ruby
63+
#
64+
65+
platform :ios, min_ios_version_supported
66+
prepare_react_native_project!
67+
68+
# ⬇️ uncomment wanted permissions (don't forget to remove the last comma)
69+
setup_permissions([
70+
# 'AppTrackingTransparency',
71+
# 'BluetoothPeripheral',
72+
# 'Calendars',
73+
# 'Camera',
74+
# 'Contacts',
75+
# 'FaceID',
76+
# 'LocationAccuracy',
77+
# 'LocationAlways',
78+
# 'LocationWhenInUse',
79+
# 'MediaLibrary',
80+
# 'Microphone',
81+
# 'Motion',
82+
# 'Notifications',
83+
# 'PhotoLibrary',
84+
# 'PhotoLibraryAddOnly',
85+
# 'Reminders',
86+
# 'SpeechRecognition',
87+
# 'StoreKit'
88+
])
89+
90+
#
91+
```
92+
93+
3. Then execute `pod install` _(📌  Note that it must be re-executed each time you update this config)_.
94+
4. Finally, update your `Info.plist` with the wanted permissions usage descriptions:
6695

6796
```xml
6897
<?xml version="1.0" encoding="UTF-8"?>
@@ -181,7 +210,7 @@ Open the project solution file from the `windows` folder. In the app project ope
181210

182211
## 🆘 Manual linking
183212

184-
Because this package targets React Native 0.63.0+, you probably won't need to link it manually. Otherwise if it's not the case, follow these additional instructions. You also need to manual link the module on Windows when using React Native Windows prior to 0.63:
213+
Because this package targets recent React Native versions, you probably don't need to link it manually. But if you have a special case, follow these additional instructions:
185214

186215
<details>
187216
<summary><b>👀 See manual linking instructions</b></summary>
@@ -707,7 +736,7 @@ check(PERMISSIONS.IOS.LOCATION_ALWAYS)
707736

708737
Request one permission.
709738

710-
Note that the `rationale` parameter is only available and used on Android.
739+
The `rationale` is only available and used on Android. It can be a native alert (a `Rationale` object) or a custom implementation (that resolves with a `boolean`).
711740

712741
```ts
713742
type Rationale = {
@@ -718,7 +747,10 @@ type Rationale = {
718747
buttonNeutral?: string;
719748
};
720749

721-
function request(permission: string, rationale?: Rationale): Promise<PermissionStatus>;
750+
function request(
751+
permission: string,
752+
rationale?: Rationale | (() => Promise<boolean>),
753+
): Promise<PermissionStatus>;
722754
```
723755

724756
```js

example/ios/Podfile

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
# Resolve react_native_pods.rb with node to allow for hoisting
2-
require Pod::Executable.execute_command('node', ['-p',
3-
'require.resolve(
4-
"react-native/scripts/react_native_pods.rb",
5-
{paths: [process.argv[1]]},
6-
)', __dir__]).strip
1+
def node_require(script)
2+
# Resolve script with node to allow for hoisting
3+
require Pod::Executable.execute_command('node', ['-p',
4+
"require.resolve(
5+
'#{script}',
6+
{paths: [process.argv[1]]},
7+
)", __dir__]).strip
8+
end
9+
10+
node_require('react-native/scripts/react_native_pods.rb')
11+
node_require('react-native-permissions/scripts/setup.rb')
712

813
platform :ios, min_ios_version_supported
914
prepare_react_native_project!
1015

16+
setup_permissions([
17+
'AppTrackingTransparency',
18+
'BluetoothPeripheral',
19+
'Calendars',
20+
'Camera',
21+
'Contacts',
22+
'FaceID',
23+
'LocationAccuracy',
24+
'LocationAlways',
25+
'LocationWhenInUse',
26+
'MediaLibrary',
27+
'Microphone',
28+
'Motion',
29+
'Notifications',
30+
'PhotoLibrary',
31+
'PhotoLibraryAddOnly',
32+
'Reminders',
33+
'SpeechRecognition',
34+
'StoreKit'
35+
])
36+
1137
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
1238
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
1339
#

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ PODS:
487487
- React-jsi (= 0.72.4)
488488
- React-logger (= 0.72.4)
489489
- React-perflogger (= 0.72.4)
490-
- RNPermissions (3.8.4):
490+
- RNPermissions (3.9.0):
491491
- React-Core
492492
- RNVectorIcons (10.0.0):
493493
- React-Core
@@ -720,12 +720,12 @@ SPEC CHECKSUMS:
720720
React-runtimescheduler: 4941cc1b3cf08b792fbf666342c9fc95f1969035
721721
React-utils: b79f2411931f9d3ea5781404dcbb2fa8a837e13a
722722
ReactCommon: 4b2bdcb50a3543e1c2b2849ad44533686610826d
723-
RNPermissions: ed00174a2d6efeff72f32af33332b28f64918e7c
723+
RNPermissions: 535ef85ad2e77d65bc90ee2afcb734619cea6f56
724724
RNVectorIcons: 8b5bb0fa61d54cd2020af4f24a51841ce365c7e9
725725
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
726726
Yoga: 3efc43e0d48686ce2e8c60f99d4e6bd349aff981
727727
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
728728

729-
PODFILE CHECKSUM: fff8f587e10e262f18b440ce402f9b16a0fcafda
729+
PODFILE CHECKSUM: d10907374d33d217871dd1ac7944e625d6d03f6c
730730

731731
COCOAPODS: 1.12.1

example/package.json

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,10 @@
99
"clean-modules": "rm -rf ./node_modules/react-native-permissions/{example,node_modules}",
1010
"clean": "rm -rf ./node_modules ./ios/Pods",
1111
"preinstall": "cd .. && yarn prepack && cd example",
12-
"postinstall": "yarn clean-modules && react-native setup-ios-permissions && pod-install",
12+
"postinstall": "yarn clean-modules && pod-install",
1313
"start": "react-native start",
1414
"reinstall": "yarn clean && yarn install"
1515
},
16-
"reactNativePermissionsIOS": [
17-
"AppTrackingTransparency",
18-
"BluetoothPeripheral",
19-
"Calendars",
20-
"Camera",
21-
"Contacts",
22-
"FaceID",
23-
"LocationAccuracy",
24-
"LocationAlways",
25-
"LocationWhenInUse",
26-
"MediaLibrary",
27-
"Microphone",
28-
"Motion",
29-
"Notifications",
30-
"PhotoLibrary",
31-
"PhotoLibraryAddOnly",
32-
"Reminders",
33-
"SpeechRecognition",
34-
"StoreKit"
35-
],
3616
"dependencies": {
3717
"react": "18.2.0",
3818
"react-native": "0.72.4",

example/yarn.lock

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,13 +4621,6 @@ pkg-dir@^3.0.0:
46214621
dependencies:
46224622
find-up "^3.0.0"
46234623

4624-
pkg-dir@^5.0.0:
4625-
version "5.0.0"
4626-
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-5.0.0.tgz#a02d6aebe6ba133a928f74aec20bafdfe6b8e760"
4627-
integrity sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==
4628-
dependencies:
4629-
find-up "^5.0.0"
4630-
46314624
46324625
version "0.1.39"
46334626
resolved "https://registry.yarnpkg.com/pod-install/-/pod-install-0.1.39.tgz#853a0585bafbd332c2ca6543854fd4919958cfb3"
@@ -4740,9 +4733,6 @@ react-native-paper@^5.10.3:
47404733

47414734
react-native-permissions@../:
47424735
version "3.8.4"
4743-
dependencies:
4744-
picocolors "^1.0.0"
4745-
pkg-dir "^5.0.0"
47464736

47474737
react-native-safe-area-context@^4.7.1:
47484738
version "4.7.1"

ios/RNPermissionsModule.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ - (NSDictionary *)constantsToExport {
201201
NSMutableString *message = [NSMutableString new];
202202

203203
[message appendString:@"⚠ No permission handler detected.\n\n"];
204-
[message appendString:@"• Check that you added at least one permission handler in your package.json reactNativePermissionsIOS config.\n"];
204+
[message appendString:@"• Check that you are correctly calling setup_permissions in your Podfile.\n"];
205205
[message appendString:@"• Uninstall this app, reinstall your Pods, delete your Xcode DerivedData folder and rebuild it.\n"];
206206

207207
RCTLogError(@"%@", message);

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-permissions",
3-
"version": "3.8.4",
3+
"version": "3.9.0",
44
"license": "MIT",
55
"description": "An unified permissions API for React Native on iOS, Android and Windows",
66
"author": "Mathieu Acthernoene <[email protected]>",
@@ -25,6 +25,7 @@
2525
"!/android/build",
2626
"/dist",
2727
"/ios",
28+
"/scripts",
2829
"/windows",
2930
"/src",
3031
"/*.podspec",
@@ -33,7 +34,7 @@
3334
],
3435
"scripts": {
3536
"format": "prettier '**/*' -u -w",
36-
"lint": "eslint \"./**/*.{js,ts,tsx}\"",
37+
"lint": "eslint './**/*.{js,ts,tsx}'",
3738
"setup-hooks": "git config --local core.hooksPath .hooks",
3839
"prepack": "bob build",
3940
"typecheck": "tsc --project ./ --noEmit"
@@ -69,10 +70,6 @@
6970
"optional": true
7071
}
7172
},
72-
"dependencies": {
73-
"picocolors": "^1.0.0",
74-
"pkg-dir": "^5.0.0"
75-
},
7673
"devDependencies": {
7774
"@types/react": "^18.2.21",
7875
"@typescript-eslint/eslint-plugin": "^6.4.1",

0 commit comments

Comments
 (0)