diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java index 6e92af4df6..63e6d3d159 100644 --- a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java @@ -100,6 +100,9 @@ public void setProperty(T view, String propName, @Nullable Object value) { case "compassImage": mViewManager.setCompassImage(view, new DynamicFromObject(value)); break; + case "mapViewImpl": + mViewManager.setMapViewImpl(view, new DynamicFromObject(value)); + break; default: super.setProperty(view, propName, value); } diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java index 3f48245856..d6c1139a38 100644 --- a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java @@ -39,4 +39,5 @@ public interface RNMBXMapViewManagerInterface { void setAttributionViewMargins(T view, Dynamic value); void setAttributionViewPosition(T view, Dynamic value); void setCompassImage(T view, Dynamic value); + void setMapViewImpl(T view, Dynamic value); } diff --git a/ios/RNMBX/RNMBXMapView.swift b/ios/RNMBX/RNMBXMapView.swift index 215024f948..d45d24b2cd 100644 --- a/ios/RNMBX/RNMBXMapView.swift +++ b/ios/RNMBX/RNMBXMapView.swift @@ -2,6 +2,26 @@ import Turf import MapKit +public typealias RNMBXMapViewFactoryFunc = (String, UIView) -> MapView?; + +/** + * Experimental MapView factory for advanced usecases + */ +public class RNMBXMapViewFactory { + private static var factories: [String: RNMBXMapViewFactoryFunc] = [:]; + + static func get(_ id: String) -> RNMBXMapViewFactoryFunc? { + if let id = id.split(separator: ":", maxSplits: 1).first { + return factories[String(id)] + } + return nil + } + + public static func register(_ id: String, factory: @escaping RNMBXMapViewFactoryFunc) { + factories.updateValue(factory, forKey: id) + } +} + class FeatureEntry { let feature: RNMBXMapComponent let view: UIView @@ -132,6 +152,9 @@ open class RNMBXMapView: UIView { @objc public var deselectAnnotationOnTap: Bool = false + + @objc + public var mapViewImpl : String? = nil #if RNMBX_11 var cancelables = Set() @@ -149,19 +172,32 @@ open class RNMBXMapView: UIView { var _mapView: MapView! = nil func createMapView() { -#if RNMBX_11 - _mapView = MapView(frame: self.bounds, mapInitOptions: MapInitOptions()) -#else - let resourceOptions = ResourceOptions(accessToken: RNMBXModule.accessToken!) - _mapView = MapView(frame: frame, mapInitOptions: MapInitOptions(resourceOptions: resourceOptions)) -#endif - _mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - addSubview(_mapView) + if let mapViewImpl = mapViewImpl, let mapViewInstance = createAndAddMapViewImpl(mapViewImpl, self) { + _mapView = mapViewInstance + } else { + #if RNMBX_11 + _mapView = MapView(frame: self.bounds, mapInitOptions: MapInitOptions()) + #else + let resourceOptions = ResourceOptions(accessToken: RNMBXModule.accessToken!) + _mapView = MapView(frame: frame, mapInitOptions: MapInitOptions(resourceOptions: resourceOptions)) + #endif + _mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + addSubview(_mapView) + } _mapView.gestures.delegate = self setupEvents() } - + + func createAndAddMapViewImpl(_ impl: String, _ view: RNMBXMapView) -> MapView? { + if let factory = RNMBXMapViewFactory.get(impl) { + return factory(impl, view) as? MapView; + } else { + Logger.log(level:.error, message: "No mapview factory registered for: \(impl)") + return nil + } + } + var mapView : MapView! { get { return _mapView } } diff --git a/scripts/autogenHelpers/DocJSONBuilder.mjs b/scripts/autogenHelpers/DocJSONBuilder.mjs index 5beec38579..eb5439044e 100644 --- a/scripts/autogenHelpers/DocJSONBuilder.mjs +++ b/scripts/autogenHelpers/DocJSONBuilder.mjs @@ -55,12 +55,18 @@ class DocJSONBuilder { } postprocess(component, name) { - // Remove all private methods and parse examples from docblock + // Remove all private methods, and properties and parse examples from docblock if (!Array.isArray(component.methods)) { return; } + for (const [propName, prop] of Object.entries(component.props)) { + if (prop.description.includes('@private')) { + delete component.props[propName]; + } + } + component.name = name; // Main description diff --git a/src/components/MapView.tsx b/src/components/MapView.tsx index 36e1541f83..8aaa7ba96e 100644 --- a/src/components/MapView.tsx +++ b/src/components/MapView.tsx @@ -433,6 +433,11 @@ type Props = ViewProps & { * the onPress event for the taps that deselect the annotation. Default is false. */ deselectAnnotationOnTap?: boolean; + + /** + * @private Experimental support for custom MapView instances + */ + mapViewImpl?: string; }; type CallbablePropKeys = diff --git a/src/specs/RNMBXMapViewNativeComponent.ts b/src/specs/RNMBXMapViewNativeComponent.ts index 2804a63a7b..57cef9e6d8 100644 --- a/src/specs/RNMBXMapViewNativeComponent.ts +++ b/src/specs/RNMBXMapViewNativeComponent.ts @@ -76,6 +76,8 @@ export interface NativeProps extends ViewProps { onLongPress?: DirectEventHandler; onMapChange?: DirectEventHandler; onCameraChanged?: DirectEventHandler; + + mapViewImpl?: OptionalProp; } export default codegenNativeComponent(