React native 深度链接后返回组件
我在react native中使用了deeplinking,以便将用户重定向到youtube频道。但是当我返回到我的应用程序时,我有一个空白屏幕,我如何才能让用户返回到主屏幕 以下是我的youtube代码:React native 深度链接后返回组件,react-native,deep-linking,React Native,Deep Linking,我在react native中使用了deeplinking,以便将用户重定向到youtube频道。但是当我返回到我的应用程序时,我有一个空白屏幕,我如何才能让用户返回到主屏幕 以下是我的youtube代码: import React from 'react'; import { View, Text, Linking } from 'react-native'; import Acceuil from './Accueil'; class ChaineYT extends React.Com
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
从“React”导入React;
从“react native”导入{视图、文本、链接};
从“/Accueil”导入Accueil;
类ChaineYT扩展了React.Component{
状态={
孤岛加载:false,
我认为:错
}
componentDidMount=()=>{
Linking.openURL('vnd.youtube://'+'www.youtube.com/channel/uc1upbyfvtztdrvdjnmszsg')
此.setState(isLoading=true,IsLink=true);
if(this.state.isLoading&&this.state.isLinking){
返回此.props.navigation.navigate(“Acceuil”)
}
}
render(){
返回(
)
}
}
导出默认ChaineYT
我不确定我使用的州
编辑:我已经更新了acueil.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
``
从“React”导入React;
从“react native”导入{样式表、视图、文本输入、按钮、文本、平面列表、列表视图、链接、状态栏};
从“../Helpers/voyantesData”导入voyantes;
从“/VoyanteItem”导入VoyanteItem;
从“/MyButton2”导入MyButton2;
常数numColumns=2;
类Accueil扩展了React.Component{
_displayDetailForVoyante=(idVoyante、照片、specialite、描述、名称)=>{
控制台日志(“id为“+idVoyante”的显示胶片);
this.props.navigation.navigate(“VoyanteProfil”,{idVoyante:idVoyante,photo:photo,specialite:specialite,description:description,name:name});
}
render(){
返回(
{Linking.openURL('tel:0144017701');}}/>
{Linking.openURL('tel:3232');}}/>
item.id.toString()}
renderItem={({item})=>}
numColumns={numColumns}/>
)
}
}
const styles=StyleSheet.create({
主容器:{
弹性:1,
背景颜色:“#dfdee1”,
背景颜色:“白色”,
flexDirection:'列',
},
文本输入:{
边缘左:5,
marginRight:5,
身高:50,
边框颜色:'#000000',
边框宽度:1,
paddingLeft:5,
背景颜色:“白色”
},
按钮:{
背景颜色:“#EF3934”,
边框颜色:'#EF3934',
marginLeft:20,
marginRight:20
},
正文:{
背景颜色:“#EF3934”,
边框颜色:'#EF3934',
marginLeft:20,
marginRight:20
},
平面列表:{
弹性:1,
flexDirection:'列',
alignContent:“flex start”,
//justifyContent:“flex start”,
//alignItems:“灵活启动”
}
})
导出默认Accueil
``
我找到了解决方案:
在您的ChaineYT
中,您已在下面的行中写入:
this.setState(isLoading=true,IsLink=true);
替换为:
this.setState({isLoading:true,isLinked:true});
“Acceuil”是您的主屏幕名称?是的,当用户离开YouTubeapso时,我想返回该页面,您可以调用this.props.navigation.navigate(“Acceuil”)
<代码>返回不需要。不变冲突:不变冲突:setState(…):获取要更新的状态变量对象或返回状态变量对象的函数。我在尝试您的方式时出现此错误,因此此错误可能出现在您的“Acceuil”屏幕中。您可以从“Acceuil”屏幕发布相关代码吗?更改this.setState({isLoading=true,isLinked=true})时,我遇到了一个意外的令牌错误代码>.I正在这样做:componentDidMount=()=>{Linking.openURL('vnd.youtube://'+'www.youtube.com/channel/uc1upbyfvtztdrvdRdJnmszsg')this.setState({isLoading=true,isLinked=true});if(this.state.isLoading&&this.state.isLinking){this.props.navigation.navigation(“Acceuil”)}好吧,我发现我的错误是这样的。setState({isLoading**:*true,isLinked**:*true});但这并不能让我回到“Accueil”。当我回到我的应用程序时,我仍然有一个空白页,所以你不知道为什么?对不起,我不知道这里出了什么问题。