Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a more thorough Usage example, and make skipPermissionRequests optional #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,23 @@ navigator.geolocation = require('@react-native-community/geolocation');
```javascript
import Geolocation from '@react-native-community/geolocation';

Geolocation.getCurrentPosition(info => console.log(info));
function() Example() {
useEffect(() => {
Geolocation.setRNConfiguration({
skipPermissionRequests: false,
authorizationLevel: 'whenInUse',
locationProvider: 'auto',
});

Geolocation.getCurrentPosition(
pos => console.debug('Geolocation.getCurrentPosition Result', JSON.stringify(pos)),
error => console.error('Geolocation.getCurrentPosition Error', JSON.stringify(error)),
{enableHighAccuracy: true},
);
};

// ...
}
```

Check out the [example project](example) for more examples.
Expand Down Expand Up @@ -128,7 +144,7 @@ Sets configuration options that will be used in all location requests.
```ts
Geolocation.setRNConfiguration(
config: {
skipPermissionRequests: boolean;
skipPermissionRequests?: boolean;
authorizationLevel?: 'always' | 'whenInUse' | 'auto';
locationProvider?: 'playServices' | 'android' | 'auto';
}
Expand Down
5 changes: 3 additions & 2 deletions js/NativeRNCGeolocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export type GeolocationConfiguration = {
skipPermissionRequests: boolean;
skipPermissionRequests?: boolean;
authorizationLevel?: 'always' | 'whenInUse' | 'auto';
locationProvider?: 'playServices' | 'android' | 'auto';
};
Expand Down Expand Up @@ -40,8 +40,9 @@ export type GeolocationError = {

export interface Spec extends TurboModule {
setConfiguration(config: {
skipPermissionRequests: boolean;
skipPermissionRequests?: boolean;
authorizationLevel?: string;
locationProvider?: string;
}): void;
requestAuthorization(
success: () => void,
Expand Down
6 changes: 3 additions & 3 deletions js/implementation.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ let updatesEnabled = false;
*/
export function setRNConfiguration(config: GeolocationConfiguration) {
RNCGeolocation.setConfiguration({
...config,
skipPermissionRequests: config.skipPermissionRequests,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip... is now optional in config, so needs to be explicit here to remain consistent.

authorizationLevel:
config?.authorizationLevel === 'auto'
config.authorizationLevel === 'auto'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config is not undefined, only the property, but this check is safe for config.authorizationLevel === undefined.

? undefined
: config.authorizationLevel,
locationProvider:
config?.locationProvider === 'auto' ? undefined : config.locationProvider,
config.locationProvider === 'auto' ? undefined : config.locationProvider,
});
}

Expand Down