Files
react-native/packages/rn-tester/js/examples/PermissionsAndroid/PermissionsExample.js
T
1270873ed6 RNTester UI Redesign (#29685)
Summary:
This Pull request adds the UI changes to the RNTester app as discussed in the MLH Fellowship.

This list is not exhaustive.

- The initial App screen is redesigned.
  - A bottom Navbar has been added.
   - Filter pills are added.
   - The list card UI is updated.

- The example page UI is updated.

- Recently Viewed Sections are added. It shows the last 5 recently viewed components/APIs.

- Bookmarking functionality is added.

- The documentation URL is added to the example page.

- RNTester doesn't lose its state on a hard refresh (even on iOS).

<img width="373" src="https://user-images.githubusercontent.com/22813027/90530113-20346180-e192-11ea-8ef6-789fa25b402b.png" />
<img width="373" src="https://user-images.githubusercontent.com/22813027/90530112-20346180-e192-11ea-9539-706b540fcc5f.png" />
<img width="373" src="https://user-images.githubusercontent.com/22813027/90530100-1d397100-e192-11ea-8836-b88070643233.png" />
<img width="373" src="https://user-images.githubusercontent.com/22813027/90530110-1f9bcb00-e192-11ea-936b-64ee75fa4289.png" />

Pull Request resolved: https://github.com/facebook/react-native/pull/29685

Test Plan:
Imported from GitHub, without a `Test Plan:` line.

{F302717939}

Note: this failed **before** this diff too:

{F302745716}

Reviewed By: mdvacca, cpojer

Differential Revision: D23240434

fbshipit-source-id: 65e2766a6a097eca0e0d0fda8dadf6871e9276c2

Co-authored-by: agarwalmanya <manya18ag@gmail.com>
Co-authored-by: chirag-singhal <csinghal208@gmail.com>
Co-authored-by: Ansh Godha <ag759@cornell.edu>
Co-authored-by: Yash Kumar Verma <yk.verma2000@gmail.com>
Co-authored-by: Sanskar Jethi <sansyrox@gmail.com>
Co-authored-by: Aniketh Saha <anik220798@gmail.com>
Co-authored-by: Xtremilicious <nilarjundas@outlook.com>
Co-authored-by: Jani Evakallio <jani.evakallio@gmail.com>
2020-08-26 08:45:57 -07:00

132 lines
3.3 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
'use strict';
const React = require('react');
const {
PermissionsAndroid,
Picker,
StyleSheet,
Text,
TouchableWithoutFeedback,
View,
} = require('react-native');
const Item = Picker.Item;
class PermissionsExample extends React.Component<{...}, $FlowFixMeState> {
state = {
permission: PermissionsAndroid.PERMISSIONS.CAMERA,
hasPermission: 'Not Checked',
};
render() {
return (
<View style={styles.container}>
<Text style={styles.text}>Permission Name:</Text>
<Picker
style={styles.picker}
selectedValue={this.state.permission}
onValueChange={this._onSelectPermission.bind(this)}>
<Item
label={PermissionsAndroid.PERMISSIONS.CAMERA}
value={PermissionsAndroid.PERMISSIONS.CAMERA}
/>
<Item
label={PermissionsAndroid.PERMISSIONS.READ_CALENDAR}
value={PermissionsAndroid.PERMISSIONS.READ_CALENDAR}
/>
<Item
label={PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION}
value={PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION}
/>
</Picker>
<TouchableWithoutFeedback onPress={this._checkPermission}>
<View>
<Text style={[styles.touchable, styles.text]}>
Check Permission
</Text>
</View>
</TouchableWithoutFeedback>
<Text style={styles.text}>
Permission Status: {this.state.hasPermission}
</Text>
<TouchableWithoutFeedback onPress={this._requestPermission}>
<View>
<Text style={[styles.touchable, styles.text]}>
Request Permission
</Text>
</View>
</TouchableWithoutFeedback>
</View>
);
}
_onSelectPermission = (permission: string | number) => {
this.setState({
permission: permission,
});
};
_checkPermission = async () => {
let result = await PermissionsAndroid.check(this.state.permission);
this.setState({
hasPermission:
(result ? 'Granted' : 'Revoked') + ' for ' + this.state.permission,
});
};
_requestPermission = async () => {
let result = await PermissionsAndroid.request(this.state.permission, {
title: 'Permission Explanation',
message:
'The app needs the following permission ' +
this.state.permission +
' because of reasons. Please approve.',
});
this.setState({
hasPermission: result + ' for ' + this.state.permission,
});
};
}
exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = 'PermissionsAndroid';
exports.category = 'Android';
exports.description = 'Permissions example for API 23+.';
exports.examples = [
{
title: 'Permissions Example',
description:
'Short example of how to use the runtime permissions API introduced in Android M.',
render: (): React.Node => <PermissionsExample />,
},
];
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
text: {
margin: 10,
},
touchable: {
color: '#007AFF',
},
picker: {
flex: 1,
},
});