简体   繁体   English

使用 react-navigation/native 返回 Home 堆栈

[英]Going back to Home stack with react-navigation/native

I'm using react-viro to develop an AR app.我正在使用 react-viro 开发 AR 应用程序。 In the main app.js i have the following code:在主 app.js 中,我有以下代码:

var arScenes = {
  'Campidoglio_AR': require('./js/Campidoglio_AR/Campidoglio_AR'),
  'Piazza_Bra_AR': require('./js/Piazza_Bra_AR/Piazza_Bra_AR'),
}

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Questa è la schermata iniziale</Text>
      <Text>Premi il bottone sottostante per visitare Piazza Bra</Text>
      <Button
        title="Piazza Bra"
        onPress={() => navigation.navigate('Piazza Bra')}
      />
  );
}

function Piazza_Bra_AR({ navigation }) {
  return (
    <ViroARSceneNavigator
      initialScene={{
        scene: arScenes['Piazza_Bra_AR'],
      }} />
    );
}

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Home">
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen options={{headerShown: false}} name="Piazza Bra" component={Piazza_Bra_AR} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

so when i click on the button in the home screen i navigate to Piazza_Bra_AR.js that looks like this:所以当我点击主屏幕中的按钮时,我导航到 Piazza_Bra_AR.js,如下所示:

export default class Piazza_Bra_AR_Scene extends React.Component {
  constructor() {
    super();

    this.state = {
      showSceneItems : false,
    }

    this._getInfoControls = this._getInfoControls.bind(this);
    this._onBackClick = this._onBackClick.bind(this);
    this._onBackgroundPhotoLoadEnd = this._onBackgroundPhotoLoadEnd.bind(this);
  }

  render() {
    return (
      <ViroARScene style={styles.container}>
      <ViroSkyBox source={{
                 nx:require('./res/Skybox/negx.png'),
                 px:require('./res/Skybox/posx.png'),
                 ny:require('./res/Skybox/negy.png'),
                 py:require('./res/Skybox/posy.png'),
                 nz:require('./res/Skybox/negz.png'),
                 pz:require('./res/Skybox/posz.png')}}
                 onLoadEnd={this._onBackgroundPhotoLoadEnd}/>

        <LoadingSpinner visible={!this.state.showSceneItems} position={[0, 0, -5]}/>
        <ViroImage source={nastro_azzurro} onClick={() => navigation.navigate('Home')} /> //here i want to navigate 
        {this._getInfoControls()}

      </ViroARScene>
    );
 }

  _getInfoControls() {
    return (
      <ViroNode
        opacity={0}
        animation={{
          name : "fadeIn",
          run : this.state.showSceneItems,
          loop : false,
        }} >

        <InfoElement url={arena_url} tipo_struttura={monumento} content={arena} event_content={event_arena} contentCardScale={[1,1,1]} position={polarToCartesian([-5, 220, -15])}/>
        <InfoElement url={initimissimi_url} tipo_struttura={negozio} content={intimissimi} event_content={event_intimissimi} contentCardScale={[1,1,1]} position={polarToCartesian([-8, 184, -5])}/>
        <InfoElement url={lv_url} tipo_struttura={negozio} content={lv} contentCardScale={[1,1,1]} event_content={event_lv} position={polarToCartesian([-7, 170, -5])}/>
        <InfoElement url={cinema_rivoli_url} tipo_struttura={tempo_libero} content={cinema_rivoli} event_content={event_cinema_rivoli} contentCardScale={[1,1,1]} position={polarToCartesian([-6, 62, -5])}/>
        <InfoElement url={piazza_url} tipo_struttura={tempo_libero} content={piazza} contentCardScale={[1,1,1]} event_content={event_piazza} position={polarToCartesian([-6, -23, -5])}/>
        <InfoElement url={comune_url} tipo_struttura={monumento} content={comune} contentCardScale={[1.5,1.5,1.5]} event_content={event_comune} position={polarToCartesian([-7, -65, -10])}/>
      </ViroNode>
    );
  }
  _onBackgroundPhotoLoadEnd() {
    this.setState({
      showSceneItems:true
    });
  }
}

module.exports = Piazza_Bra_AR_Scene;

i was wondering how could i go back to my home screen by using an OnClick on a ViroImage.我想知道如何通过在 ViroImage 上使用 OnClick 返回到我的主屏幕。 On a github issue ( https://github.com/viromedia/viro/issues/877 ) it's said that u just do how u normally would on a plain react-native app but i can't get to it.在 github 问题 ( https://github.com/viromedia/viro/issues/877 ) 上,据说你只是在普通的 react-native 应用程序上做你通常会做的事情,但我无法做到。 As u can imagine for my words i'm not a developer at all, it just happens that a friend of mine that is working on his thesis (he is a graphic) ask'd me to help him out;正如你可以想象的那样,我根本不是开发人员,碰巧我的一个朋友正在写他的论文(他是一个图形)要求我帮助他; that said any help would be really appreciated and i'll provide further information if neeeded.这就是说任何帮助将不胜感激,如果需要,我会提供更多信息。

NVM that was a stupid question... just edited it like this NVM 这是一个愚蠢的问题......只是像这样编辑它

function Piazza_Bra_AR({ navigation }) {
  return (
    <ViroARSceneNavigator
      initialScene={{
        scene: arScenes['Piazza_Bra_AR'],
        passProps: { navigation },
      }} />
    );
}

and then in the Piazza_Bra_AR.js added this line just under render(){ :然后在 Piazza_Bra_AR.js 中,在render(){下添加了这一行:

const { navigation } = this.props;

to call it like this:像这样称呼它:

onClick={() => navigation.navigate('Screen_name')}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 禁用使用react-navigation返回react-native - Disable going back in react-native using react-navigation 从嵌套导航返回时 React-navigation 崩溃 - React-navigation crash when going back from a nested navigation 在 react native @react-navigation/native-stack 错误发生 - In react native @react-navigation/native-stack error occured @react-navigation/stack 与 @react-navigation/native-stack 有什么区别? - What is the difference between @react-navigation/stack vs @react-navigation/native-stack? @react-navigation/native 和@react-navigation/stack 读取整个堆栈 - @react-navigation/native and @react-navigation/stack read whole stack 反应导航中的反应原生android后退按钮 - React-native android back button in react-navigation 如何在 React-navigation/react-native 中隐藏后退按钮 - how to hide back button in React-navigation/react-native 突然没有任何返回动画(React Native,React-Navigation) - Suddenly not getting any back animations (React Native, React-Navigation) “在‘​​@react-navigation/native-stack’中找不到导出‘createStackNavigator’ - "export 'createStackNavigator' was not found in '@react-navigation/native-stack' react-navigation 6 的本机堆栈找不到路由 object - native-stack of react-navigation 6 does not find a route object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM