Skip to content

Commit 306e692

Browse files
author
Yonah Forst
committed
breaking changes - use RN's own JS PermissionsAndroid.
1 parent dc61a04 commit 306e692

File tree

16 files changed

+228
-439
lines changed

16 files changed

+228
-439
lines changed

Example/Example.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export default class Example extends Component {
2424
}
2525

2626
componentDidMount() {
27-
let types = Permissions.getPermissionTypes()
28-
this.setState({ types })
27+
let types = Permissions.getTypes()
28+
let canOpenSettings = Permissions.canOpenSettings()
29+
30+
this.setState({ types, canOpenSettings })
2931
this._updatePermissions(types)
3032
AppState.addEventListener('change', this._handleAppStateChange.bind(this));
3133
}
@@ -47,10 +49,10 @@ export default class Example extends Component {
4749
}
4850

4951
_updatePermissions(types) {
50-
Permissions.checkMultiplePermissions(types)
52+
Permissions.checkMultiple(types)
5153
.then(status => {
5254
if (this.state.isAlways) {
53-
return Permissions.getPermissionStatus('location', 'always')
55+
return Permissions.check('location', 'always')
5456
.then(location => ({...status, location}))
5557
}
5658
return status
@@ -65,19 +67,19 @@ export default class Example extends Component {
6567
options = this.state.isAlways ? 'always' : 'whenInUse'
6668
}
6769

68-
Permissions.requestPermission(permission, options)
70+
Permissions.request(permission, options)
6971
.then(res => {
7072
this.setState({
7173
status: {...this.state.status, [permission]: res}
7274
})
7375
if (res != 'authorized') {
76+
var buttons = [{ text: 'Cancel', style: 'cancel' }]
77+
if (this.state.canOpenSettings) buttons.push({ text: 'Open Settings', onPress: this._openSettings.bind(this) })
78+
7479
Alert.alert(
7580
'Whoops!',
7681
"There was a problem getting your permission. Please enable it from settings.",
77-
[
78-
{text: 'Cancel', style: 'cancel'},
79-
{text: 'Open Settings', onPress: this._openSettings.bind(this) },
80-
]
82+
buttons
8183
)
8284
}
8385
}).catch(e => console.warn(e))
@@ -114,11 +116,15 @@ export default class Example extends Component {
114116
onPress={this._onLocationSwitchChange.bind(this)}>
115117
<Text style={styles.text}>Toggle location type</Text>
116118
</TouchableHighlight>
119+
120+
{
121+
this.state.canOpenSettings &&
122+
<TouchableHighlight
123+
onPress={this._openSettings.bind(this)}>
124+
<Text style={styles.text}>Open settings</Text>
125+
</TouchableHighlight>
126+
}
117127

118-
<TouchableHighlight
119-
onPress={this._openSettings.bind(this)}>
120-
<Text style={styles.text}>Open settings</Text>
121-
</TouchableHighlight>
122128
</View>
123129

124130

@@ -163,7 +169,7 @@ const styles = StyleSheet.create({
163169
backgroundColor: '#ef9a9a',
164170
},
165171
restricted: {
166-
backgroundColor: '#FFAB91'
172+
backgroundColor: '#ef9a9a'
167173
},
168174
footer: {
169175
padding: 10,

Example/android/app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ android {
126126
}
127127

128128
dependencies {
129-
compile project(':react-native-permissions')
130129
compile fileTree(dir: "libs", include: ["*.jar"])
131130
compile "com.android.support:appcompat-v7:23.0.1"
132131
compile "com.facebook.react:react-native:+" // From node_modules

Example/android/app/src/main/java/com/example/MainActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.example;
22

33
import com.facebook.react.ReactActivity;
4-
import com.joshblour.reactnativepermissions.ReactNativePermissionsPackage;
54

65
public class MainActivity extends ReactActivity {
76

Example/android/app/src/main/java/com/example/MainApplication.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.facebook.react.ReactNativeHost;
99
import com.facebook.react.ReactPackage;
1010
import com.facebook.react.shell.MainReactPackage;
11-
import com.joshblour.reactnativepermissions.ReactNativePermissionsPackage;
1211
import com.facebook.soloader.SoLoader;
1312

1413
import java.util.Arrays;
@@ -25,8 +24,7 @@ public boolean getUseDeveloperSupport() {
2524
@Override
2625
protected List<ReactPackage> getPackages() {
2726
return Arrays.<ReactPackage>asList(
28-
new MainReactPackage(),
29-
new ReactNativePermissionsPackage()
27+
new MainReactPackage()
3028
);
3129
}
3230
};

Example/android/settings.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
rootProject.name = 'Example'
22

33
include ':app'
4-
include ':react-native-permissions'
5-
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')

Example/ios/Example.xcodeproj/project.pbxproj

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2323
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
2424
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
25-
14902CDAB1064113A6B4C970 /* libReactNativePermissions.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B27CA08432F04FFCB0256EA1 /* libReactNativePermissions.a */; };
2625
2D02E4BC1E0B4A80006451C7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
2726
2D02E4BD1E0B4A84006451C7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
2827
2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
@@ -36,6 +35,7 @@
3635
2D02E4C91E0B4AEC006451C7 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3EA31DF850E9000B6D8A /* libReact.a */; };
3736
2DCD954D1E0B4F2C00145EB5 /* ExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* ExampleTests.m */; };
3837
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
38+
6D05A8F55CC4482AACFFC932 /* libReactNativePermissions.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DF4131A2930454297EF564B /* libReactNativePermissions.a */; };
3939
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
4040
/* End PBXBuildFile section */
4141

@@ -229,9 +229,9 @@
229229
remoteGlobalIDString = 58B5119B1A9E6C1200147676;
230230
remoteInfo = RCTText;
231231
};
232-
9D8131C41E44834800F4B1D3 /* PBXContainerItemProxy */ = {
232+
9D140CBB1F068EB400146F6C /* PBXContainerItemProxy */ = {
233233
isa = PBXContainerItemProxy;
234-
containerPortal = 8068EB7451414340B0AC0D03 /* ReactNativePermissions.xcodeproj */;
234+
containerPortal = 1CB53DB705894AAA8CB22783 /* ReactNativePermissions.xcodeproj */;
235235
proxyType = 2;
236236
remoteGlobalIDString = 9D23B34F1C767B80008B4819;
237237
remoteInfo = ReactNativePermissions;
@@ -258,13 +258,13 @@
258258
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Example/Info.plist; sourceTree = "<group>"; };
259259
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Example/main.m; sourceTree = "<group>"; };
260260
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
261+
1CB53DB705894AAA8CB22783 /* ReactNativePermissions.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = ReactNativePermissions.xcodeproj; path = "../node_modules/react-native-permissions/ReactNativePermissions.xcodeproj"; sourceTree = "<group>"; };
261262
2D02E47B1E0B4A5D006451C7 /* Example-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
262263
2D02E4901E0B4A5D006451C7 /* Example-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Example-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
264+
5DF4131A2930454297EF564B /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libReactNativePermissions.a; sourceTree = "<group>"; };
263265
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
264266
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
265-
8068EB7451414340B0AC0D03 /* ReactNativePermissions.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = ReactNativePermissions.xcodeproj; path = "../node_modules/react-native-permissions/ReactNativePermissions.xcodeproj"; sourceTree = "<group>"; };
266267
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
267-
B27CA08432F04FFCB0256EA1 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libReactNativePermissions.a; sourceTree = "<group>"; };
268268
/* End PBXFileReference section */
269269

270270
/* Begin PBXFrameworksBuildPhase section */
@@ -291,7 +291,7 @@
291291
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
292292
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
293293
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
294-
14902CDAB1064113A6B4C970 /* libReactNativePermissions.a in Frameworks */,
294+
6D05A8F55CC4482AACFFC932 /* libReactNativePermissions.a in Frameworks */,
295295
);
296296
runOnlyForDeploymentPostprocessing = 0;
297297
};
@@ -458,7 +458,7 @@
458458
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
459459
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
460460
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
461-
8068EB7451414340B0AC0D03 /* ReactNativePermissions.xcodeproj */,
461+
1CB53DB705894AAA8CB22783 /* ReactNativePermissions.xcodeproj */,
462462
);
463463
name = Libraries;
464464
sourceTree = "<group>";
@@ -495,10 +495,10 @@
495495
name = Products;
496496
sourceTree = "<group>";
497497
};
498-
9D8131A81E44834700F4B1D3 /* Products */ = {
498+
9D140C9F1F068EB400146F6C /* Products */ = {
499499
isa = PBXGroup;
500500
children = (
501-
9D8131C51E44834800F4B1D3 /* libReactNativePermissions.a */,
501+
9D140CBC1F068EB400146F6C /* libReactNativePermissions.a */,
502502
);
503503
name = Products;
504504
sourceTree = "<group>";
@@ -584,7 +584,7 @@
584584
83CBB9F71A601CBA00E9B192 /* Project object */ = {
585585
isa = PBXProject;
586586
attributes = {
587-
LastUpgradeCheck = 0820;
587+
LastUpgradeCheck = 820;
588588
ORGANIZATIONNAME = Facebook;
589589
TargetAttributes = {
590590
00E356ED1AD99517003FC87E = {
@@ -666,8 +666,8 @@
666666
ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */;
667667
},
668668
{
669-
ProductGroup = 9D8131A81E44834700F4B1D3 /* Products */;
670-
ProjectRef = 8068EB7451414340B0AC0D03 /* ReactNativePermissions.xcodeproj */;
669+
ProductGroup = 9D140C9F1F068EB400146F6C /* Products */;
670+
ProjectRef = 1CB53DB705894AAA8CB22783 /* ReactNativePermissions.xcodeproj */;
671671
},
672672
);
673673
projectRoot = "";
@@ -856,11 +856,11 @@
856856
remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */;
857857
sourceTree = BUILT_PRODUCTS_DIR;
858858
};
859-
9D8131C51E44834800F4B1D3 /* libReactNativePermissions.a */ = {
859+
9D140CBC1F068EB400146F6C /* libReactNativePermissions.a */ = {
860860
isa = PBXReferenceProxy;
861861
fileType = archive.ar;
862862
path = libReactNativePermissions.a;
863-
remoteRef = 9D8131C41E44834800F4B1D3 /* PBXContainerItemProxy */;
863+
remoteRef = 9D140CBB1F068EB400146F6C /* PBXContainerItemProxy */;
864864
sourceTree = BUILT_PRODUCTS_DIR;
865865
};
866866
/* End PBXReferenceProxy section */
@@ -1007,6 +1007,8 @@
10071007
LIBRARY_SEARCH_PATHS = (
10081008
"$(inherited)",
10091009
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1010+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1011+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
10101012
);
10111013
OTHER_LDFLAGS = (
10121014
"-ObjC",
@@ -1028,6 +1030,8 @@
10281030
LIBRARY_SEARCH_PATHS = (
10291031
"$(inherited)",
10301032
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1033+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1034+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
10311035
);
10321036
OTHER_LDFLAGS = (
10331037
"-ObjC",
@@ -1090,6 +1094,8 @@
10901094
LIBRARY_SEARCH_PATHS = (
10911095
"$(inherited)",
10921096
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1097+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1098+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
10931099
);
10941100
OTHER_LDFLAGS = (
10951101
"-ObjC",
@@ -1120,6 +1126,8 @@
11201126
LIBRARY_SEARCH_PATHS = (
11211127
"$(inherited)",
11221128
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1129+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1130+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
11231131
);
11241132
OTHER_LDFLAGS = (
11251133
"-ObjC",
@@ -1149,6 +1157,8 @@
11491157
LIBRARY_SEARCH_PATHS = (
11501158
"$(inherited)",
11511159
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1160+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1161+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
11521162
);
11531163
PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.Example-tvOSTests";
11541164
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1174,6 +1184,8 @@
11741184
LIBRARY_SEARCH_PATHS = (
11751185
"$(inherited)",
11761186
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1187+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1188+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
11771189
);
11781190
PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.Example-tvOSTests";
11791191
PRODUCT_NAME = "$(TARGET_NAME)";

Example/ios/Example/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
<string>test</string>
5252
<key>NSRemindersUsageDescription</key>
5353
<string>test</string>
54+
<key>NSSpeechRecognitionUsageDescription</key>
55+
<string>test</string>
5456
<key>UIBackgroundModes</key>
5557
<array>
5658
<string>bluetooth-peripheral</string>

0 commit comments

Comments
 (0)