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

feat: make setAccessToken(null) obsolete #593

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public MLRNModule(ReactApplicationContext reactApplicationContext) {
mReactContext = reactApplicationContext;
}

@Override
public void initialize() {
initializeMapLibreInstance();
}

@Override
public String getName() {
return REACT_CLASS;
Expand Down Expand Up @@ -127,7 +132,11 @@ public Map<String, Object> getConstants() {
.build();
}

// TODO: How to handle this? API has changed significantly
/**
* @deprecated This will be removed in the next major version.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
@Deprecated
@ReactMethod
public void setAccessToken(final String accessToken) {
mReactContext.runOnUiQueueThread(new Runnable() {
Expand Down Expand Up @@ -170,7 +179,11 @@ public void run() {
});
}

// TODO: How to handle this? Underlying API has changed significantly on Android
/**
* @deprecated This will be removed in the next major version.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
@Deprecated
@ReactMethod
public void getAccessToken(Promise promise) {
String token = MapLibre.getApiKey();
Expand Down Expand Up @@ -198,4 +211,13 @@ private Dispatcher getDispatcher() {
dispatcher.setMaxRequestsPerHost(20);
return dispatcher;
}

private void initializeMapLibreInstance() {
mReactContext.runOnUiQueueThread(new Runnable() {
@Override
public void run() {
MapLibre.getInstance(getReactApplicationContext());
}
});
}
}
20 changes: 0 additions & 20 deletions docs/guides/MLRNModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

## Methods

### `setAccessToken(accessToken)`

Set accessToken, which is required when you want to use Mapbox tiles. Not required when using other tiles.

#### Arguments

| Name | Type | Required | Description |
|---------------|:--------:|:--------:|:--------------------------------------------------------------------------------:|
| `accessToken` | `string` | `Yes` | Access token necessary for Mapbox tiles. Can be `null` for other tile providers. |

### `getAccessToken()`

Get the accessToken.

#### Arguments

| Name | Type | Required | Description |
|---------------|:--------:|:--------:|:-------------------------------------------------------------------------------:|
| `accessToken` | `string` | `Yes` | access token to pull Mapbox-hosted tiles; can be `null` if for other tile hosts |

### `addCustomHeader(headerName, headerValue)`

See [Custom HTTP Headers](/docs/guides/Custom-HTTP-Headers.md)
Expand Down
9 changes: 9 additions & 0 deletions docs/guides/migrations/v10.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Migrating to v10

## Remove `setAccessToken(null)`

Calling `setAccessToken(null)` is obsolete now. Vendor specific access tokens should be set via style or tile URLs,
consult the corresponding provider docs if necessary.

```diff
- setAccessToken(null)
```

## Changes to `Camera` Component

### Default `animationMode` is now `CameraMode.None`
Expand Down
9 changes: 1 addition & 8 deletions docs/guides/setup/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,13 @@ After completing the installation and rebuilding the app, you can start using th

```tsx
import React from "react";
import { MapView, setAccessToken } from "@maplibre/maplibre-react-native";

// Required on Android, see note below
setAccessToken(null);
import { MapView } from "@maplibre/maplibre-react-native";

function App() {
return <MapView style={{ flex: 1 }} />;
}
```

> [!Important]
> MapLibre Native for Android **requires** calling `setAccessToken` with either `null` or a proper value, if you are
> using Mapbox.

## Further reading

For applied usage, view the [examples app](/packages/examples). For more reading, follow
Expand Down
8 changes: 8 additions & 0 deletions ios/MLRN/MLRNModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ + (BOOL)requiresMainQueueSetup
};
}

/**
* @deprecated This will be removed in the next major version.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
RCT_EXPORT_METHOD(setAccessToken:(NSString *)accessToken)
OleksiiZubko marked this conversation as resolved.
Show resolved Hide resolved
{
if (accessToken.length > 0) {
Expand All @@ -107,6 +111,10 @@ + (BOOL)requiresMainQueueSetup
[MLRNCustomHeaders.sharedInstance removeHeader:headerName];
}

/**
* @deprecated This will be removed in the next major version.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
RCT_EXPORT_METHOD(getAccessToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
NSString* accessToken = MLNSettings.apiKey;
Expand Down
7 changes: 1 addition & 6 deletions packages/examples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
requestAndroidLocationPermissions,
setAccessToken,
} from "@maplibre/maplibre-react-native";
import { requestAndroidLocationPermissions } from "@maplibre/maplibre-react-native";
import { useEffect, useState } from "react";
import { LogBox, Platform, StyleSheet, Text, View } from "react-native";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
Expand All @@ -24,8 +21,6 @@ const styles = StyleSheet.create({

const IS_ANDROID = Platform.OS === "android";

setAccessToken(null);

export function App() {
const [isFetchingAndroidPermission, setIsFetchingAndroidPermission] =
useState(IS_ANDROID);
Expand Down
8 changes: 8 additions & 0 deletions src/MLRNModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ interface IMLRNModule {
Default: string;
};

/**
* @deprecated This will be removed in the next major version.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
setAccessToken(accessToken: string | null): Promise<string | null>;
/**
* @deprecated This will be removed in the next major version.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
getAccessToken(): Promise<string>;

addCustomHeader(headerName: string, headerValue: string): void;
Expand Down
Loading