react-native - DeepLinking react native 后返回组件
问题描述
我在 react-native 中使用深度链接,以便将用户重定向到 youtube 频道。但是当我回到我的应用程序时,我有一个空白屏幕,我怎样才能让用户回到 homeScreen ?
这是我的 YouTube 代码:
import React from 'react';
import { View, Text, Linking } from 'react-native';
import Acceuil from './Accueil';
class ChaineYT extends React.Component {
state = {
isLoading:false,
isLinked: false
}
componentDidMount = () => {
Linking.openURL('vnd.youtube://' + 'www.youtube.com/channel/UC1UpcbyFVTZTDrvdjNmSzSg')
this.setState(isLoading=true, isLinked=true);
if(this.state.isLoading && this.state.isLinking){
return this.props.navigation.navigate("Acceuil")
}
}
render() {
return (
<View>
</View>
)
}
}
export default ChaineYT
我不确定我正在使用的状态。
编辑:我已经更新了 Accueil.js 屏幕。
import React from 'react';
import { StyleSheet, View, TextInput, Button, Text, FlatList, ListView, Linking, StatusBar } from 'react-native';
import voyantes from '../Helpers/voyantesData';
import VoyanteItem from './VoyanteItem';
import MyButton2 from './MyButton2';
const numColumns = 2;
class Accueil extends React.Component {
_displayDetailForVoyante = (idVoyante,photo, specialite, description, name) => {
console.log("Display film with id " + idVoyante);
this.props.navigation.navigate("VoyanteProfil", { idVoyante: idVoyante,photo: photo,specialite:specialite,description:description, name:name });
}
render() {
return (
<View style={styles.main_container}>
<View style={{ flexDirection:'row', justifyContent: 'space-around', marginVertical: 8 }}>
<MyButton2 style={{}} text={"Voyance privée\nouvert 24h/24\n01 44 01 77 01"} icone='icone-transfert' onPress={() => { Linking.openURL('tel:0144017701'); }}/>
<MyButton2 text={"Voyance sans CB\nouvert 24h/24\n32 32"} icone='icone-sonnerie' onPress={() => { Linking.openURL('tel:3232'); }}/>
</View>
<FlatList style={styles.flatList}
data={voyantes}
keyExtractor={(item) => item.id.toString()}
renderItem={({item}) => <VoyanteItem voyante={item} displayDetailForVoyante={this._displayDetailForVoyante} />}
numColumns={numColumns} />
</View>
)
}
}
const styles = StyleSheet.create({
main_container: {
flex: 1,
backgroundColor: '#dfdee1',
backgroundColor: 'white',
flexDirection: 'column',
},
textinput: {
marginLeft: 5,
marginRight: 5,
height: 50,
borderColor: '#000000',
borderWidth: 1,
paddingLeft: 5,
backgroundColor: 'white'
},
button: {
backgroundColor: '#EF3934',
borderColor: '#EF3934',
marginLeft: 20,
marginRight: 20
},
text: {
backgroundColor: '#EF3934',
borderColor: '#EF3934',
marginLeft: 20,
marginRight: 20
},
flatList: {
flex: 1,
flexDirection: 'column',
alignContent: 'flex-start',
//justifyContent: 'flex-start',
//alignItems: 'flex-start'
}
})
export default Accueil
``
解决方案
我找到了解决方案:
在您的ChaineYT
以下行中:
this.setState(isLoading=true, isLinked=true);
将其替换为:
this.setState({isLoading:true, isLinked:true});
推荐阅读
- php - 上传图像时“字段列表”中的未知列“数组”
- html - 在 Linux 上从命令行发送带有 ZIP 的 HTML 邮件
- json - Text()时的表情符号长度错误 - 颤动
- r - 如何在 R 中使用 ggplot2 向图形添加名称标签?
- r - 使用 aes_str 将列名作为函数参数传递
- c++ - VSCode C++ 调试器 Mac 未链接 CPP 文件
- r - 使用 dplyr 根据 R 中的特定列对数据框进行排序
- java - Java 字体是否适用于所有 unicode 代码点?
- python - cv2.imshow 不显示网络摄像头视频,也不打开任何窗口
- django - request.get:名称解析暂时失败。无法使用会话()