Skip to content

Commit 33a411a

Browse files
authored
Merge pull request #123 from simpleweb/navigation-fixes
Updates to react-navigation changes
2 parents 1e3aecf + 78cb74c commit 33a411a

6 files changed

Lines changed: 41 additions & 7 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
interface ReducerAction {
22
type: string;
33
}
4+
5+
type RootStackParamList = {
6+
Main: undefined;
7+
Styleguide: undefined;
8+
};
9+
10+
type Environment = "development" | "staging" | "edge" | "production" | "live";

generators/base/templates/App/Components/App/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import React from "react";
22
import { ENV } from "<%= name %>/App/Config";
33
import Environment from "<%= name %>/App/Components/Utilities/Environment";
44

5+
const environment = ENV as Environment;
6+
57
const App: React.FC = ({ children }) => (
68
<React.Fragment>
79
{children}
8-
<Environment env={ENV} />
10+
<Environment env={environment} />
911
</React.Fragment>
1012
);
1113

generators/base/templates/App/Router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createStackNavigator } from "@react-navigation/stack";
44

55
import Screens from "<%= name %>/App/Screens";
66

7-
const Stack = createStackNavigator();
7+
const Stack = createStackNavigator<RootStackParamList>();
88

99
function RootStack() {
1010
return (

generators/base/templates/App/Screens/Main.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import React from 'react';
2-
import { NavigationStackScreenComponent } from "react-navigation-stack";
2+
import { StackNavigationProp } from '@react-navigation/stack';
33
<% if (i18nSupport) { -%>
44
import { t } from "<%= name %>/App/Helpers/Translations";
55
<% } -%>
66
import Layout from '<%= name %>/App/Components/Layout';
77
import Button from '<%= name %>/App/Components/Button';
88
import Text from '<%= name %>/App/Components/Text';
99

10-
const Main: NavigationStackScreenComponent = ({ navigation }) => {
10+
type MainScreenNavigationProp = StackNavigationProp<RootStackParamList, "Main">;
11+
12+
type Props = {
13+
navigation: MainScreenNavigationProp;
14+
};
15+
16+
const Main: React.FC<Props> = ({ navigation }) => {
1117
return (
1218
<Layout.Center>
1319
<% if (i18nSupport) { -%>

generators/base/templates/App/Screens/Styleguide.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import { Alert } from "react-native";
33
import { useSelector, useDispatch } from "react-redux";
4+
import { StackNavigationProp } from "@react-navigation/stack";
45
import styled from "styled-components/native";
56
import Button from "<%= name %>/App/Components/Button";
67
import Layout from "<%= name %>/App/Components/Layout";
@@ -12,7 +13,16 @@ interface RootState {
1213
};
1314
}
1415

15-
const Styleguide: React.FC = () => {
16+
type StyleguideScreenNavigationProp = StackNavigationProp<
17+
RootStackParamList,
18+
"Styleguide"
19+
>;
20+
21+
type Props = {
22+
navigation: StyleguideScreenNavigationProp;
23+
};
24+
25+
const Styleguide: React.FC<Props> = () => {
1626
const dispatch = useDispatch();
1727
const installed = useSelector((state: RootState) => state.app.installed);
1828
const requestExample = React.useCallback(

generators/screen/templates/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import React from "react";
2-
import { NavigationStackScreenComponent } from "react-navigation-stack";
2+
import { StackNavigationProp } from "@react-navigation/stack";
33
import Layout from "<%= name %>/App/Components/Layout";
44
import Text from "<%= name %>/App/Components/Text";
55

6-
const <%= screen %>: NavigationStackScreenComponent = ({ navigation }) => {
6+
type <%= screen %>ScreenNavigationProp = StackNavigationProp<
7+
RootStackParamList,
8+
"<%= screen %>"
9+
>;
10+
11+
type Props = {
12+
navigation: <%= screen %>ScreenNavigationProp;
13+
};
14+
15+
const <%= screen %>: React.FC<Props> = ({ navigation }) => {
716
return (
817
<Layout.Center>
918
<Text><%= screen %></Text>

0 commit comments

Comments
 (0)