react-native-move-sdk 2.6.9 → 2.7.1-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-move-sdk",
3
- "version": "2.6.9",
3
+ "version": "2.7.1-alpha",
4
4
  "description": "React Native library for MOVE SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -46,20 +46,20 @@
46
46
  "@commitlint/config-conventional": "^11.0.0",
47
47
  "@react-native-community/eslint-config": "^2.0.0",
48
48
  "@release-it/conventional-changelog": "^2.0.0",
49
- "@types/react": "^16.9.19",
50
- "@types/react-native": "0.62.13",
49
+ "@types/react": "^18.2.48",
50
+ "@types/react-native": "^0.73.0",
51
51
  "commitlint": "^11.0.0",
52
- "eslint": "^7.2.0",
52
+ "eslint": "^8.57.0",
53
53
  "eslint-config-prettier": "^7.0.0",
54
54
  "eslint-plugin-prettier": "^3.1.3",
55
55
  "flow-remove-types": "^2.177.0",
56
56
  "pod-install": "^0.1.0",
57
57
  "prettier": "^2.0.5",
58
- "react": "16.13.1",
59
- "react-native": "0.63.3",
58
+ "react": "^18.2.0",
59
+ "react-native": "^0.73.2",
60
60
  "react-native-builder-bob": "^0.17.1",
61
61
  "release-it": "^14.2.2",
62
- "typescript": "^4.1.3"
62
+ "typescript": "^5.3.3"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "react": "*",
@@ -115,7 +115,8 @@
115
115
  "singleQuote": true,
116
116
  "tabWidth": 2,
117
117
  "trailingComma": "es5",
118
- "useTabs": false
118
+ "useTabs": false,
119
+ "printWidth": 200
119
120
  },
120
121
  "react-native-builder-bob": {
121
122
  "source": "src",
@@ -131,5 +132,7 @@
131
132
  ]
132
133
  ]
133
134
  },
134
- "dependencies": {}
135
+ "dependencies": {
136
+ "@react-native-async-storage/async-storage": "^1.21.0"
137
+ }
135
138
  }
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
18
18
  s.source_files = "ios/**/*.{h,m,mm,swift}"
19
19
 
20
20
  s.dependency 'React'
21
- s.dependency 'DolphinMoveSDK', '2.6.9.276'
21
+ s.dependency 'MoveSDK', '2.7.0.280'
22
22
  end
