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

nkkqxpd9  于 2023-03-03  发布在  React
关注(0)|答案(2)|浏览(171)

我正在使用react-viro开发一个AR应用程序。在主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;

因此,当我点击主屏幕中的按钮时,我导航到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;

我想知道我怎么能通过在ViroImage上使用OnClick回到我的主屏幕。关于Github问题(https://github.com/viromedia/viro/issues/877)据说你只是做你通常会在一个普通的React原生应用程序,但我不能得到它。正如你可以想象我的话,我不是一个开发人员在所有,碰巧我的一个朋友正在写他的论文(他是一个绘图员),他请我帮他一把;也就是说,任何帮助都将不胜感激,如果需要的话,我会提供进一步的信息。

xuo3flqw

xuo3flqw1#

这是一个愚蠢的问题...只是编辑它像这样

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

然后在Piazza_Bra_AR.js中,在render(){下添加了这一行:

const { navigation } = this.props;

这样称呼它:

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

tnkciper2#

我有一个导航问题。当我导航到渲染ViroarSceneNavigator的组件时,应用程序崩溃并关闭!
App.js

'use strict';
import 'react-native-gesture-handler';
import React, {Component} from 'react';
import {Button, SafeAreaView, Text, View} from 'react-native';
import {ViroARSceneNavigator} from '@viro-community/react-viro';
import SceneAR from './SceneAR';
import {createStackNavigator} from '@react-navigation/stack';
import {NavigationContainer} from '@react-navigation/native';

const Stack = createStackNavigator();

const Scene1 = ({navigation}) => {
  return (
    <ViroARSceneNavigator
      initialScene={{
        scene: SceneAR,
        passProps: { navigation },
      }}
    />
  );
};
const Home = ({navigation}) => {
  return (
    <>
      <View>
        <Text>Vei</Text>
        <Button
          title="Test AR"
          onPress={() => navigation.navigate('Scene1')}></Button>
      </View>
    </>
  );
};
const App = () => {
  return (
    <NavigationContainer>
      <Stack.Navigator screenOptions={{headerShown: false}}>
        <Stack.Screen name="Home" component={Home} />
        <Stack.Screen name="Scene1" component={Scene1} />
      </Stack.Navigator>
    </NavigationContainer>
    // <Scene1 />
  );
};
export default App;

SceneAR.js

'use strict';
import React, {Component, useState} from 'react';
import {StyleSheet} from 'react-native';
import {
  ViroARScene,
  Viro3DObject,
  ViroAmbientLight,
  ViroARTrackingTargets,
  ViroARImageMarker,
  ViroImage,
} from '@viro-community/react-viro';

class SceneAR extends Component {

  render() {
    ViroARTrackingTargets.createTargets({
      skullImage: {
        source: require('./assets/QRcode.png'),
        orientation: 'Up',
        physicalWidth: 0.1,
        type: 'Image',
      },
    });
    const anchorFound = () => {
      console.log('Image Detected');
    };
    return (
      <ViroARScene>

        <ViroARImageMarker target="skullImage" onAnchorFound={anchorFound}>
          <ViroImage
              rotation={[-90, 0, 0]}
              scale={[0.2, 0.2, 0]}
              position={[0,0,0.2]}
              // width={0.2}
              // hight={0.001}
              source={require('./res/tracking_diffuse_2.png')}
            />

        </ViroARImageMarker>
      </ViroARScene>
    );
  }
}
export default SceneAR;

如果你能帮我解决这个问题,我将不胜感激。

相关问题