/** * 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('./RNTesterBlock'); type Props = $ReadOnly<{| url?: ?string, |}>; class OpenURLButton extends React.Component { 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 ( Open {this.props.url} ); } } class SendIntentButton extends React.Component { handleIntent = async () => { try { await Linking.sendIntent(this.props.action, this.props.extras); } catch (e) { ToastAndroid.show(e.message, ToastAndroid.LONG); } }; render() { return ( {this.props.action} ); } } class IntentAndroidExample extends React.Component { render() { return ( {Platform.OS === 'android' && ( Next one will crash if Facebook app is not installed. )} ); } } const styles = StyleSheet.create({ button: { padding: 10, backgroundColor: '#3B5998', marginBottom: 10, }, buttonIntent: { backgroundColor: '#009688', }, text: { color: 'white', }, textSeparator: { paddingBottom: 8, }, }); exports.title = 'Linking'; exports.description = 'Shows how to use Linking to open URLs.'; exports.examples = [ { title: 'Simple list of items', render: function(): React.Element { return ; }, }, ];