package/src/MoveSdk.ts ADDED
@@ -0,0 +1,450 @@
1
+ import { NativeModules, NativeEventEmitter, Platform, EmitterSubscription } from 'react-native';
2
+
3
+ export type SdkState = 'UNINITIALIZED' | 'READY' | 'RUNNING';
4
+ export type TripState = 'UNKNOWN' | 'DRIVING' | 'HALT' | 'IDLE' | 'IGNORED';
5
+ export type AuthState = 'UNKNOWN' | 'VALID' | 'EXPIRED' | 'INVALID';
6
+ export type DrivingService = 'DISTRACTION_FREE_DRIVING' | 'DRIVING_BEHAVIOUR' | 'DEVICE_DISCOVERY';
7
+ export type WalkingService = 'WALKING_LOCATION';
8
+ export type OtherService = 'POINTS_OF_INTEREST';
9
+ export type TimelineDetectionService = 'DRIVING' | 'CYCLING' | 'WALKING' | 'PLACES' | 'PUBLIC_TRANSPORT' | 'AUTOMATIC_IMPACT_DETECTION' | 'ASSISTANCE_CALL' | 'POINTS_OF_INTEREST';
10
+
11
+ export type ErrorReasons =
12
+ | 'BACKGROUND_LOCATION_PERMISSION_MISSING'
13
+ | 'LOCATION_PERMISSION_MISSING'
14
+ | 'MOTION_PERMISSION_MISSING'
15
+ | 'ACTIVITY_PERMISSION_MISSING'
16
+ | 'BATTERY_PERMISSION_MISSING'
17
+ | 'UNAUTHORIZED'
18
+ | 'INTERNET_PERMISSION_MISSING'
19
+ | 'PHONE_PERMISSION_MISSING'
20
+ | 'OVERLAY_PERMISSION_MISSING'
21
+ | 'NOTIFICATION_MISSING'
22
+ | 'ACCELEROMETER_MISSING'
23
+ | 'GOOGLE_PLAY_LOCATION_ACCURACY_MISSING'
24
+ | 'PRECISE_LOCATION_PERMISSION_MISSING';
25
+
26
+ export type WarningReasons =
27
+ | 'BACKGROUND_LOCATION_PERMISSION_MISSING'
28
+ | 'MOTION_PERMISSION_MISSING'
29
+ | 'ACTIVITY_PERMISSION_MISSING'
30
+ | 'BATTERY_OPTIMIZATION'
31
+ | 'BLUETOOTH_TURNED_OFF'
32
+ | 'BLUETOOTH_SCAN_PERMISSION_MISSING'
33
+ | 'BLUETOOTH_CONNECT_PERMISSION_MISSING'
34
+ | 'GOOGLE_PLAY_LOCATION_ACCURACY_MISSING'
35
+ | 'NOTIFICATION_PERMISSION_MISSING'
36
+ | 'FINE_LOCATION_PERMISSION_MISSING'
37
+ | 'BLUETOOTH_PERMISSION_MISSING'
38
+ | 'GPS_OFF'
39
+ | 'OFFLINE';
40
+
41
+ export type IssueListService = TimelineDetectionService | DrivingService | WalkingService;
42
+
43
+ export type IssueListItem<ReasonsType> = {
44
+ reasons: Array<ReasonsType>;
45
+ service?: IssueListService;
46
+ };
47
+
48
+ export type ErrorListType = Array<IssueListItem<ErrorReasons>>;
49
+
50
+ export type WarningListType = Array<IssueListItem<WarningReasons>>;
51
+
52
+ export type ShutdownReturnType = 'NETWORK_ERROR' | 'SUCCESS' | 'UNINITIALIZED';
53
+
54
+ export type MoveSdkConfig = {
55
+ timelineDetectionServices: Array<TimelineDetectionService>;
56
+ drivingServices: Array<DrivingService>;
57
+ walkingServices: Array<WalkingService>;
58
+ };
59
+
60
+ export type MoveSdkDeviceDiscovery = {
61
+ startDelay?: number;
62
+ duration?: number;
63
+ interval?: number;
64
+ stopScanOnFirstDiscovered?: boolean;
65
+ };
66
+
67
+ export type MoveSdkOptions = {
68
+ motionPermissionMandatory?: boolean;
69
+ backgroundLocationPermissionMandatory?: boolean;
70
+ useBackendConfig?: boolean;
71
+ deviceDiscovery?: MoveSdkDeviceDiscovery;
72
+ };
73
+
74
+ export type MoveSdkAuth = {
75
+ userId: string;
76
+ accessToken: string;
77
+ refreshToken: string;
78
+ projectId: number;
79
+ };
80
+
81
+ export type NotificationConfig = {
82
+ title: string;
83
+ text: string;
84
+ channel: { id: string; name: string; description: string };
85
+ };
86
+
87
+ export type MoveSdkAndroidConfig = {
88
+ notifications: {
89
+ recognitionNotification: NotificationConfig;
90
+ tripNotification: NotificationConfig;
91
+ };
92
+ };
93
+
94
+ export type ListenerSubscription = EmitterSubscription;
95
+
96
+ export type AuthStateEvent = {
97
+ state: AuthState;
98
+ accessToken?: string;
99
+ refreshToken?: string;
100
+ };
101
+
102
+ export type MoveSdkDeviceFilter = 'beacon' | 'paired';
103
+
104
+ export type MoveSdkDevice = {
105
+ name: string;
106
+ data: string;
107
+ id: string;
108
+ };
109
+
110
+ export type MoveScanResult = {
111
+ isDiscovered: boolean;
112
+ device: MoveSdkDevice;
113
+ name: string;
114
+ };
115
+
116
+ const { MoveSdk: NativeMoveSdk } = NativeModules;
117
+ const eventEmitter = new NativeEventEmitter(NativeMoveSdk);
118
+
119
+ export default class MoveSdk {
120
+ static READY: SdkState = 'READY';
121
+ static RUNNING: SdkState = 'RUNNING';
122
+ static UNINITIALIZED: SdkState = 'UNINITIALIZED';
123
+
124
+ static AUTH_EXPIRED: AuthState = 'EXPIRED';
125
+ static AUTH_VALID: AuthState = 'VALID';
126
+ static AUTH_UNKNOWN: AuthState = 'UNKNOWN';
127
+ static AUTH_INVALID: AuthState = 'INVALID';
128
+
129
+ static UNKNOWN: TripState = 'UNKNOWN';
130
+ static DRIVING: TripState = 'DRIVING';
131
+ static HALT: TripState = 'HALT';
132
+ static IDLE: TripState = 'IDLE';
133
+ static IGNORED: TripState = 'IGNORED';
134
+
135
+ static sdkStateFromNative(sdkState: SdkState): SdkState {
136
+ if ([MoveSdk.UNINITIALIZED, MoveSdk.READY, MoveSdk.RUNNING, MoveSdk.UNINITIALIZED].includes(sdkState)) {
137
+ return sdkState;
138
+ }
139
+
140
+ return MoveSdk.UNINITIALIZED;
141
+ }
142
+
143
+ static tripStateFromNative(nativeTripState: TripState): TripState {
144
+ if ([MoveSdk.UNKNOWN, MoveSdk.DRIVING, MoveSdk.HALT, MoveSdk.IDLE, MoveSdk.IGNORED].includes(nativeTripState)) {
145
+ return nativeTripState;
146
+ }
147
+
148
+ return MoveSdk.UNKNOWN;
149
+ }
150
+
151
+ static authStateFromNative(nativeAuthState: AuthState): AuthState {
152
+ if ([MoveSdk.AUTH_VALID, MoveSdk.AUTH_EXPIRED, MoveSdk.AUTH_INVALID].includes(nativeAuthState)) {
153
+ return nativeAuthState;
154
+ }
155
+
156
+ return MoveSdk.AUTH_UNKNOWN;
157
+ }
158
+
159
+ static async setup(config: MoveSdkConfig, auth: MoveSdkAuth, android: MoveSdkAndroidConfig, options?: MoveSdkOptions): Promise<void> {
160
+ const { timelineDetectionServices, drivingServices, walkingServices } = config;
161
+
162
+ const { userId, projectId, accessToken, refreshToken } = auth;
163
+
164
+ let platformParams: Array<string | boolean> = [];
165
+ if (Platform.OS === 'android') {
166
+ const { notifications } = android;
167
+
168
+ const { tripNotification, recognitionNotification } = notifications;
169
+
170
+ if (!tripNotification || !recognitionNotification) {
171
+ throw new Error('MOVE SDK needs notification configuration for Android');
172
+ }
173
+
174
+ platformParams = [
175
+ recognitionNotification.title,
176
+ recognitionNotification.text,
177
+ recognitionNotification.channel.id,
178
+ recognitionNotification.channel.name,
179
+ recognitionNotification.channel.description,
180
+ tripNotification.title,
181
+ tripNotification.text,
182
+ tripNotification.channel.id,
183
+ tripNotification.channel.name,
184
+ tripNotification.channel.description,
185
+ ];
186
+ }
187
+
188
+ return await NativeMoveSdk.setup(
189
+ userId,
190
+ accessToken,
191
+ refreshToken,
192
+ projectId,
193
+ // Config
194
+ timelineDetectionServices,
195
+ drivingServices,
196
+ walkingServices,
197
+ options,
198
+ // Platform config
199
+ ...platformParams
200
+ );
201
+ }
202
+
203
+ static allowMockLocations(allowMockLocations: boolean) {
204
+ NativeMoveSdk.allowMockLocations(allowMockLocations);
205
+ }
206
+
207
+ /* Deprecated */
208
+ static init() {
209
+ NativeMoveSdk.init();
210
+ }
211
+
212
+ static resolveError() {
213
+ NativeMoveSdk.resolveError();
214
+ }
215
+
216
+ static async updateAuth(auth: MoveSdkAuth): Promise<void> {
217
+ const { userId, projectId, accessToken, refreshToken } = auth;
218
+ return await NativeMoveSdk.updateAuth(userId, accessToken, refreshToken, projectId);
219
+ }
220
+
221
+ static startAutomaticDetection() {
222
+ NativeMoveSdk.startAutomaticDetection();
223
+ }
224
+
225
+ static stopAutomaticDetection() {
226
+ NativeMoveSdk.stopAutomaticDetection();
227
+ }
228
+
229
+ static forceTripRecognition(duration: number = 60000) {
230
+ NativeMoveSdk.forceTripRecognition(duration);
231
+ }
232
+
233
+ static keepInForeground(enabled: boolean) {
234
+ if (Platform.OS === 'android') {
235
+ NativeMoveSdk.keepInForeground(enabled);
236
+ } else {
237
+ console.warn('MoveSdk.keepInForeground() is Android OS only.');
238
+ }
239
+ }
240
+
241
+ static keepActive(enabled: boolean) {
242
+ if (Platform.OS === 'android') {
243
+ NativeMoveSdk.keepActive(enabled);
244
+ } else {
245
+ console.warn('MoveSdk.keepActive() is Android OS only.');
246
+ }
247
+ }
248
+
249
+ static async synchronizeUserData(): Promise<boolean> {
250
+ return await NativeMoveSdk.synchronizeUserData();
251
+ }
252
+
253
+ static async getAuthState(): Promise<AuthState> {
254
+ const authState = await NativeMoveSdk.getAuthState();
255
+ return MoveSdk.authStateFromNative(authState);
256
+ }
257
+
258
+ static async getState(): Promise<SdkState> {
259
+ const state = await NativeMoveSdk.getState();
260
+ return MoveSdk.sdkStateFromNative(state);
261
+ }
262
+
263
+ static async getTripState(): Promise<TripState> {
264
+ const tripState = await NativeMoveSdk.getTripState();
265
+ return MoveSdk.tripStateFromNative(tripState);
266
+ }
267
+
268
+ static async getErrors(): Promise<ErrorListType> {
269
+ return await NativeMoveSdk.getErrors();
270
+ }
271
+
272
+ static async getWarnings(): Promise<WarningListType> {
273
+ return await NativeMoveSdk.getWarnings();
274
+ }
275
+
276
+ static async initiateAssistanceCall(): Promise<boolean> {
277
+ return await NativeMoveSdk.initiateAssistanceCall();
278
+ }
279
+
280
+ static setAssistanceMetaData(data: string) {
281
+ NativeMoveSdk.setAssistanceMetaData(data);
282
+ }
283
+
284
+ static addTripStateListener(tripStateChanged: (state: TripState) => void): ListenerSubscription {
285
+ return eventEmitter.addListener('MOVE_SDK_TRIP_STATE', (event) => tripStateChanged(MoveSdk.tripStateFromNative(event.state)));
286
+ }
287
+
288
+ static addTripStartListener(tripStartTriggered: (start: Date) => void): ListenerSubscription {
289
+ return eventEmitter.addListener('MOVE_SDK_TRIP_START', (start) => tripStartTriggered(new Date(Number(start))));
290
+ }
291
+
292
+ static addSdkStateListener(sdkStateChanged: (state: SdkState) => void): ListenerSubscription {
293
+ return eventEmitter.addListener('MOVE_SDK_STATE', (event) => {
294
+ sdkStateChanged(MoveSdk.sdkStateFromNative(event.state));
295
+ });
296
+ }
297
+
298
+ static addAuthStateListener(authStateChanged: (event: AuthStateEvent) => void): ListenerSubscription {
299
+ return eventEmitter.addListener('MOVE_SDK_AUTH_STATE', (event) => {
300
+ const transformedEvent = {
301
+ ...event,
302
+ state: MoveSdk.authStateFromNative(event.state),
303
+ };
304
+ authStateChanged(transformedEvent);
305
+ });
306
+ }
307
+
308
+ static addErrorsListener(errorsReceived: (errors: ErrorListType) => void): ListenerSubscription {
309
+ return eventEmitter.addListener('MOVE_SDK_ERRORS', (event) => {
310
+ errorsReceived(event.errors);
311
+ });
312
+ }
313
+
314
+ static addWarningsListener(warningsReceived: (warnings: WarningListType) => void): ListenerSubscription {
315
+ return eventEmitter.addListener('MOVE_SDK_WARNINGS', (event) => {
316
+ warningsReceived(event.warnings);
317
+ });
318
+ }
319
+
320
+ static addAppEventListener(appEventReceived: (event: string) => void): ListenerSubscription {
321
+ return eventEmitter.addListener('MOVE_SDK_APP_EVENT', (event) => {
322
+ appEventReceived(event);
323
+ });
324
+ }
325
+
326
+ static addRemoteConfigChangeListener(configChangeReceived: (config: Array<IssueListService>) => void): ListenerSubscription {
327
+ return eventEmitter.addListener('MOVE_SDK_CONFIG_UPDATE', (config) => {
328
+ configChangeReceived(config);
329
+ });
330
+ }
331
+
332
+ static version(): string {
333
+ return Platform.OS === 'android' ? NativeMoveSdk.getConstants().version : 'Unknown';
334
+ }
335
+
336
+ static finishCurrentTrip() {
337
+ NativeMoveSdk.finishCurrentTrip();
338
+ }
339
+
340
+ static ignoreCurrentTrip() {
341
+ NativeMoveSdk.ignoreCurrentTrip();
342
+ }
343
+
344
+ static requestMotionPermission() {
345
+ if (Platform.OS === 'ios') {
346
+ NativeMoveSdk.requestMotionPermission();
347
+ } else {
348
+ console.warn('MoveSdk.requestMotionPermission() is iOS only.');
349
+ }
350
+ }
351
+
352
+ static async shutdown(force: boolean = true): Promise<ShutdownReturnType> {
353
+ return await NativeMoveSdk.shutdown(force);
354
+ }
355
+
356
+ static async getDeviceQualifier(): Promise<string | null> {
357
+ return NativeMoveSdk.getDeviceQualifier();
358
+ }
359
+
360
+ static async geocode(latitude: number, longitude: number): Promise<string> {
361
+ return await NativeMoveSdk.geocode(latitude, longitude);
362
+ }
363
+
364
+ static async isAuthValid(): Promise<boolean> {
365
+ return await NativeMoveSdk.isAuthValid();
366
+ }
367
+
368
+ // **** PERMISSIONS MODULE START *****
369
+
370
+ static async canDrawOverlays(): Promise<boolean> {
371
+ return await NativeMoveSdk.canDrawOverlays();
372
+ }
373
+
374
+ static requestDrawOverlaysPermission() {
375
+ if (Platform.OS === 'android') {
376
+ NativeMoveSdk.requestDrawOverlaysPermission();
377
+ } else {
378
+ console.warn('MoveSdk.requestDrawOverlaysPermission() is Android OS only.');
379
+ }
380
+ }
381
+
382
+ static async isAppIgnoringBatteryOptimization(): Promise<boolean> {
383
+ return await NativeMoveSdk.isAppIgnoringBatteryOptimization();
384
+ }
385
+
386
+ static requestAppIgnoringBatteryOptimization() {
387
+ if (Platform.OS === 'android') {
388
+ NativeMoveSdk.requestAppIgnoringBatteryOptimization();
389
+ } else {
390
+ console.warn('MoveSdk.requestAppIgnoringBatteryOptimization() is Android OS only.');
391
+ }
392
+ }
393
+
394
+ // **** PERMISSIONS MODULE END *****
395
+
396
+ static startScanningDevices(sdkDevicesDetected: (state: Array<MoveSdkDevice>) => void, filter: MoveSdkDeviceFilter[] = ['paired'], uuid?: string, manufacturerId?: number): ListenerSubscription {
397
+ const subscription = eventEmitter.addListener('MOVE_SDK_DEVICES', (devices) => {
398
+ sdkDevicesDetected(devices);
399
+ });
400
+ const subscriptionRemove = subscription.remove;
401
+ subscription.remove = () => {
402
+ NativeMoveSdk.stopScanningDevices();
403
+ subscriptionRemove();
404
+ };
405
+
406
+ NativeMoveSdk.startScanningDevices(filter, uuid, manufacturerId ?? -1);
407
+ return subscription;
408
+ }
409
+
410
+ static async getRegisteredDevices(): Promise<Array<MoveSdkDevice>> {
411
+ return await NativeMoveSdk.getRegisteredDevices();
412
+ }
413
+
414
+ static async registerDevices(devices: Array<MoveSdkDevice>): Promise<boolean> {
415
+ return await NativeMoveSdk.registerDevices(devices);
416
+ }
417
+
418
+ static async unregisterDevices(devices: Array<MoveSdkDevice>): Promise<boolean> {
419
+ return await NativeMoveSdk.unregisterDevices(devices);
420
+ }
421
+
422
+ static requestBluetoothAlwaysUsagePermission(): void {
423
+ NativeMoveSdk.requestBluetoothAlwaysUsagePermission();
424
+ }
425
+
426
+ static addDeviceDiscoveryListener(onScanResult: (state: Array<MoveScanResult>) => void): ListenerSubscription {
427
+ return eventEmitter.addListener('MOVE_SDK_SCAN_RESULT', (results) => {
428
+ onScanResult(results);
429
+ });
430
+ }
431
+
432
+ static setTimer(callback: () => void, delay: number = 60000): string {
433
+ if (Platform.OS === 'android') {
434
+ const key = Date.now().toString();
435
+ NativeMoveSdk.setTimer(delay, key, callback);
436
+ return key;
437
+ } else {
438
+ console.warn('MoveSdk.setTimer() is Android OS only.');
439
+ return '';
440
+ }
441
+ }
442
+
443
+ static cancelTimer(key: string) {
444
+ if (Platform.OS === 'android') {
445
+ NativeMoveSdk.cancelTimer(key);
446
+ } else {
447
+ console.warn('MoveSdk.cancelTimer() is Android OS only.');
448
+ }
449
+ }
450
+ }
@@ -0,0 +1,81 @@
1
+ import React, { Suspense, useEffect, useRef, useState } from 'react';
2
+ import { AppState, AppStateStatus, Platform, View } from 'react-native';
3
+ import AsyncStorage from '@react-native-async-storage/async-storage';
4
+
5
+ import MoveSdk, { TripState } from '../MoveSdk';
6
+
7
+ type LazyMoveSdkProps = {
8
+ children: React.ReactNode;
9
+ delayToRemoveUiInBackgroundMs?: number;
10
+ };
11
+
12
+ export default function LazyMoveSdk({ children, delayToRemoveUiInBackgroundMs = 30000 }: LazyMoveSdkProps) {
13
+ const prevState = useRef('terminated');
14
+ const [currentMode, setCurrentMode] = useState(AppState.currentState);
15
+ const [tripState, setTripState] = useState<TripState>();
16
+ const [removeUi, setRemoveUi] = useState(false);
17
+
18
+ useEffect(() => {
19
+ let timer: ReturnType<typeof setTimeout> | null | number | string = null;
20
+ const appStateSubscription = AppState.addEventListener('change', (state: AppStateStatus) => {
21
+ setCurrentMode(state);
22
+ prevState.current = state;
23
+ });
24
+ const tripStateSubscription = MoveSdk.addTripStateListener(setTripState);
25
+
26
+ const checkStatesAndSetTimerToRemoveUi = async () => {
27
+ const removeUiInBackgroundTimeoutId = await AsyncStorage.getItem('@removeUiInBackgroundTimeoutId');
28
+ if (currentMode === 'background' && tripState === MoveSdk.DRIVING && !removeUiInBackgroundTimeoutId && timer === null) {
29
+ if (Platform.OS === 'android') {
30
+ timer = MoveSdk.setTimer(() => setRemoveUi(true), delayToRemoveUiInBackgroundMs);
31
+ } else {
32
+ timer = setTimeout(() => setRemoveUi(true), delayToRemoveUiInBackgroundMs);
33
+ }
34
+ if (timer) {
35
+ AsyncStorage.setItem('@removeUiInBackgroundTimeoutId', timer.toString());
36
+ }
37
+ }
38
+ if (currentMode === 'active' && removeUiInBackgroundTimeoutId) {
39
+ if (Platform.OS === 'android') {
40
+ MoveSdk.cancelTimer(removeUiInBackgroundTimeoutId);
41
+ } else {
42
+ clearTimeout(+removeUiInBackgroundTimeoutId);
43
+ }
44
+ timer = null;
45
+ await AsyncStorage.removeItem('@removeUiInBackgroundTimeoutId');
46
+ }
47
+ };
48
+ checkStatesAndSetTimerToRemoveUi();
49
+
50
+ return () => {
51
+ appStateSubscription.remove();
52
+ tripStateSubscription.remove();
53
+ if (timer) {
54
+ if (Platform.OS === 'android') {
55
+ MoveSdk.cancelTimer(timer as string);
56
+ } else {
57
+ clearTimeout(timer as number);
58
+ }
59
+ timer = null;
60
+ }
61
+ };
62
+ }, [currentMode, tripState, delayToRemoveUiInBackgroundMs]);
63
+
64
+ useEffect(() => {
65
+ if (currentMode === 'active' && removeUi) {
66
+ setRemoveUi(false);
67
+ }
68
+ }, [currentMode, removeUi]);
69
+
70
+ const startedInBackground =
71
+ (prevState.current === 'terminated' && currentMode === 'background') ||
72
+ (prevState.current === 'terminated' && currentMode === 'unknown') ||
73
+ (prevState.current === 'background' && currentMode === 'background');
74
+
75
+ // DON'T RENDER UI IF APP STARTED IN BACKGROUND OR APP IS IN BACKGROUND AND TRIP STARTS
76
+ if (startedInBackground || removeUi) {
77
+ return <View />;
78
+ }
79
+
80
+ return <Suspense fallback={<View />}>{children}</Suspense>;
81
+ }