-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: headless js + example updates
- Loading branch information
1 parent
a2df70e
commit e5e23d1
Showing
14 changed files
with
176 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) React Native Community | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { View, Button, AppState } from 'react-native'; | ||
import BackgroundTimer from 'react-native-background-timer'; | ||
import Geolocation from '@react-native-community/geolocation'; | ||
|
||
export default function BackgroundLocationUpdates() { | ||
const appState = useRef(AppState.currentState); | ||
const [backgroundListener, setBackgroundListener] = useState(false); | ||
|
||
useEffect(() => { | ||
if (!backgroundListener) { | ||
return; | ||
} | ||
|
||
const subscription = AppState.addEventListener('change', (nextAppState) => { | ||
if (nextAppState.match(/inactive|background/)) { | ||
BackgroundTimer.runBackgroundTimer(() => { | ||
Geolocation.getCurrentPosition( | ||
(position) => { | ||
console.log( | ||
'getCurrentPosition background', | ||
JSON.stringify(position) | ||
); | ||
}, | ||
(error) => | ||
console.log( | ||
'getCurrentPosition background error', | ||
JSON.stringify(error) | ||
), | ||
{ enableHighAccuracy: true } | ||
); | ||
}, 1000); | ||
|
||
console.log('App has come to the foreground!'); | ||
} else { | ||
BackgroundTimer.stopBackgroundTimer(); | ||
} | ||
|
||
appState.current = nextAppState; | ||
}); | ||
|
||
return () => { | ||
subscription.remove(); | ||
}; | ||
}, [backgroundListener]); | ||
|
||
return ( | ||
<View> | ||
<Button | ||
title={`${ | ||
backgroundListener ? 'Disable' : 'Enable' | ||
} background location updates`} | ||
onPress={() => setBackgroundListener(!backgroundListener)} | ||
/> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.