PRs are most welcome! This doc covers some basic things you'll need to know to set up your development environment and streamline the review process.
This project consists of these parts:
- Library
- Examples
/examples/shared: Shared code for examples/examples/expo-app: Expo example app, uses new architecture/examples/react-native-app: React Native example app, uses old architecture
Use Node Version Manager, which allows to simply run nvm install within the root, to
install and apply the correct
node version. Otherwise make sure, you are using the Node.js version from .nvmrc.
This project uses yarn as a package manager.
Caution
Do not install yarn using npm, this would install outdated yarn v1. Read
the yarn installation docs or follow the next steps.
corepack enablecorepack prepare yarn@stable --activateyarn install
Make sure to correctly configure your IDE by following the Editor SDKs guide.
These are some recommendations and hints on how to work with the project for optimal support during development through the IDEs.
Working on the overall architecture and TypeScript sourcecode works best by opening the library root directory with the IDE of you choice which supports TypeScript like VSCode, WebStorm or similar.
- Android Studio freely available on all platforms
- Open the
/examples/react-native-app/androiddirectory- Shows the library as
mlrnin the sourcetree - Shows the React Native example app as
appin the sourcetree
- Shows the library as
- You can rebuild the React Native Android example app directly from Android Studio, when you have changed Java/Kotlin code
- Xcode freely available on macOS
- Open the
/examples/react-native-app/ios/MapLibreReactNativeExample.xcworkspacefile- Shows the library as
Pods > Development Pods > maplibre-react-native - Shows the React Native example app as
MapLibreReactNativeExample
- Shows the library as
- You can rebuild the React Native iOS example app directly from Xcode, when you have changed Objective-C/Swift code
- For formatting Objective-C
clang-formatis configured- Xcode 16 supports
clang-formatout of the box - Alternatively install via homebrew and use
clang-format -i ios/MLRN/*
- Xcode 16 supports
The React Native and Expo example apps are set up
to use the library files in the root and the example scenes from /examples/shared. Therefore,
when using the start commands, changes to TypeScript code will be immediately refreshed. When changing native Android
or iOS code, it's necessary to rebuild the native dev clients.
This project uses yarn workspaces to accommodate the example apps. You can run yarn install form anywhere, which will
install dependencies for all
workspaces.
- To execute commands for the Expo app, you can run with
yarn examples:expo <script>- Alternatively switch to the
/examples/expo-appdirectory and use the commands without theexamples:expoprefix
- Alternatively switch to the
- Build and run a platform:
yarn examples:expo androidfor building and running Androidyarn examples:expo iosfor building and running iOS
- Starting the dev server
yarn examples:expo start - Purging all artifacts, if you want to create a clean build
yarn examples:expo purge
- To execute commands for the React Native app, you can run with
yarn examples:react-native <script>- Alternatively switch to the
/examples/react-native-appdirectory and use the commands without theexamples:react-nativeprefix
- Alternatively switch to the
- Build and run a platform:
- Building and running Android
yarn examples:react-native android - Building and running iOS
yarn examples:react-native ios:pod-install(necessary on first install/changes inPodfile)
yarn examples:react-native ios
- Building and running Android
- Starting the dev server
yarn examples:react-native start
Press one of the following keys:afor building and running Androidifor building and running iOS
- Purging all artifacts, if you want to create a clean build
yarn purge, which will run:yarn purge:jsyarn purge:androidyarn purge:ios
It's also possible to build and run the React Native app from Android Studio and Xcode, see IDEs.
The following steps are necessary to upgrade MapLibre Native for this library and the examples:
- Android
- Update the
org.maplibre.reactnative.nativeVersionproperty in/android/gradle.properties
- Update the
- iOS
- Update the
$MLRN_NATIVE_VERSIONvariable in/maplibre-react-native.podspec - Update the
XCRemoteSwiftPackageReference "maplibre-gl-native-distribution"version requirement in/examples/react-native-app/ios/MapLibreReactNativeExample.xcodeproj/project.pbxproj - Delete the
/examples/react-native-app/ios/MapLibreReactNativeExample.xcworkspace/xcshareddata/swiftpm/Package.resolvedfile - Run
yarn ios:pod-install - Build through Xcode
- The
/examples/react-native-app/ios/MapLibreReactNativeExample.xcworkspace/xcshareddata/swiftpm/Package.resolvedfile should have been regenerated
- Update the
- For both platforms update the version in
/docs/content/setup/getting-started.md
This library uses a strict linting setup enforced through TypeScript
and ESLint. Use yarn lint to run all linters.
The unit tests are implemented through Jest
and React Native Testing Library. They are found within
/src/__tests__. For these tests all native functionality should be mocked and only the TypeScript sourcecode
is tested. Run them with yarn test.
The end-to-end tests are implemented through Maestro in the React
Native example app. They are found within /examples/react-native-app/e2e. To run
them locally, install Maestro first. Then run the React
Native example app on Android emulator or iOS Simulator using yarn examples:react-native start. To execute the tests
run maestro test ./examples/react-native-app/e2e.
Documentation is generated from code blocks and comments. Run yarn codegen to generate the docs.
It's not feasible to edit the files within /docs/content/components or /docs/content/modules directly. Each file has a comment which notes from which file the doc was generated. To make a change,
update the TSDoc in the corresponding file and run yarn codegen again.
If you are about to implement something new or substantially change this library, consider to first open an issue to discuss the matter.
Make sure to use small concise commits with meaningful commit messages based on conventional commits. Please also name your PR following this schema, as we use semantic-release to automatically generate the CHANGELOG.
If you implemented a new feature, please add tests and demonstrate the functionality through adding a scene in
examples. Document your feature using the appropriate TSDoc comments.
Make sure, the checks on the pipeline pass, when creating a PR. See Testing on how to run these locally.
As this library needs a build step, it's discouraged to continuously develop against another app project and rather use the React Native or Expo example apps for fast, iterative development. The examples are set up to use the TypeScript source files without a build step, with updates through the dev server. But we encourage to test your changes after the initial development within you own app, allowing you to validate changes in a more complex use case.
The simplest approach is creating a Tarball .tgz,copying it to your project and installing from file. This has the
benefits that it should work in any environment like CI as well as eas build --local and also for other collaborators,
as it can be committed in your repository.
- Run
yarn pack --out %s-%v.tgzwithin the library
This will create a@maplibre-maplibre-react-native-X.X.X.tgzfile for latest version at the root of the library - Copy the file into your app project, you can choose any path or name
- Install from file
yarn add ./@maplibre-maplibre-react-native-X.X.X.tgzor similar command of the package manager of you choice
You can use commands like yarn link or
npm link or a comparable alternative of the package manager of your
choice.
Another alternative for link is using yalc.
Warning
When using link or yalc, you will have to run yarn prepack after changes to the TypeScript source code within
this library. A watch mode is not available through these approaches. For faster development, use the example apps.