Skip to content

Commit 6ebec60

Browse files
Update HyperTrack SDK React Native to 14.0.0 (#44)
1 parent 0d88363 commit 6ebec60

File tree

6 files changed

+1962
-2035
lines changed

6 files changed

+1962
-2035
lines changed

ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ PODS:
1414
- hermes-engine (0.72.17):
1515
- hermes-engine/Pre-built (= 0.72.17)
1616
- hermes-engine/Pre-built (0.72.17)
17-
- HyperTrack (5.10.0)
18-
- hypertrack-sdk-react-native (13.8.0):
19-
- HyperTrack (= 5.10.0)
17+
- HyperTrack (5.11.0)
18+
- hypertrack-sdk-react-native (14.0.0):
19+
- HyperTrack (= 5.11.0)
2020
- React-Core
2121
- libevent (2.1.12)
2222
- RCT-Folly (2021.07.22.00):
@@ -578,8 +578,8 @@ SPEC CHECKSUMS:
578578
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
579579
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
580580
hermes-engine: 982096772bd947125ee3b4f72ace6cb9a33f1d02
581-
HyperTrack: d6dd275a8e067e7c81859fc73edc095c981813d5
582-
hypertrack-sdk-react-native: 69689d816e499fab7bc73fd1076696ad491236aa
581+
HyperTrack: aa6f271e6f9b1339790667c20e281e470531cc21
582+
hypertrack-sdk-react-native: 43c21686055bd0336c0573728515a5dd1993882d
583583
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
584584
RCT-Folly: 8dc08ca5a393b48b1c523ab6220dfdcc0fe000ad
585585
RCTRequired: 01c639ec840ee03928b2d65f5cd5297d737b3834

ios/QuickstartReactNative.xcodeproj/xcshareddata/xcschemes/QuickstartReactNative.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</BuildableProductRunnable>
6363
</LaunchAction>
6464
<ProfileAction
65-
buildConfiguration = "Release"
65+
buildConfiguration = "Debug"
6666
shouldUseLaunchSchemeArgsEnv = "YES"
6767
savedToolIdentifier = ""
6868
useCustomWorkingDirectory = "NO"

justfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
alias a := add-plugin
22
alias al := add-plugin-local
33
alias ap := add-plugin
4-
alias c := compile
4+
alias c := clean
5+
alias cm := compile
56
alias cn := clear-nm
67
alias epn := extract-plugin-nm
78
alias ogp := open-github-prs
89
alias oi := open-ios
910
alias pi := pod-install
1011
alias ra := run-android
12+
alias s := setup
1113
alias sm := start-metro
1214
alias us := update-sdk
1315
alias v := version
@@ -79,6 +81,9 @@ add-plugin-local: hooks
7981

8082
just pod-install
8183

84+
clean:
85+
just clear-nm
86+
8287
clear-nm: hooks
8388
rm -rf node_modules
8489
rm yarn.lock
@@ -112,6 +117,10 @@ pod-install:
112117
run-android: hooks compile
113118
npx react-native run-android
114119

120+
setup: hooks
121+
yarn
122+
just pi
123+
115124
start-metro: hooks compile
116125
npx react-native start
117126

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"test": "jest"
1111
},
1212
"dependencies": {
13-
"hypertrack-sdk-react-native": "13.8.0",
14-
"hypertrack-sdk-react-native-plugin-android-activity-service-google": "13.8.0",
15-
"hypertrack-sdk-react-native-plugin-android-location-services-google": "13.8.0",
16-
"hypertrack-sdk-react-native-plugin-android-push-service-firebase": "13.8.0",
13+
"hypertrack-sdk-react-native": "14.0.0",
14+
"hypertrack-sdk-react-native-plugin-android-activity-service-google": "14.0.0",
15+
"hypertrack-sdk-react-native-plugin-android-location-services-google": "14.0.0",
16+
"hypertrack-sdk-react-native-plugin-android-push-service-firebase": "14.0.0",
1717
"react": "18.2.0",
1818
"react-native": "0.72.17",
1919
"react-native-permissions": "^4.1.5"

src/App.tsx

Lines changed: 59 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const App = () => {
4242
const [isAvailableState, setIsAvailableState] = useState(false);
4343
const [isTrackingState, setIsTrackingState] = useState(false);
4444
const [locationState, setLocationState] = useState('');
45-
const [ordersState, setOrdersState] = useState(new Map<string, Order>());
45+
const [ordersState, setOrdersState] = useState('N/A');
4646

4747
const errorsListener = useRef<EmitterSubscription | null | undefined>(null);
4848
const isAvailableListener = useRef<EmitterSubscription | null | undefined>(
@@ -88,7 +88,7 @@ const App = () => {
8888
* (to remove the link between the device and the worker)
8989
**/
9090
HyperTrack.setWorkerHandle(
91-
`test_driver_quickstart_react_native_${platformName}`,
91+
`test_worker_quickstart_react_native_${platformName}`,
9292
);
9393
console.log('workerHandle is set');
9494

@@ -125,9 +125,10 @@ const App = () => {
125125
);
126126

127127
ordersListener.current = HyperTrack.subscribeToOrders(
128-
(orders: Map<string, Order>) => {
128+
async (orders: Map<string, Order>) => {
129129
console.log('Listener orders: ', orders);
130-
setOrdersState(orders);
130+
const text = await getOrdersResponseText(orders);
131+
setOrdersState(text);
131132
},
132133
);
133134
} catch (error) {
@@ -216,7 +217,7 @@ const App = () => {
216217
const allowMockLocation = await HyperTrack.getAllowMockLocation();
217218
console.log('AllowMockLocation:', allowMockLocation);
218219
Alert.alert('AllowMockLocation', `${allowMockLocation}`);
219-
}
220+
};
220221

221222
const getErrors = async () => {
222223
const errors = await HyperTrack.getErrors();
@@ -261,7 +262,8 @@ const App = () => {
261262
const getOrders = async () => {
262263
const orders = await HyperTrack.getOrders();
263264
console.log('Orders:', orders);
264-
Alert.alert('Orders', getOrdersText(orders));
265+
const text = await getOrdersResponseText(orders);
266+
Alert.alert('Orders', text);
265267
};
266268

267269
const locate = async () => {
@@ -284,7 +286,7 @@ const App = () => {
284286
const setAllowMockLocation = async (allowMockLocation: boolean) => {
285287
HyperTrack.setAllowMockLocation(allowMockLocation);
286288
console.log('setAllowMockLocation', allowMockLocation);
287-
}
289+
};
288290

289291
const setIsAvailable = async (isAvailable: boolean) => {
290292
HyperTrack.setIsAvailable(isAvailable);
@@ -306,16 +308,7 @@ const App = () => {
306308
</Text>
307309

308310
<Text style={styles.titleText}>Orders:</Text>
309-
{Array.from(ordersState.values()).map(order => {
310-
return (
311-
<View key={order.orderHandle}>
312-
<Text selectable style={styles.text}>
313-
{order.orderHandle}
314-
</Text>
315-
<Text>{getIsInsideGeofenceText(order.isInsideGeofence)}</Text>
316-
</View>
317-
);
318-
})}
311+
<Text style={styles.text}>{ordersState}</Text>
319312

320313
<Text style={styles.titleText}>{'Location'}</Text>
321314
<Text style={styles.text}>{locationState}</Text>
@@ -386,9 +379,18 @@ const App = () => {
386379
</View>
387380

388381
<View style={styles.buttonWrapper}>
389-
<Button title="Allow Mock Location" onPress={() => setAllowMockLocation(true)} />
390-
<Button title="Disallow Mock Location" onPress={() => setAllowMockLocation(false)} />
391-
<Button title="Get Allow Mock Location" onPress={getAllowMockLocation} />
382+
<Button
383+
title="Allow Mock Location"
384+
onPress={() => setAllowMockLocation(true)}
385+
/>
386+
<Button
387+
title="Disallow Mock Location"
388+
onPress={() => setAllowMockLocation(false)}
389+
/>
390+
<Button
391+
title="Get Allow Mock Location"
392+
onPress={getAllowMockLocation}
393+
/>
392394
</View>
393395
</ScrollView>
394396
</SafeAreaView>
@@ -410,6 +412,17 @@ function getLocateResponseText(response: Result<Location, HyperTrackError[]>) {
410412
}
411413
}
412414

415+
function getLocationErrorResponseText(locationError: LocationError) {
416+
switch (locationError.type) {
417+
case 'notRunning':
418+
return 'Not running';
419+
case 'starting':
420+
return 'Starting';
421+
case 'errors':
422+
return `Errors:\n${getErrorsText(locationError.value)}`;
423+
}
424+
}
425+
413426
function getLocationResponseText(
414427
response: Result<Location, LocationError>,
415428
): string {
@@ -421,16 +434,7 @@ function getLocationResponseText(
421434
4,
422435
)}`;
423436
case 'failure':
424-
switch (response.value.type) {
425-
case 'notRunning':
426-
return 'Not running';
427-
case 'starting':
428-
return 'Starting';
429-
case 'errors':
430-
return `Errors:\n${getErrorsText(response.value.value)}`;
431-
}
432-
default:
433-
return `Unknown response: $response`;
437+
return getLocationErrorResponseText(response.value);
434438
}
435439
}
436440

@@ -445,14 +449,31 @@ function getLocationWithDeviationResponseText(
445449
4,
446450
)}\nDeviation: ${response.value.deviation}`;
447451
case 'failure':
448-
switch (response.value.type) {
449-
case 'notRunning':
450-
return 'Not running';
451-
case 'starting':
452-
return 'Starting';
453-
case 'errors':
454-
return `Errors:\n${getErrorsText(response.value.value)}`;
455-
}
452+
return getLocationErrorResponseText(response.value);
453+
}
454+
}
455+
456+
async function getOrdersResponseText(orders: Map<string, Order>) {
457+
if (orders.size === 0) {
458+
return 'No orders';
459+
} else {
460+
return await Promise.all(
461+
Array.from(orders).map(async ([_, order]) => {
462+
let isInsideGeofenceText: string;
463+
const isInsideGeofence = await order.isInsideGeofence();
464+
switch (isInsideGeofence.type) {
465+
case 'success':
466+
isInsideGeofenceText = isInsideGeofence.value.toString();
467+
break;
468+
case 'failure':
469+
isInsideGeofenceText = getLocationErrorResponseText(
470+
isInsideGeofence.value,
471+
);
472+
break;
473+
}
474+
return `Order: ${order.orderHandle}\nIsInsideGeofence: ${isInsideGeofenceText}`;
475+
}),
476+
).then(texts => texts.join('\n'));
456477
}
457478
}
458479

@@ -472,34 +493,6 @@ function getErrorsText(errors: HyperTrackError[]) {
472493
}
473494
}
474495

475-
function getIsInsideGeofenceText(
476-
isInsideResult: Result<boolean, LocationError>,
477-
) {
478-
switch (isInsideResult.type) {
479-
case 'success':
480-
return isInsideResult.value.toString();
481-
case 'failure':
482-
switch (isInsideResult.value.type) {
483-
case 'notRunning':
484-
return 'Not running';
485-
case 'starting':
486-
return 'Starting';
487-
case 'errors':
488-
return `Errors:\n${getErrorsText(isInsideResult.value.value)}`;
489-
}
490-
}
491-
}
492-
493-
function getOrdersText(orders: Map<string, Order>) {
494-
return Array.from(orders.values())
495-
.map(order => {
496-
return `${order.orderHandle}:\n\t\t${getIsInsideGeofenceText(
497-
order.isInsideGeofence,
498-
)}`;
499-
})
500-
.join('\n');
501-
}
502-
503496
const styles = StyleSheet.create({
504497
container: {
505498
flex: 1,

0 commit comments

Comments
 (0)