我是新来的react -本地,我想打开url在default browser like Chrome in Android and iPhone两个.
我们在Android中通过Intent打开url,就像我想要实现的功能一样.
我已经搜索了很多次,但它会给我Deepklinking次的搜索结果.
我是新来的react -本地,我想打开url在default browser like Chrome in Android and iPhone两个.
我们在Android中通过Intent打开url,就像我想要实现的功能一样.
我已经搜索了很多次,但它会给我Deepklinking次的搜索结果.
你应该用Linking
.
文档中的示例:
class OpenURLButton extends React.Component {
static propTypes = { url: React.PropTypes.string };
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>
);
}
}
下面是一个你可以试穿Expo Snack件的例子:
import React, { Component } from 'react';
import { View, StyleSheet, Button, Linking } from 'react-native';
import { Constants } from 'expo';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Button title="Click me" onPress={ ()=>{ Linking.openURL('https://google.com')}} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
});