我在react-native中使用深层链接,以便在用户单击按钮时将其重定向到特定的YouTube频道。
它运行良好,但是当用户使用“后退”按钮返回到应用程序时,它显示空白屏幕,我无法再将用户重定向到youtube频道。
如何每次都能使深层链接正常工作?谢谢 !
import React from 'react';
import { View, Text, Linking, Platform } from 'react-native';
class ChaineYT extends React.Component {
state = {
isLoading:false,
isLinked: false
}
componentDidMount = () => {
Linking.openURL('http://www.youtube.com/channel/UC1UpcbyFVTZTDrvdjNmSzSg');
this.setState({isLoading:true, isLinked:true});
if(this.state.isLoading && this.state.isLinked){
this.props.navigation.navigate('Acceuil')
}
}
render() {
return (
<View>
</View>
)
}
}
export default ChaineYT
如何在后台管理youtube应用?
答案 0 :(得分:0)
您将必须使用AppState
import React from 'react';
import { View, Text, Linking, Platform, AppState } from 'react-native';
class ChaineYT extends React.Component {
state = {
isLoading:false,
isLinked: false,
appState: AppState.currentState,
}
componentDidMount = () => {
Linking.openURL('http://www.youtube.com/channel/UC1UpcbyFVTZTDrvdjNmSzSg');
this.setState({isLoading:true, isLinked:true});
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === 'active'
) {
if(this.state.isLoading && this.state. isLinked){
this.props.navigation.navigate('Acceuil')
}
}
this.setState({appState: nextAppState});
};
render() {
return (
<View>
</View>
)
}
}
export default ChaineYT
答案 1 :(得分:0)
从头开始here解释了带有react-native的react-navigation v5的深层链接