Skip to content

Commit

Permalink
chore: deprecate access token support
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Zubko <oleksii.zubko@gmail.com>
  • Loading branch information
OleksiiZubko committed Jan 5, 2025
1 parent 0661d38 commit e8c89bd
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,21 @@ public Map<String, Object> getConstants() {
.build();
}

@ReactMethod
public void createMapLibreInstance() {
mReactContext.runOnUiQueueThread(new Runnable() {
@Override
public void run() {
MapLibre.getInstance(getReactApplicationContext());
}
});
}

// TODO: How to handle this? API has changed significantly
/**
* @deprecated This will be removed in the next major version, Use createMapLibreInstance instead.
* @see https://github.com/maplibre/maplibre-react-native/issues/25#issuecomment-1382382044
*/
@ReactMethod
public void setAccessToken(final String accessToken) {
mReactContext.runOnUiQueueThread(new Runnable() {
Expand Down Expand Up @@ -171,6 +185,10 @@ 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
*/
@ReactMethod
public void getAccessToken(Promise promise) {
String token = MapLibre.getApiKey();
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/MLRNModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Methods

### `setAccessToken(accessToken)`
### `createMapLibreInstance()`

Set accessToken, which is required when you want to use Mapbox tiles. Not required when using other tiles.
MapLibre Native for Android **requires** calling this.

#### Arguments

Expand Down
7 changes: 3 additions & 4 deletions docs/guides/setup/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,18 @@ 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";
import { MapView, createMapLibreInstance } from "@maplibre/maplibre-react-native";

// Required on Android, see note below
setAccessToken(null);
createMapLibreInstance();

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.
> MapLibre Native for Android **requires** calling `MapLibre.getInstance` before inflating or creating the view.
## Further reading

Expand Down
4 changes: 4 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 Down
6 changes: 4 additions & 2 deletions packages/examples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
requestAndroidLocationPermissions,
setAccessToken,
createMapLibreInstance,
} from "@maplibre/maplibre-react-native";
import { useEffect, useState } from "react";
import { LogBox, Platform, StyleSheet, Text, View } from "react-native";
Expand All @@ -24,7 +24,9 @@ const styles = StyleSheet.create({

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

setAccessToken(null);
if (IS_ANDROID) {
createMapLibreInstance();
}

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

createMapLibreInstance(): Promise<void>;

setAccessToken(accessToken: string | null): Promise<string | null>;
getAccessToken(): Promise<string>;

Expand All @@ -42,6 +44,8 @@ export const {
StyleSource,
StyleURL,

createMapLibreInstance,

setAccessToken,
getAccessToken,

Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/__mocks__/NativeModules.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ NativeModules.MLRNModule = {
OfflineCallbackName: keyMirror(["Progress", "Error"]),

// Methods

createMapLibreInstance: jest.fn(),

setAccessToken: jest.fn(),
getAccessToken: () => Promise.resolve("test-token"),

Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ describe("Package Exports", () => {

// Methods

"createMapLibreInstance",

"setAccessToken",
"getAccessToken",

Expand Down

0 comments on commit e8c89bd

Please sign in to comment.