feat(ios): forward mapViewImpl prop so RNMBXMapViewFactory is usable on iOS - #4289
feat(ios): forward mapViewImpl prop so RNMBXMapViewFactory is usable on iOS#4289SamuelBrucksch wants to merge 1 commit into
Conversation
…on iOS RNMBXMapViewFactory.register is public and RNMBXMapView.createMapView() already prefers a factory-built MapView, but nothing assigned RNMBXMapView.mapViewImpl on iOS, so the hook could never be reached from JS. The prop is declared in the specs and forwarded on Android (RNMBXMapViewManager.setMapViewImpl), so this only brings iOS in line. Assigned before -didSetProps:, which is where createMapView() runs.
|
Some history I dug up while checking for duplicates — this is closer to a regression than a gap that was never filled:
Possibly related: #2728 ("Map aspect ratio broken inside CarPlay on iOS", also reported for an external monitor) was closed as not-planned for lack of resources. That class of problem comes from the map being initialised with the main screen's scale — For completeness: no open issue tracks this. I searched the repo for |
Description
Makes the existing
RNMBXMapViewFactoryhook reachable on iOS.RNMBXMapViewFactory.register(_:factory:)is public API, andRNMBXMapView.createMapView()already prefers a factory-builtMapViewwhenmapViewImplis set:But nothing ever assigned
RNMBXMapView.mapViewImplon iOS, so that branch was unreachable from JS and everymapViewImplvalue fell through to the defaultMapView. The prop is declared insrc/specs/RNMBXMapViewNativeComponent.tsand on the JS component, and it is forwarded on Android (RNMBXMapViewManager.setMapViewImpl) — this only brings iOS in line, so it's a missing-functionality fix rather than a behaviour change.The assignment is placed before
[_view didSetProps:@[]], since that is wherecreateMapView()runs.Why this is useful
The factory is the only way to control
MapInitOptionsfrom an app, which matters for things the props don't cover — in our caseMapOptions.pixelRatio.MapboxMapsdefaults it toUIScreen.main.nativeScaleand sizes the Metal drawable asbounds * pixelRatio, so a CarPlay map renders at the phone's scale (3.0) on a head unit that only has ~1.88 px/pt — ~2.5x the pixels per frame, discarded by the compositor. With this prop forwarded, the app can register a factory that builds theMapViewwith the car screen's pixel ratio; no library change beyond this is needed.Checklist
CONTRIBUTING.mdyarn generatein the root folder@privateinMapView.tsx, so it is not part of the generated docs/exampleapp./example)How it was verified
Not via
/example— verified in a production app (RN 0.86, New Architecture, iOS,@rnmapbox/maps10.3.2 with this change applied throughpatch-package):before: a
MapViewwithmapViewImpl="…"silently used the defaultMapView; the registered factory closure was never invoked (andcreateAndAddMapViewImpl's "No mapview factory registered" error never fired either, sincemapViewImplwasnilat that point).after: the factory closure runs for every CarPlay surface and the returned
MapViewis the one used. Log line from the factory, on a real head unit connection:and the Metal drawable then matches the head unit's resolution instead of ~1.6x it.
Happy to add an
/examplescene for it if you'd like — it needs a factory registration in the example app'sAppDelegatesince the hook is native-only, so I left that out of this PR unless you want it.🤖 Prepared by Devin on behalf of @SamuelBrucksch.