-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
195 lines (182 loc) · 5.63 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import React, { useState, useRef, useEffect } from 'react';
import { SafeAreaView, StyleSheet, View, Text, TouchableOpacity, Animated, StatusBar } from 'react-native';
import KinestexSDK from 'kinestex-sdk-react-native';
import { IntegrationOption, PlanCategory, KinesteXSDKCamera, IPostData } from 'kinestex-sdk-react-native/src/types';
const App = () => {
const [showWebView, setShowWebView] = useState(true);
const [selectedOption, setSelectedOption] = useState<'coach' | 'ai'>('ai');
const kinestexSDKRef = useRef<KinesteXSDKCamera>(null);
const toggleWebView = (option: 'coach' | 'ai') => {
setSelectedOption(option);
setShowWebView(option === 'ai');
};
// we will use this postData for the MAIN, PLAN, AND WORKOUT Integration Option
const postDataMAIN: IPostData = {
key: 'YOUR API KEY',
userId: 'YOUR USER ID',
company: 'YOUR COMPANY NAME',
planCategory: PlanCategory.Cardio, // plan category
};
// we will use this postData for the CHALLENGE Integration Option
const postDataChallenge: IPostData = {
key: 'YOUR API KEY',
userId: 'YOUR USER ID',
company: 'YOUR COMPANY NAME',
countdown: 100, // duration of the challenge in seconds
exercise: 'Squats', // challenge exercise name
};
// we will use this postData for the CAMERA Integration Option
const postDataCamera: IPostData = {
key: 'YOUR API KEY',
userId: 'YOUR USER ID',
company: 'YOUR COMPANY NAME',
currentExercise: 'Squats', // current exercise name
exercises: ['Squats', 'Jumping Jack'] // array of expected exercises
};
// handle data from the kinestex sdk
const handleMessage = (type: string, data: { [key: string]: any }) => {
switch (type) {
case 'finished_workout':
console.log('Received data:', data);
break;
case 'kinestex_launched':
break;
case 'exit_kinestex':
console.log("User wishes to exit the app", data);
if (data.message) {
console.log('Date:', data.message);
}
setShowWebView(false);
break;
case 'error_occured':
console.log('Error occured:', data);
break;
case "plan_unlocked":
console.log('Workout plan unlocked:', data);
break;
default:
console.log('Unknown message type:', type, data);
break;
}
};
// setting another exercise for the CAMERA Integration Option
// const changeExerciseCamera = () => {
// if (kinestexSDKRef.current) {
// kinestexSDKRef.current?.changeExercise('Jumping Jack');
// }
// }
return (
<SafeAreaView style={styles.safeArea}>
<StatusBar barStyle="light-content" backgroundColor="black" />
<View style={styles.container}>
<View style={styles.navBar}>
<TouchableOpacity
style={[
styles.navButton,
selectedOption === 'ai' && styles.navButtonSelected,
]}
onPress={() => toggleWebView('ai')}
>
<Text
style={[
styles.navButtonText,
selectedOption === 'ai' && styles.navButtonTextSelected,
]}
>
AI coach
</Text>
</TouchableOpacity>
</View>
<View style={styles.content}>
{!showWebView && (
<View style={styles.blackScreen}>
<Text style={styles.blackScreenText}>Click on AI Coach to launch </Text>
</View>
)}
{showWebView && (
<View style={styles.webViewContainer}>
<View style={styles.webViewContent}>
<KinestexSDK
ref={kinestexSDKRef}
// change based on your use-case
data={postDataMAIN}
// change based on your use-case: MAIN, PLAN, WORKOUT, CHALLENGE, EXPERIENCE CAMERA
integrationOption={IntegrationOption.MAIN}
// handle data from the kinestex sdk
handleMessage={handleMessage}
// If using the PLAN Integration Option, you must specify the plan name that you want to present:
plan="Circuit Training"
// If using the WORKOUT Integration Option, you must specify the workout name that you want to present:
workout="Fitness Lite"
// IF using EXPERIENCE Integration Option, you must specify the experience name that you want to present:
experience={"box"}
/>
</View>
</View>
)}
</View>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: 'black',
},
container: {
flex: 1,
},
navBar: {
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
height: 60,
backgroundColor: 'black',
borderBottomWidth: 1,
borderBottomColor: '#ddd',
},
navButton: {
padding: 10,
},
navButtonSelected: {
backgroundColor: 'gray',
},
navButtonText: {
fontSize: 18,
color: 'gray',
},
navButtonTextSelected: {
color: 'white',
},
content: {
flex: 1,
},
blackScreen: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'black',
},
blackScreenText: {
color: 'white',
fontSize: 24,
},
webViewContainer: {
flex: 1,
},
webViewContent: {
flex: 1,
},
overlay: {
...StyleSheet.absoluteFillObject,
backgroundColor: 'black',
justifyContent: 'center',
alignItems: 'center',
},
progressBar: {
height: 10,
backgroundColor: 'blue',
},
});
export default App;