-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
150 lines (134 loc) · 3.64 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import React, { useEffect, useState } from 'react';
import type { PropsWithChildren } from 'react';
import {
Button,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import { MedalliaDXA, MedalliaDxaCustomerConsentType } from 'dxa-react-native/src';
import crashlytics from '@react-native-firebase/crashlytics';
const Stack = createNativeStackNavigator();
const App = () => {
crashlytics().log('User signed in.');
const navigationRef = useNavigationContainerRef();
MedalliaDXA.initialize(
{
accountId: 0,
propertyId: 0,
consents: MedalliaDxaCustomerConsentType.analyticsAndTracking,
manualTracking: false,
},
navigationRef
);
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator initialRouteName="Screen1">
<Stack.Screen
name="Screen1"
component={Screen1}
options={{ title: 'Screen1' }}
/>
<Stack.Screen
name="Screen2"
component={Screen2}
options={{ title: 'Screen2' }}
/>
<Stack.Screen
name="SessionDataScreen"
component={SessionDataScreen}
options={{ title: 'SessionDataScreen' }}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
function Screen1({ navigation }: { navigation: any }) {
return (
<View>
<ScrollView>
<Button
title='Send DXA goal'
onPress={() => MedalliaDXA.sendGoal('myCustomGoal', 5)} />
<Button
title='Go to Screen 2'
onPress={() => navigation.push('Screen2')} />
<Button
title='Go to Session Data Screen'
onPress={() => navigation.push('SessionDataScreen')} />
</ScrollView>
</View>
);
}
function Screen2({ navigation }: { navigation: any }) {
return (
<View>
<ScrollView>
<Button
title='Go to Screen 1'
onPress={() => navigation.push('Screen1')} />
</ScrollView>
</View>
);
}
export function SessionDataScreen({ navigation }: { navigation: any }) {
const [sessionUrl, setSessionUrl] = useState<string>("requesting...");
const [sessionId, setSessionId] = useState<string>("requesting...");
useEffect(() => {
MedalliaDXA.getSessionUrl().then((url) => setSessionUrl(url));
MedalliaDXA.getSessionId().then((id) => setSessionId(id));
}, []);
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={styles.text}>Session url from native is:</Text>
<View style={{ height: 20 }}></View>
<Text style={styles.text}>{sessionUrl}</Text>
<View style={{ height: 20 }}></View>
<Text style={styles.text}>Session ID from native is:</Text>
<View style={{ height: 20 }}></View>
<Text style={styles.text}>{sessionId}</Text>
<Button
title="Go back"
onPress={() => navigation.pop()}
/>
</View>
);
}
const styles = StyleSheet.create({
item: {
flexDirection: 'row',
alignItems: 'center',
padding: 16,
borderBottomWidth: 1,
borderBottomColor: '#ccc',
},
image: {
width: 50,
height: 50,
marginRight: 16,
},
text: {
fontSize: 16,
color: 'black',
},
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
});
export default App;