-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use latest play services version 21.0.1 (#249) Thanks, I'll test this out and include in the next version * work in Headless JS (#254) Co-authored-by: lavrik acer <valery.lavrik@gmail.com> * Default `maximumAge` to 0 on iOS. (#268) * Example updates (#270) * chore: headless js + example updates * chore: revert ts changes * chore: fix background location timer types * chore: move types package --------- Co-authored-by: Brian Rojas <marchinram@gmail.com> Co-authored-by: valery-lavrik <valery-lavrik@users.noreply.github.com> Co-authored-by: lavrik acer <valery.lavrik@gmail.com> Co-authored-by: Justin Kaufman <57186+jkaufman@users.noreply.github.com>
- Loading branch information
1 parent
7de1d36
commit f3da392
Showing
16 changed files
with
178 additions
and
53 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
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
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.