Skip to content

Commit a81a737

Browse files
authored
feat(react): Update React NativeScript app template (#182)
* feat(react): Update to latest dependencies, and improve starter template * chore(react): Change version caret * chore: Add "Screen" after the names of the screen-related functional components * chore: Rename Second -> Secondary
1 parent d1b2426 commit a81a737

File tree

7 files changed

+118
-105
lines changed

7 files changed

+118
-105
lines changed

packages/template-blank-react/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/template-blank-react",
3-
"version": "7.0.10",
3+
"version": "7.0.11",
44
"description": "Blank template for NativeScript apps using React.",
55
"author": "Jamie Birch <[email protected]>",
66
"main": "app.js",
@@ -33,8 +33,9 @@
3333
"@nativescript/core": "~7.1.0",
3434
"@react-navigation/core": "^5.13.2",
3535
"react": "^16.13.1",
36-
"react-nativescript": "^2.1.0",
37-
"react-nativescript-navigation": "^2.0.1"
36+
"react-nativescript": "^2.2.0",
37+
"react-nativescript-navigation": "^2.0.1",
38+
"react-refresh": "^0.8.3"
3839
},
3940
"devDependencies": {
4041
"@babel/core": "^7.4.5",
@@ -45,8 +46,7 @@
4546
"babel-loader": "8.0.6",
4647
"fork-ts-checker-webpack-plugin": "^5.1.0",
4748
"patch-package": "^6.2.2",
48-
"react-refresh": "^0.8.3",
49-
"typescript": "^3.9.3"
49+
"typescript": "~4.0.3"
5050
},
5151
"gitHead": "1350d382fb4b0ed4c6e9685df909518b2688e004",
5252
"readme": "NativeScript Application"

packages/template-blank-react/src/components/FirstScreen.tsx

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as React from "react";
2+
import { RouteProp } from '@react-navigation/core';
3+
import { Dialogs } from '@nativescript/core';
4+
import { FrameNavigationProp } from "react-nativescript-navigation";
5+
import { StyleSheet } from "react-nativescript";
6+
import { MainStackParamList } from "./NavigationParamList";
7+
8+
type HomeScreenProps = {
9+
route: RouteProp<MainStackParamList, "Home">,
10+
navigation: FrameNavigationProp<MainStackParamList, "Home">,
11+
}
12+
13+
export function HomeScreen({ navigation }: HomeScreenProps) {
14+
return (
15+
<flexboxLayout style={styles.container}>
16+
<label
17+
className="fas"
18+
style={styles.text}
19+
>
20+
&#xf135; Hello World!
21+
</label>
22+
<button
23+
style={styles.button}
24+
onTap={() => Dialogs.alert("Tapped!")}
25+
>
26+
Tap me for an alert
27+
</button>
28+
<button
29+
style={styles.button}
30+
onTap={() => navigation.navigate('Secondary')}
31+
>
32+
Go to next screen
33+
</button>
34+
</flexboxLayout>
35+
);
36+
}
37+
38+
const styles = StyleSheet.create({
39+
container: {
40+
height: "100%",
41+
flexDirection: "column",
42+
justifyContent: "center",
43+
},
44+
text: {
45+
textAlignment: "center",
46+
fontSize: 24,
47+
color: "black",
48+
},
49+
button: {
50+
fontSize: 24,
51+
color: "#2e6ddf",
52+
},
53+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export type MainStackParamList = {
2-
first: {},
3-
second: {},
2+
Home: {},
3+
Secondary: {},
44
};
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import * as React from "react";
22
import { BaseNavigationContainer } from '@react-navigation/core';
33
import { stackNavigatorFactory } from "react-nativescript-navigation";
4-
import { First } from "./FirstScreen";
5-
import { Second } from "./SecondScreen";
4+
import { HomeScreen } from "./HomeScreen";
5+
import { SecondaryScreen } from "./SecondaryScreen";
66

77
const StackNavigator = stackNavigatorFactory();
88

99
export const mainStackNavigator = () => (
1010
<BaseNavigationContainer>
1111
<StackNavigator.Navigator
12-
initialRouteName="first"
12+
initialRouteName="Home"
1313
screenOptions={{
14+
headerStyle: {
15+
backgroundColor: "white",
16+
},
1417
headerShown: true,
1518
}}
1619
>
17-
<StackNavigator.Screen name="first" component={First} />
18-
<StackNavigator.Screen name="second" component={Second} />
20+
<StackNavigator.Screen
21+
name="Home"
22+
component={HomeScreen}
23+
/>
24+
<StackNavigator.Screen
25+
name="Secondary"
26+
component={SecondaryScreen}
27+
/>
1928
</StackNavigator.Navigator>
2029
</BaseNavigationContainer>
2130
);

packages/template-blank-react/src/components/SecondScreen.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as React from "react";
2+
import { RouteProp } from '@react-navigation/core';
3+
import { FrameNavigationProp } from "react-nativescript-navigation";
4+
import { MainStackParamList } from "./NavigationParamList";
5+
import { StyleSheet } from "react-nativescript";
6+
7+
type SecondaryScreenProps = {
8+
route: RouteProp<MainStackParamList, "Secondary">,
9+
navigation: FrameNavigationProp<MainStackParamList, "Secondary">,
10+
}
11+
12+
export function SecondaryScreen({ navigation }: SecondaryScreenProps) {
13+
return (
14+
<flexboxLayout style={styles.container}>
15+
<label style={styles.text}>
16+
You're viewing the secondary screen!
17+
</label>
18+
<button
19+
style={styles.button}
20+
onTap={() => navigation.goBack()}
21+
>
22+
Go back
23+
</button>
24+
</flexboxLayout>
25+
);
26+
}
27+
28+
const styles = StyleSheet.create({
29+
container: {
30+
height: "100%",
31+
flexDirection: "column",
32+
justifyContent: "center",
33+
backgroundColor: "yellow",
34+
},
35+
text: {
36+
textAlignment: "center",
37+
fontSize: 24,
38+
color: "black",
39+
},
40+
button: {
41+
fontSize: 24,
42+
color: "#2e6ddf",
43+
},
44+
});

0 commit comments

Comments
 (0)