react-native - react-native 的 Linking api 在 openURL() 之后没有在浏览器中打开 url
问题描述
我做了一个按钮:
<-Button onPress={() => Linking.openURL(props.albumName.url)} /->
按下按钮后,应用程序不会被重定向到新的浏览器窗口。我在 AVD 和我的 Android 手机上检查了它。参数props.albumName.url == https://www.amazon.com/Evolve-Imagine-Dragons/dp/B07143J5MM/
。其他属性(例如props.albumName.title
,props.albumName.artist
等)正在正确显示,因此语法没有问题,我还尝试注销props.albumName.url
以确认它包含正确格式的给定 url
解决方案
我猜您在按钮标签中缺少 title 属性,这是必需的道具。
我尝试了相同的代码,效果很好。
这是我的代码
import React, { Component } from 'react';
import {
View,
Linking,
Button
} from 'react-native';
export default class Button1 extends Component {
render() {
return(
<View>
<Button
title="click"
onPress={() => Linking.openURL(this.props.albumName)}/>
</View>
);
}
}
我在这里使用该组件
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
import Button1 from './Button';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>`enter code here`
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Button1 albumName = 'https://www.amazon.com/Evolve-Imagine-
Dragons/dp/B07143J5MM/' />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
推荐阅读
- reactjs - 在 ReactJS 项目中自动导入所有 *.scss
- c# - 从字符串中读取字符并计算每个字符
- javascript - 在不使用 INCLUDES 的情况下检查值是否存在于对象数组中
- terraform - 如何使用 terraform 中的 user_data 值更改 aws_instance?
- android - 错误:程序类型已存在:com.google.android.gms.internal.measurement.zzeb
- php - 将在多个字符串中找到的缩写转换为完整的单词 - PHP
- realm - Swift Realm - 'RLMException',原因:'只有由 Realm 管理的对象才支持更改'
- c# - 从带括号的字符串创建二叉树
- android - android 键盘打开时,如何通过单击按钮提交 html 表单?
- soap - 在 Axis2 + Rampart 中流式传输解密的肥皂响应