Skip to content

Commit

Permalink
Merge pull request #3694 from TrainLCD/fix/perf
Browse files Browse the repository at this point in the history
Fix/perf
  • Loading branch information
TinyKitten authored Aug 14, 2024
2 parents b24de2c + da651f7 commit 22fcf84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as TaskManager from 'expo-task-manager'

TaskManager.unregisterAllTasksAsync().catch(console.error)

let lastTimestamp = 0

if (!TaskManager.isTaskDefined(LOCATION_TASK_NAME)) {
TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
if (error) {
console.error(error)
return
}

setLocation(data.locations[0])
const latestTimestamp = data.locations[0]?.timestamp ?? 0
if (lastTimestamp < latestTimestamp) {
setLocation(data.locations[0])
lastTimestamp = latestTimestamp
}
})
}

Expand All @@ -18,8 +26,6 @@ import App from './src'
import { LOCATION_TASK_NAME } from './src/constants'
import { setLocation } from './src/hooks/useLocationStore'

TaskManager.unregisterAllTasksAsync().catch(console.error)

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in the Expo client or in a native build,
// the environment is set up appropriately
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useStartBackgroundLocationUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useStartBackgroundLocationUpdates = () => {
) {
Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.High,
distanceInterval: 100,
distanceInterval: 250,
foregroundService: {
notificationTitle: translate('bgAlertTitle'),
notificationBody: translate('bgAlertContent'),
Expand Down

0 comments on commit 22fcf84

Please sign in to comment.