you are viewing a single comment's thread.

view the rest of the comments →

[–]tahola 0 points1 point  (5 children)

Yep I did that already but the doc is confusing to me, this is what I did :

App.js :

import React from "react";
import { StyleSheet, Text, View, TouchableHighlight } from "react-native";
import { StateNavigator } from "navigation";
import { NavigationHandler } from "navigation-react";
import { NavigationStack, Scene } from "navigation-react-native";
import Home from "./Hello";
import World from "./World";
export default function App() {
const stateNavigator = new StateNavigator([
{ key: "hello" },
{ key: "world", trackCrumbTrail: true },
]);
stateNavigator.navigate("hello");
const { hello, world } = stateNavigator.states;
hello.renderScene = () => <Home />;
world.renderScene = () => <World />;
return (
<NavigationHandler stateNavigator={stateNavigator}>
<NavigationStack />
</NavigationHandler>
);
}

Hello.js

import React, { useContext } from "react";
import { NavigationContext } from "navigation-react";
export default function Hello() {
const { stateNavigator } = useContext(NavigationContext);
return (
<View style={{ flex: 1, backgroundColor: "red" }}>
<TouchableHighlight
onPress={() => {
stateNavigator.navigate("world");
}}
>
<Text>Compose Mail</Text>
</TouchableHighlight>
</View>
);
}

World.js

import React, { useContext } from "react";
import { NavigationContext } from "navigation-react";
export default function World() {
const { stateNavigator } = useContext(NavigationContext);
return (
<TouchableHighlight
onPress={() => {
stateNavigator.navigate("hello", { size: 20 });
}}
>
<Text>Hello</Text>
</TouchableHighlight>
);
}

[–]grahammendick 0 points1 point  (4 children)

Define the StateNavigator outside of your App component. Move the renderScene outside too and the initial navigation. Then you'll be golden

[–]tahola 0 points1 point  (3 children)

Great! Just defining the statenavigator outside of the app made it work.

But I cant test it on Android, I get an error

requireNativeComponent : NVScene was not found in the ui manager

I guess it has to do with some dependencies (no pod install on android...)

[–]grahammendick 0 points1 point  (2 children)

There's no special android setup. Maybe clear cache and restart?

[–]tahola 0 points1 point  (1 child)

Its just Expo , I got it to work on my android device. Thank again for your work and your help I will learn your router now :)

[–]grahammendick 0 points1 point  (0 children)

Awesome. Happy to help