[Bug]: The SDK is constantly using the location when the user permits the App to use location 'Always'
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 2.9k
- Forks
- 947
- Avg merge
- 6d 37m
- Merged PRs (30d)
- 1
Description
Mapbox Implementation
Mapbox
Mapbox Version
10.7.0
Platform
iOS
@rnmapbox/maps version
rnmapbox/maps#main
Standalone component to reproduce
import React from 'react';
import PropTypes from 'prop-types';
import {MapView, UserLocation} from '@rnmapbox/maps';
import {useIsFocused} from '@react-navigation/native';
import {connect} from 'react-redux';
const APP_STATE = {
active: 'active',
inactive: 'inactive',
background: 'background',
};
class Mapp extends React.Component {
_contidionallyRenderUserLocation = () => {
const {isFocused, appState} = this.props;
if (isFocused && APP_STATE.active === appState)
return (
<UserLocation
showsUserHeadingIndicator={true}
visible={true}
renderMode="native"
/>
);
};
render() {
return <MapView>{this._contidionallyRenderUserLocation()}</MapView>;
}
}
const EnhancedMapp = props => {
const isFocused = useIsFocused();
return <Mapp {...props} isFocused={isFocused} />;
};
const mapStateToProps = state => {
const {appSettings} = state;
return {
appState: appSettings.appState,
};
};
Mapp.propTypes = {
appState: PropTypes.string,
isFocused: PropTypes.boolean
}
export default connect(mapStateToProps, null)(EnhancedMapp);
appSettings is an event listener, basically this
import {AppState} from 'react-native';
...
const appStateSubscription = AppState.addEventListener(
'change',
nextAppState => {
if (
nextAppState === APP_STATE.active ||
nextAppState === APP_STATE.background
) {
store.dispatch(setAppState(nextAppState));
}
appState.current = nextAppState;
})
...
Observed behavior and steps to reproduce
When the user gives the app Location Permission - Always the Maps SDK uses the location always, when the App is in the foreground (opened) or in the background (closed, but not terminated).
Expected behavior
I expect to be able to set a property that tells the SDK 'Use the location now' or 'Do not use the location when the App is in the background', 'Do not access the location, eventhough you have permission always' ... or something similiar.
Notes / preliminary analysis
This is a thing arising with React-Navigation and Tab Navigator. When using a Tab Navigator, React Naigation does not unmount a component once its mounted inside a Tab Navigator. I though that <UserLocation /> is the component responsible for using the location all the time, so I tried to conditionally render it with isFocused = false and appState === 'active'. isFocused becomes true when the Tab Navigator focussed on the map. appState === 'active becomes true when the app is in the foreground. However, even with the precautions on the <UserLocation/>, the SDK always uses the location, doesnt really matter if the app is in the foreground or in the background, if the corresponding Tab in the Tab Navigator is focussed or not. So I assume the <MapView> is responsible for using the location always?
Additional links and references
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Mapp reproduction, especially the conditional rendering of UserLocation inside MapView and the React Native AppState and React Navigation state transitions. Trace whether location use continues after UserLocation is omitted or the tab loses focus, then verify the expected foreground and background behavior on iOS with Location Permission set to Always.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100