mapbox-maps-android
mapbox-maps-android copied to clipboard
Official support for Jetpack Compose
This comes in a great combination with Mapbox v10's Kotlin first design.
Hey folks :wave: I played around with Compose to build an app and ran into this exact issue, too. The main question is how to adapt the imperative apis the map provides for a declarative world modern user interfaces are moving towards.
Ideally we'd have a declarative map wrapper taking a viewport from the parent component (composable), then
- the map component is stateless and its appearance only gets controlled by the properties passed in, and
- the viewport property acts as a single source of truth for the map's appearance throughout the app
The most basic use-case would then look like this on the call site
val (viewport, setViewport) = remember { mutableStateOf(initialViewport) }
Map(viewport = viewport, onViewportChange = setViewport)
I've built a declarative wrapper around the map for my own use case; you can find a very basic version here
https://gist.github.com/daniel-j-h/cd88b6cdf54e86bffed2bc440cbbb751
Side note: this is similar to https://github.com/visgl/react-map-gl (are we full circle yet :upside_down_face:) and it would be great to have support within this project, instead of smaller wrapper projects (like react-map-gl) popping up.
Compose is now stable
https://github.com/googlemaps/android-maps-compose
Take a look at this and copy/paste their solution ;-)
I've played around with building a Compose for Web wrapper around mapbox-gl-js. The implementation still needs work, but I think the general compose-level API design is decent.
The map is controlled through a MapboxState
object which, for example, allows the different camera methods to be called. The map's sources, layers, and styles are implemented as a separate compose tree in order to properly integrate with the Map's separate lifecycle and also maintains a nice DSL for constructing the map.
I haven't tried yet, but I'm sure the same kind of thing could be implemented with Jetpack Compose and the Android Maps SDK.
Any official updates regarding this?
Any official updates regarding this?
Hi, no updates at the moment.
Will this ever be possible to have a a Mapbox application without any XML layouts and AndroidView
s?
There is a prototype for a compose interface here
- https://github.com/mapbox/mapbox-maps-android/pull/1443
It looks like it hasn't moved in the last four months, tho.
Looking forward to seeing it being supported. Is there any timeline on official support for Jetpack Compose?
Waiting for the official support too!
We are also waiting for an update on this. Otherwise, we'll have to move on to another platform.
Is there any official to-do list or features backlog for the Jetpack Compose support?
It is not the official support, but @RomanBapst and I have been working on a small Jetpack Compose layer for Mapbox (and MapLibre) called ramani-maps. It is still fairly new, and we still have to solve some issues with Mapbox (e.g. this one, but for some use-cases that is not a problem).
For now we have only added features that we use ourselves, and we hope that it may be useful for others. We want to keep adding features steadily, and obviously we are open to contributions.
Some people here mentioned having to move to another platform if Compose doesn't come to Mapbox (we know there is work in progress), so we hope that maybe this helps bridging the gap.
The project is available on GitHub: https://github.com/ramani-maps/ramani-maps
Thanks for your patience. We're thrilled to unveil our first official Jetpack Compose Extension, now available for public preview. Your feedback is invaluable to us. Please share your thoughts so we can enhance the experience for everyone. Thank you!
Closing this issue for now, please feel free to open any Jetpack Compose related issues here with label compose
.