当我单击 URL(适用于 iOS 和 Android)时,我尝试在不离开应用程序的情况下打开浏览器窗口。
行为应如下(以airbnb应用程序为例):
- 点击“条款和条件”链接:链接示例 https://i.stack.imgur.com/4esEA.png
- 在应用程序内打开浏览器:
- 对于 iOS:iOS 应用内浏览器 https://i.stack.imgur.com/gCwSK.png
- 安卓也一样。
我怎样才能做到这一点?我需要使用任何指定的现有库吗?
我正在使用react-native 0.37。
您可以使用新的React Native 的 InAppBrowser 插件 https://github.com/proyecto26/react-native-inappbrowser,检查下一个示例:
import { Linking } from 'react-native'
import InAppBrowser from 'react-native-inappbrowser-reborn';
...
async openLink() {
try {
const isAvailable = await InAppBrowser.isAvailable()
const url = 'https://www.google.com'
if (isAvailable) {
InAppBrowser.open(url, {
// iOS Properties
dismissButtonStyle: 'cancel',
preferredBarTintColor: 'gray',
preferredControlTintColor: 'white',
// Android Properties
showTitle: true,
toolbarColor: '#6200EE',
secondaryToolbarColor: 'black',
enableUrlBarHiding: true,
enableDefaultShare: true,
forceCloseOnRedirection: true,
}).then((result) => {
Alert.alert(JSON.stringify(result))
})
} else Linking.openURL(url)
} catch (error) {
Alert.alert(error.message)
}
}
...
另一方面,您可以通过深度链接使用此插件,请查看项目的自述文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)