Skip to content

Commit

Permalink
feat: make setAccessToken(null) obsolete (#593)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Zubko <[email protected]>
Co-authored-by: Kilian Finger <[email protected]>
  • Loading branch information
OleksiiZubko and KiwiKilian authored Jan 6, 2025
1 parent 0661d38 commit df44b48
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 36 deletions.
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)
{
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

0 comments on commit df44b48

Please sign in to comment.