Skip to content

Commit 8c21c96

Browse files
committed
add RN navigation screens
1 parent b547fd0 commit 8c21c96

File tree

6 files changed

+634
-389
lines changed

6 files changed

+634
-389
lines changed

examples/RNOneSignalTS/App.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,34 @@
55
* @format
66
*/
77

8-
import { StatusBar, StyleSheet, useColorScheme, View } from 'react-native';
8+
import { NavigationContainer } from '@react-navigation/native';
9+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
10+
import { StatusBar, useColorScheme } from 'react-native';
911
import { SafeAreaProvider } from 'react-native-safe-area-context';
12+
import DetailsScreen from './DetailsScreen';
1013
import OSDemo from './OSDemo';
1114

15+
export type RootStackParamList = {
16+
Home: undefined;
17+
Details: undefined;
18+
};
19+
20+
const Stack = createNativeStackNavigator<RootStackParamList>();
21+
1222
function App() {
1323
const isDarkMode = useColorScheme() === 'dark';
1424

1525
return (
1626
<SafeAreaProvider>
1727
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
18-
<AppContent />
28+
<NavigationContainer>
29+
<Stack.Navigator initialRouteName="Home">
30+
<Stack.Screen name="Home" component={OSDemo} />
31+
<Stack.Screen name="Details" component={DetailsScreen} />
32+
</Stack.Navigator>
33+
</NavigationContainer>
1934
</SafeAreaProvider>
2035
);
2136
}
2237

23-
function AppContent() {
24-
return (
25-
<View style={styles.container}>
26-
<OSDemo />
27-
</View>
28-
);
29-
}
30-
31-
const styles = StyleSheet.create({
32-
container: {
33-
flex: 1,
34-
},
35-
});
36-
3738
export default App;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { NativeStackScreenProps } from '@react-navigation/native-stack';
2+
import React from 'react';
3+
import { StyleSheet, Text, View } from 'react-native';
4+
import type { RootStackParamList } from './App';
5+
6+
type Props = NativeStackScreenProps<RootStackParamList, 'Details'>;
7+
8+
const DetailsScreen: React.FC<Props> = ({ navigation }) => {
9+
return (
10+
<View style={styles.container}>
11+
<Text style={styles.title}>Details Screen</Text>
12+
<Text style={styles.text}>This is a simple extra screen.</Text>
13+
</View>
14+
);
15+
};
16+
17+
const styles = StyleSheet.create({
18+
container: {
19+
flex: 1,
20+
justifyContent: 'center',
21+
alignItems: 'center',
22+
backgroundColor: '#fff',
23+
},
24+
title: {
25+
fontSize: 24,
26+
fontWeight: 'bold',
27+
marginBottom: 16,
28+
},
29+
text: {
30+
fontSize: 16,
31+
color: '#666',
32+
},
33+
});
34+
35+
export default DetailsScreen;

examples/RNOneSignalTS/OSDemo.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NativeStackScreenProps } from '@react-navigation/native-stack';
12
import React, { useCallback, useEffect, useState } from 'react';
23
import {
34
Alert,
@@ -9,13 +10,16 @@ import {
910
View,
1011
} from 'react-native';
1112
import { LogLevel, OneSignal } from 'react-native-onesignal';
13+
import type { RootStackParamList } from './App';
1214
import { renderButtonView } from './Helpers';
1315
import OSButtons from './OSButtons';
1416
import OSConsole from './OSConsole';
1517

1618
const APP_ID = '77e32082-ea27-42e3-a898-c72e141824ef';
1719

18-
const OSDemo: React.FC = () => {
20+
type Props = NativeStackScreenProps<RootStackParamList, 'Home'>;
21+
22+
const OSDemo: React.FC<Props> = ({ navigation }) => {
1923
const [consoleValue, setConsoleValue] = useState('');
2024
const [inputValue, setInputValue] = useState('');
2125

@@ -220,6 +224,11 @@ const OSDemo: React.FC = () => {
220224
<SafeAreaView style={styles.container}>
221225
<View style={styles.header}>
222226
<Text style={styles.title}>OneSignal</Text>
227+
<View style={styles.navButton}>
228+
{renderButtonView('Go to Details', () => {
229+
navigation.navigate('Details');
230+
})}
231+
</View>
223232
<OSConsole value={consoleValue} />
224233
<View style={styles.clearButton}>
225234
{renderButtonView('X', () => {
@@ -259,6 +268,11 @@ const styles = StyleSheet.create({
259268
alignSelf: 'center',
260269
paddingVertical: 10,
261270
},
271+
navButton: {
272+
position: 'absolute',
273+
right: 0,
274+
top: 10,
275+
},
262276
clearButton: {
263277
position: 'absolute',
264278
right: 0,

0 commit comments

Comments
 (0)