Files
react-native/packages/rn-tester/js/examples/Linking/LinkingExample.js
T
Ankit Tiwari 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

131 lines
3.2 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
*/
'use strict';
const React = require('react');
const {
Linking,
Platform,
StyleSheet,
Text,
TouchableOpacity,
ToastAndroid,
View,
} = require('react-native');
const RNTesterBlock = require('../../components/RNTesterBlock');
type Props = $ReadOnly<{|
url?: ?string,
|}>;
class OpenURLButton extends React.Component<Props> {
handleClick = () => {
Linking.canOpenURL(this.props.url).then(supported => {
if (supported) {
Linking.openURL(this.props.url);
} else {
console.log("Don't know how to open URI: " + this.props.url);
}
});
};
render() {
return (
<TouchableOpacity onPress={this.handleClick}>
<View style={styles.button}>
<Text style={styles.text}>Open {this.props.url}</Text>
</View>
</TouchableOpacity>
);
}
}
class SendIntentButton extends React.Component<Props> {
handleIntent = async () => {
try {
await Linking.sendIntent(this.props.action, this.props.extras);
} catch (e) {
ToastAndroid.show(e.message, ToastAndroid.LONG);
}
};
render() {
return (
<TouchableOpacity onPress={this.handleIntent}>
<View style={[styles.button, styles.buttonIntent]}>
<Text style={styles.text}>{this.props.action}</Text>
</View>
</TouchableOpacity>
);
}
}
class IntentAndroidExample extends React.Component {
render() {
return (
<View>
<RNTesterBlock title="Open external URLs">
<OpenURLButton url={'https://www.facebook.com'} />
<OpenURLButton url={'http://www.facebook.com'} />
<OpenURLButton url={'http://facebook.com'} />
<OpenURLButton url={'fb://notifications'} />
<OpenURLButton url={'geo:37.484847,-122.148386'} />
<OpenURLButton url={'tel:9876543210'} />
</RNTesterBlock>
{Platform.OS === 'android' && (
<RNTesterBlock title="Send intents">
<SendIntentButton action="android.intent.action.POWER_USAGE_SUMMARY" />
<Text style={styles.textSeparator}>
Next one will crash if Facebook app is not installed.
</Text>
<SendIntentButton
action="android.settings.APP_NOTIFICATION_SETTINGS"
extras={[
{'android.provider.extra.APP_PACKAGE': 'com.facebook.katana'},
]}
/>
</RNTesterBlock>
)}
</View>
);
}
}
const styles = StyleSheet.create({
button: {
padding: 10,
backgroundColor: '#3B5998',
marginBottom: 10,
},
buttonIntent: {
backgroundColor: '#009688',
},
text: {
color: 'white',
},
textSeparator: {
paddingBottom: 8,
},
});
exports.title = 'Linking';
exports.category = 'Basic';
exports.documentationURL = 'https://reactnative.dev/docs/linking';
exports.description = 'Shows how to use Linking to open URLs.';
exports.examples = [
{
title: 'Simple list of items',
render: function(): React.Element<typeof IntentAndroidExample> {
return <IntentAndroidExample />;
},
},
];