Skip to content

Commit

Permalink
Merge branch 'master' into 3.0.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	example/package.json
#	example/yarn.lock
#	package.json
  • Loading branch information
zoontek committed Oct 27, 2020
2 parents b5aff13 + d969b46 commit 36b661e
Show file tree
Hide file tree
Showing 57 changed files with 8,668 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
@@ -1,6 +1,6 @@
.eslintrc.js
dist/
example/
fetchWindowsCapabilites.js
mock.js

node_modules
114 changes: 111 additions & 3 deletions README.md
Expand Up @@ -2,11 +2,13 @@

[![npm version](https://badge.fury.io/js/react-native-permissions.svg)](https://badge.fury.io/js/react-native-permissions)
[![npm](https://img.shields.io/npm/dt/react-native-permissions.svg)](https://www.npmjs.org/package/react-native-permissions)
![Platform - Android and iOS](https://img.shields.io/badge/platform-Android%20%7C%20iOS-yellow.svg)
![Platform - Android, iOS and Windows](https://img.shields.io/badge/platform-Android%20%7C%20iOS%20%7C%20Windows-yellow.svg)
![MIT](https://img.shields.io/dub/l/vibe-d.svg)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

A unified permissions API for React Native on iOS and Android.
A unified permissions API for React Native on iOS, Android and Windows.

For Windows only builds 18362 and later are supported.

## Support

Expand Down Expand Up @@ -184,9 +186,13 @@ Add all wanted permissions to your app `android/app/src/main/AndroidManifest.xml
</manifest>
```

### Windows

Open the project solution file from the `windows` folder. In the app project open `Package.appxmanifest` file. From there you can select which capabilites you want your app to support.

## 🆘 Manual linking

Because this package targets React Native 0.60.0+, you probably won't need to link it manually. Otherwise if it's not the case, follow these additional instructions:
Because this package targets React Native 0.60.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:

<details>
<summary><b>👀 See manual linking instructions</b></summary>
Expand Down Expand Up @@ -242,6 +248,23 @@ public class MainApplication extends Application implements ReactApplication {
}
```

### Windows

1. In `windows/myapp.sln` add the `RNCConfig` project to your solution:

- Open the solution in Visual Studio 2019
- Right-click Solution icon in Solution Explorer > Add > Existing Project
- Select `node_modules\react-native-permissions\windows\RNPermissions\RNPermissions.vcxproj`

2. In `windows/myapp/myapp.vcxproj` ad a reference to `RNPermissions` to your main application project. From Visual Studio 2019:

- Right-click main application project > Add > Reference...
- Check `RNPermissions` from Solution Projects.

3. In `pch.h` add `#include "winrt/RNPermissions.h"`.

4. In `app.cpp` add `PackageProviders().Append(winrt::RNPermissions::ReactPackageProvider());` before `InitializeComponent();`.

</details>

## Understanding permission flow
Expand Down Expand Up @@ -348,6 +371,56 @@ As permissions are not handled in the same way on iOS and Android, this library
└─────────────────┘ └─────────────────┘
```

### Windows flow

```
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ check(PERMISSIONS.WINDOWS.WEBCAM) ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Is the feature available
on this device ?
│ ╔════╗
├───────────║ NO ║──────────────┐
│ ╚════╝ │
╔═════╗ ▼
║ YES ║ ┌─────────────────────┐
╚═════╝ │ RESULTS.UNAVAILABLE │
│ └─────────────────────┘
Is the permission
requestable ?
│ ╔════╗
├───────────║ NO ║──────────────┐
│ ╚════╝ │
╔═════╗ ▼
║ YES ║ ┌───────────────────┐
╚═════╝ │ RESULTS.BLOCKED / │
│ │ RESULTS.GRANTED │
▼ └───────────────────┘
┌────────────────┐
│ RESULTS.DENIED │
└────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ request(PERMISSIONS.WINDOWS.WEBCAM) ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Does the user accept
the request ?
│ ╔════╗
├───────────║ NO ║──────────────┐
│ ╚════╝ │
╔═════╗ ▼
║ YES ║ ┌─────────────────┐
╚═════╝ │ RESULTS.BLOCKED │
│ └─────────────────┘
┌─────────────────┐
│ RESULTS.GRANTED │
└─────────────────┘
```

## API

### Supported permissions
Expand Down Expand Up @@ -406,6 +479,38 @@ PERMISSIONS.IOS.REMINDERS;
PERMISSIONS.IOS.SIRI;
PERMISSIONS.IOS.SPEECH_RECOGNITION;
PERMISSIONS.IOS.STOREKIT;

// Windows permissions

PERMISSIONS.WINDOWS.APPOINTMENTS;
PERMISSIONS.WINDOWS.BLOCKED_CHAT_MESSAGES;
PERMISSIONS.WINDOWS.BLUETOOTH_GATT;
PERMISSIONS.WINDOWS.BLUETOOTH_RFCOMM;
PERMISSIONS.WINDOWS.CHAT;
PERMISSIONS.WINDOWS.CODE_GENERATION;
PERMISSIONS.WINDOWS.CONTACTS;
PERMISSIONS.WINDOWS.DOCUMENTS_LIBRARY;
PERMISSIONS.WINDOWS.ENTERPRISE_AUTHENTICATION;
PERMISSIONS.WINDOWS.HUMAN_INTERFACE_DEVICE;
PERMISSIONS.WINDOWS.INTERNET_CLIENT;
PERMISSIONS.WINDOWS.INTERNET_CLIENT_SERVER;
PERMISSIONS.WINDOWS.LOCATION;
PERMISSIONS.WINDOWS.MICROPHONE;
PERMISSIONS.WINDOWS.MUSIC_LIBRARY;
PERMISSIONS.WINDOWS.OBJECTS_3D;
PERMISSIONS.WINDOWS.PHONE_CALL;
PERMISSIONS.WINDOWS.PHOTO_LIBRARY;
PERMISSIONS.WINDOWS.POINT_OF_SERVICE;
PERMISSIONS.WINDOWS.PRIVATE_NETWORK_CLIENT_SERVER;
PERMISSIONS.WINDOWS.PROXIMITY;
PERMISSIONS.WINDOWS.RECORDED_CALLS_FOLDER;
PERMISSIONS.WINDOWS.REMOVABLE_STORAGE;
PERMISSIONS.WINDOWS.SHARED_USER_CERTIFICATES;
PERMISSIONS.WINDOWS.USB;
PERMISSIONS.WINDOWS.USER_ACCOUNT_INFORMATION;
PERMISSIONS.WINDOWS.VIDEOS_LIBRARY;
PERMISSIONS.WINDOWS.VOIP_CALL;
PERMISSIONS.WINDOWS.WEBCAM;
```

### Permissions statuses
Expand Down Expand Up @@ -541,6 +646,8 @@ checkNotifications().then(({status, settings}) => {

Request notifications permission status and get notifications settings values.

You cannot request notifications permissions on Windows. Disabling or enabling notifications can only be done through the App Settings.

```ts
// only used on iOS
type NotificationOption =
Expand Down Expand Up @@ -724,6 +831,7 @@ request(
Platform.select({
android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
windows: PERMISSIONS.WINDOWS.LOCATION,
}),
);
```
11 changes: 9 additions & 2 deletions example/App.tsx
Expand Up @@ -20,10 +20,14 @@ import theme from './theme';
const {SIRI, ...PERMISSIONS_IOS} = PERMISSIONS.IOS; // remove siri (certificate required)

const PLATFORM_PERMISSIONS = Platform.select<
typeof PERMISSIONS_IOS | typeof PERMISSIONS.ANDROID | {}
| typeof PERMISSIONS_IOS
| typeof PERMISSIONS.ANDROID
| typeof PERMISSIONS.WINDOWS
| {}
>({
ios: PERMISSIONS_IOS,
android: PERMISSIONS.ANDROID,
windows: PERMISSIONS.WINDOWS,
default: {},
});

Expand Down Expand Up @@ -54,7 +58,10 @@ const PermissionRow = ({
status: string;
onPress: () => void;
}) => (
<TouchableRipple onPress={onPress}>
<TouchableRipple
onPress={onPress}
accessible={true}
accessibilityLabel={`${name}:${status}`}>
<List.Item
right={() => <List.Icon color={colors[status]} icon={icons[status]} />}
title={name}
Expand Down
26 changes: 26 additions & 0 deletions example/__test__/Permissions.test.js
@@ -0,0 +1,26 @@
import {driver, By2} from 'selenium-appium';
import {until} from 'selenium-webdriver';

const setup = require('../jest-setups/jest.setup');
jest.setTimeout(50000);

beforeAll(() => {
return driver.startWithCapabilities(setup.capabilites);
});

afterAll(() => {
return driver.quit();
});

describe('Test App', () => {
test('Permissions present', async () => {
await driver.wait(
until.elementLocated(By2.nativeName('CODE_GENERATION:granted')),
);
await driver.wait(
until.elementLocated(By2.nativeName('DOCUMENTS_LIBRARY:unavailable')),
);
await driver.wait(until.elementLocated(By2.nativeName('CONTACTS:denied')));
await driver.wait(until.elementLocated(By2.nativeName('LOCATION:blocked')));
});
});
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Expand Up @@ -15,12 +15,12 @@ PODS:
- Flipper-Folly (~> 2.2)
- Flipper-RSocket (~> 1.1)
- Flipper-DoubleConversion (1.1.7)
- Flipper-Folly (2.2.0):
- Flipper-Folly (2.3.0):
- boost-for-react-native
- CocoaLibEvent (~> 1.0)
- Flipper-DoubleConversion
- Flipper-Glog
- OpenSSL-Universal (= 1.0.2.19)
- OpenSSL-Universal (= 1.0.2.20)
- Flipper-Glog (0.3.6)
- Flipper-PeerTalk (0.0.4)
- Flipper-RSocket (1.1.0):
Expand Down Expand Up @@ -67,9 +67,9 @@ PODS:
- DoubleConversion
- glog
- glog (0.3.5)
- OpenSSL-Universal (1.0.2.19):
- OpenSSL-Universal/Static (= 1.0.2.19)
- OpenSSL-Universal/Static (1.0.2.19)
- OpenSSL-Universal (1.0.2.20):
- OpenSSL-Universal/Static (= 1.0.2.20)
- OpenSSL-Universal/Static (1.0.2.20)
- Permission-AppTrackingTransparency (3.0.0-alpha.0):
- RNPermissions
- Permission-BluetoothPeripheral (3.0.0-alpha.0):
Expand Down Expand Up @@ -527,14 +527,14 @@ SPEC CHECKSUMS:
FBReactNativeSpec: 7da9338acfb98d4ef9e5536805a0704572d33c2f
Flipper: be611d4b742d8c87fbae2ca5f44603a02539e365
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
Flipper-Folly: c12092ea368353b58e992843a990a3225d4533c3
Flipper-Folly: e4493b013c02d9347d5e0cb4d128680239f6c78a
Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7
FlipperKit: ab353d41aea8aae2ea6daaf813e67496642f3d7d
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355
OpenSSL-Universal: ff34003318d5e1163e9529b08470708e389ffcdd
Permission-AppTrackingTransparency: 2b00bff16fb19fc6ddf30715c1bae4c006ddde4e
Permission-BluetoothPeripheral: b53e5a7d462a82499e4215d196e16f300d01ae40
Permission-Calendars: 077f4fbf6a706323d498faa830c2a5b8d796e33c
Expand Down
13 changes: 13 additions & 0 deletions example/jest-setups/jest.setup.js
@@ -0,0 +1,13 @@
/* eslint-disable no-undef */
import {windowsAppDriverCapabilities} from 'selenium-appium';

switch (platform) {
case 'windows':
const webViewWindowsAppId = 'PermissionsExample_nsp2ha5jnb6xr!App';
module.exports = {
capabilites: windowsAppDriverCapabilities(webViewWindowsAppId),
};
break;
default:
throw 'Unknown platform: ' + platform;
}
2 changes: 2 additions & 0 deletions example/jest-setups/jest.setup.windows.js
@@ -0,0 +1,2 @@
/* eslint-disable no-undef */
platform = 'windows';
17 changes: 17 additions & 0 deletions example/metro.config.js
@@ -1,4 +1,21 @@
const path = require('path');
const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
resolver: {
blacklistRE: blacklist([
// This stops "react-native run-windows" from causing the metro server to crash if its already running
new RegExp(
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
),
// This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip
new RegExp(
`${path
.resolve(__dirname, 'msbuild.ProjectImports.zip')
.replace(/[/\\]/g, '/')}.*`,
),
]),
},
transformer: {
getTransformOptions: async () => ({
transform: {
Expand Down
27 changes: 25 additions & 2 deletions example/package.json
Expand Up @@ -3,28 +3,51 @@
"version": "0.0.1",
"private": true,
"scripts": {
"appium": "appium",
"clean-modules": "rm -rf ./node_modules/react-native-permissions/{example,node_modules}",
"clean": "rm -rf ./node_modules ./ios/Pods",
"postinstall": "patch-package && yarn clean-modules && yarn pod-update",
"pod-update": "cd ./ios && pod update && cd ..",
"start": "react-native start",
"reinstall": "yarn clean && yarn install"
"reinstall": "yarn clean && yarn install",
"test:windows": "yarn jest --setupFiles=./jest-setups/jest.setup.windows.js"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"dependencies": {
"react": "16.13.1",
"react-native": "0.63.3",
"react-native-paper": "4.2.0",
"react-native-permissions": "../",
"react-native-vector-icons": "7.1.0"
"react-native-vector-icons": "7.1.0",
"react-native-windows": "^0.62.0-0"
},
"devDependencies": {
"@babel/core": "7.11.6",
"@babel/runtime": "7.11.2",
"@types/jest": "24.0.24",
"@types/react": "16.9.51",
"@types/react-native": "0.63.25",
"@types/react-test-renderer": "16.9.2",
"appium": "1.18.2",
"babel-jest": "24.9.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.59.0",
"patch-package": "6.2.2",
"postinstall-postinstall": "2.1.0",
"prettier": "2.0.4",
"react-test-renderer": "16.11.0",
"selenium-appium": "0.0.15",
"selenium-webdriver": "4.0.0-alpha.7",
"typescript": "4.0.3"
}
}

0 comments on commit 36b661e

Please sign in to comment.