Skip to content

Commit f5746ac

Browse files
authored
Merge pull request #741 from Iterable/loren/embedded/MOB-12260-create-embedded-tab-in-example-app
[MOB-12260] create-embedded-tab-in-example-app
2 parents 074d64f + 733ebd3 commit f5746ac

File tree

10 files changed

+102
-1
lines changed

10 files changed

+102
-1
lines changed

example/src/components/App/App.constants.ts

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

example/src/components/App/App.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,59 @@
1+
/* eslint-disable react-native/split-platform-components */
12
import { createNativeStackNavigator } from '@react-navigation/native-stack';
3+
import { useEffect } from 'react';
4+
import { PermissionsAndroid, Platform } from 'react-native';
25

36
import { Route } from '../../constants/routes';
47
import { useIterableApp } from '../../hooks/useIterableApp';
8+
import type { RootStackParamList } from '../../types';
59
import { Login } from '../Login';
610
import { Main } from './Main';
7-
import type { RootStackParamList } from '../../types';
811

912
const Stack = createNativeStackNavigator<RootStackParamList>();
1013

14+
const requestNotificationPermission = async () => {
15+
if (Platform.OS === 'android') {
16+
const apiLevel = Platform.Version; // Get the Android API level
17+
18+
if (apiLevel >= 33) {
19+
// Check if Android 13 or higher
20+
try {
21+
const granted = await PermissionsAndroid.request(
22+
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
23+
{
24+
title: 'Notification Permission',
25+
message:
26+
'This app needs access to your notifications for push, in-app messages, embedded messages and more.',
27+
buttonNeutral: 'Ask Me Later',
28+
buttonNegative: 'Cancel',
29+
buttonPositive: 'OK',
30+
}
31+
);
32+
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
33+
console.log('Notification permission granted');
34+
} else {
35+
console.log('Notification permission denied');
36+
}
37+
} catch (err) {
38+
console.warn(err);
39+
}
40+
} else {
41+
// For Android versions below 13, notification permission is generally not required
42+
// or is automatically granted upon app installation.
43+
console.log(
44+
'Notification permission not required for this Android version.'
45+
);
46+
}
47+
}
48+
};
49+
1150
export const App = () => {
1251
const { isLoggedIn } = useIterableApp();
1352

53+
useEffect(() => {
54+
requestNotificationPermission();
55+
}, []);
56+
1457
return (
1558
<Stack.Navigator>
1659
{isLoggedIn ? (

example/src/components/App/Main.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { User } from '../User';
88
import { Inbox } from '../Inbox';
99
import { useIterableApp } from '../../hooks';
1010
import { Commerce } from '../Commerce';
11+
import { Embedded } from '../Embedded';
1112

1213
const Tab = createBottomTabNavigator<MainScreenParamList>();
1314

@@ -44,6 +45,13 @@ export const Main = () => {
4445
},
4546
})}
4647
/>
48+
<Tab.Screen
49+
name={Route.Embedded}
50+
component={Embedded}
51+
listeners={() => ({
52+
tabPress: () => setIsInboxTab(false),
53+
})}
54+
/>
4755
<Tab.Screen
4856
name={Route.Commerce}
4957
component={Commerce}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { StyleSheet } from 'react-native';
2+
import { button, buttonText, container, hr } from '../../constants';
3+
4+
const styles = StyleSheet.create({
5+
button,
6+
buttonText,
7+
container: { ...container, paddingHorizontal: 0 },
8+
embeddedSection: {
9+
display: 'flex',
10+
flexDirection: 'column',
11+
gap: 16,
12+
paddingHorizontal: 16,
13+
},
14+
hr,
15+
text: { textAlign: 'center' },
16+
utilitySection: {
17+
paddingHorizontal: 16,
18+
},
19+
});
20+
21+
export default styles;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Text, View } from 'react-native';
2+
3+
import styles from './Embedded.styles';
4+
5+
export const Embedded = () => {
6+
return (
7+
<View style={styles.container}>
8+
<Text style={styles.text}>EMBEDDED</Text>
9+
</View>
10+
);
11+
};
12+
13+
export default Embedded;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Embedded';

example/src/constants/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export enum Route {
22
Commerce = 'Commerce',
3+
Embedded = 'Embedded',
34
Inbox = 'Inbox',
45
Login = 'Login',
56
Main = 'Main',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './colors';
22
export * from './containers';
33
export * from './formElements';
4+
export * from './miscElements';
45
export * from './shadows';
56
export * from './typography';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { type ViewStyle } from 'react-native';
2+
import { colors } from './colors';
3+
4+
export const hr: ViewStyle = {
5+
backgroundColor: colors.borderPrimary,
6+
height: 1,
7+
marginVertical: 20,
8+
marginHorizontal: 0,
9+
};

example/src/types/navigation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Route } from '../constants/routes';
1010
export type MainScreenParamList = {
1111
[Route.Commerce]: undefined;
1212
[Route.Inbox]: undefined;
13+
[Route.Embedded]: undefined;
1314
[Route.User]: undefined;
1415
};
1516

0 commit comments

Comments
 (0)