diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/EventHandler.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/EventHandler.kt index 413da106..67454dad 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/EventHandler.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/EventHandler.kt @@ -37,7 +37,8 @@ import java.util.Date class MapboxEventHandler( private val eventProvider: Observable, binaryMessenger: BinaryMessenger, - eventTypes: List + eventTypes: List, + channelSuffix: String, ) : MethodChannel.MethodCallHandler { private val channel: MethodChannel private val cancellables = HashSet() @@ -47,7 +48,8 @@ class MapboxEventHandler( .create() init { - channel = MethodChannel(binaryMessenger, "com.mapbox.maps.flutter.map_events") + val pigeon_channelSuffix = if (channelSuffix.isNotEmpty()) ".$channelSuffix" else "" + channel = MethodChannel(binaryMessenger, "com.mapbox.maps.flutter.map_events$pigeon_channelSuffix") channel.setMethodCallHandler(this) eventTypes.mapNotNull { _MapEvent.ofRaw(it.toInt()) } diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/GestureController.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/GestureController.kt index 1c63fea4..dc7b084a 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/GestureController.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/GestureController.kt @@ -32,8 +32,8 @@ class GestureController(private val mapView: MapView, private val context: Conte private var onLongClickListener: OnMapLongClickListener? = null private var onMoveListener: OnMoveListener? = null - fun addListeners(messenger: BinaryMessenger) { - fltGestureListener = GestureListener(messenger) + fun addListeners(messenger: BinaryMessenger, channelSuffix: String) { + fltGestureListener = GestureListener(messenger, channelSuffix) removeListeners() diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt index 11fbe486..acb4f829 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt @@ -47,7 +47,11 @@ class MapboxMapController( private var mapView: MapView? = null private var mapboxMap: MapboxMap? = null + private val methodChannel: MethodChannel + private val messenger: BinaryMessenger + private val channelSuffix: String + private val styleController: StyleController private val cameraController: CameraController private val projectionController: MapProjectionController @@ -61,7 +65,6 @@ class MapboxMapController( private val scaleBarController: ScaleBarController private val compassController: CompassController - private val proxyBinaryMessenger = ProxyBinaryMessenger(messenger, "$channelSuffix") private val eventHandler: MapboxEventHandler /* @@ -122,11 +125,14 @@ class MapboxMapController( private var lifecycleHelper: LifecycleHelper? = null init { + this.messenger = messenger + this.channelSuffix = channelSuffix.toString() + val mapView = MapView(context, mapInitOptions) val mapboxMap = mapView.mapboxMap this.mapView = mapView this.mapboxMap = mapboxMap - eventHandler = MapboxEventHandler(mapboxMap.styleManager, proxyBinaryMessenger, eventTypes) + eventHandler = MapboxEventHandler(mapboxMap.styleManager, messenger, eventTypes, this.channelSuffix) styleController = StyleController(context, mapboxMap) cameraController = CameraController(mapboxMap, context) projectionController = MapProjectionController(mapboxMap) @@ -142,20 +148,20 @@ class MapboxMapController( changeUserAgent(pluginVersion) - StyleManager.setUp(proxyBinaryMessenger, styleController) - _CameraManager.setUp(proxyBinaryMessenger, cameraController) - Projection.setUp(proxyBinaryMessenger, projectionController) - _MapInterface.setUp(proxyBinaryMessenger, mapInterfaceController) - _AnimationManager.setUp(proxyBinaryMessenger, animationController) - annotationController.setup(proxyBinaryMessenger) - _LocationComponentSettingsInterface.setUp(proxyBinaryMessenger, locationComponentController) - LogoSettingsInterface.setUp(proxyBinaryMessenger, logoController) - GesturesSettingsInterface.setUp(proxyBinaryMessenger, gestureController) - AttributionSettingsInterface.setUp(proxyBinaryMessenger, attributionController) - ScaleBarSettingsInterface.setUp(proxyBinaryMessenger, scaleBarController) - CompassSettingsInterface.setUp(proxyBinaryMessenger, compassController) - - methodChannel = MethodChannel(proxyBinaryMessenger, "plugins.flutter.io") + StyleManager.setUp(messenger, styleController, this.channelSuffix) + _CameraManager.setUp(messenger, cameraController, this.channelSuffix) + Projection.setUp(messenger, projectionController, this.channelSuffix) + _MapInterface.setUp(messenger, mapInterfaceController, this.channelSuffix) + _AnimationManager.setUp(messenger, animationController, this.channelSuffix) + annotationController.setup(messenger, this.channelSuffix) + _LocationComponentSettingsInterface.setUp(messenger, locationComponentController, this.channelSuffix) + LogoSettingsInterface.setUp(messenger, logoController, this.channelSuffix) + GesturesSettingsInterface.setUp(messenger, gestureController, this.channelSuffix) + AttributionSettingsInterface.setUp(messenger, attributionController, this.channelSuffix) + ScaleBarSettingsInterface.setUp(messenger, scaleBarController, this.channelSuffix) + CompassSettingsInterface.setUp(messenger, compassController, this.channelSuffix) + + methodChannel = MethodChannel(messenger, "plugins.flutter.io.$channelSuffix") methodChannel.setMethodCallHandler(this) } @@ -191,18 +197,18 @@ class MapboxMapController( mapView = null mapboxMap = null methodChannel.setMethodCallHandler(null) - StyleManager.setUp(proxyBinaryMessenger, null) - _CameraManager.setUp(proxyBinaryMessenger, null) - Projection.setUp(proxyBinaryMessenger, null) - _MapInterface.setUp(proxyBinaryMessenger, null) - _AnimationManager.setUp(proxyBinaryMessenger, null) - annotationController.dispose(proxyBinaryMessenger) - _LocationComponentSettingsInterface.setUp(proxyBinaryMessenger, null) - LogoSettingsInterface.setUp(proxyBinaryMessenger, null) - GesturesSettingsInterface.setUp(proxyBinaryMessenger, null) - CompassSettingsInterface.setUp(proxyBinaryMessenger, null) - ScaleBarSettingsInterface.setUp(proxyBinaryMessenger, null) - AttributionSettingsInterface.setUp(proxyBinaryMessenger, null) + StyleManager.setUp(messenger, null, channelSuffix) + _CameraManager.setUp(messenger, null, channelSuffix) + Projection.setUp(messenger, null, channelSuffix) + _MapInterface.setUp(messenger, null, channelSuffix) + _AnimationManager.setUp(messenger, null, channelSuffix) + annotationController.dispose(messenger, channelSuffix) + _LocationComponentSettingsInterface.setUp(messenger, null, channelSuffix) + LogoSettingsInterface.setUp(messenger, null, channelSuffix) + GesturesSettingsInterface.setUp(messenger, null, channelSuffix) + CompassSettingsInterface.setUp(messenger, null, channelSuffix) + ScaleBarSettingsInterface.setUp(messenger, null, channelSuffix) + AttributionSettingsInterface.setUp(messenger, null, channelSuffix) } override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { @@ -214,7 +220,7 @@ class MapboxMapController( annotationController.handleRemoveManager(call, result) } "gesture#add_listeners" -> { - gestureController.addListeners(proxyBinaryMessenger) + gestureController.addListeners(messenger, channelSuffix) result.success(null) } "gesture#remove_listeners" -> { diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/ProxyBinaryMessenger.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/ProxyBinaryMessenger.kt deleted file mode 100644 index 3e8b9091..00000000 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/ProxyBinaryMessenger.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.mapbox.maps.mapbox_maps - -import io.flutter.plugin.common.BinaryMessenger -import java.nio.ByteBuffer - -// BinaryMessenger that proxies all calls to another BinaryMessenger, -// but with a suffix appended to the channel name. -// Different map instances use different suffixes to avoid channel name conflicts. -class ProxyBinaryMessenger( - private val messenger: BinaryMessenger, - private val nameSuffix: String, -) : BinaryMessenger { - - private fun String.appendSuffix() = "$this$nameSuffix" - - override fun send(channel: String, message: ByteBuffer?) { - messenger.send(channel.appendSuffix(), message) - } - - override fun send(channel: String, message: ByteBuffer?, callback: BinaryMessenger.BinaryReply?) { - messenger.send(channel.appendSuffix(), message, callback) - } - - override fun setMessageHandler(channel: String, handler: BinaryMessenger.BinaryMessageHandler?) { - messenger.setMessageHandler(channel.appendSuffix(), handler) - } -} \ No newline at end of file diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/AnnotationController.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/AnnotationController.kt index b38cb68a..14a16bc6 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/AnnotationController.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/AnnotationController.kt @@ -22,10 +22,10 @@ class AnnotationController(private val mapView: MapView) : private val circleAnnotationController = CircleAnnotationController(this) private val polygonAnnotationController = PolygonAnnotationController(this) private val polylineAnnotationController = PolylineAnnotationController(this) - private lateinit var onPointAnnotationClickListener: OnPointAnnotationClickListener - private lateinit var onPolygonAnnotationClickListener: OnPolygonAnnotationClickListener - private lateinit var onPolylineAnnotationController: OnPolylineAnnotationClickListener - private lateinit var onCircleAnnotationClickListener: OnCircleAnnotationClickListener + private var onPointAnnotationClickListener: OnPointAnnotationClickListener? = null + private var onPolygonAnnotationClickListener: OnPolygonAnnotationClickListener? = null + private var onPolylineAnnotationClickListener: OnPolylineAnnotationClickListener? = null + private var onCircleAnnotationClickListener: OnCircleAnnotationClickListener? = null private var index = 0 fun handleCreateManager(call: MethodCall, result: MethodChannel.Result) { val id = call.argument("id") ?: (index++).toString() @@ -41,7 +41,7 @@ class AnnotationController(private val mapView: MapView) : mapView.annotations.createCircleAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply { this.addClickListener( com.mapbox.maps.plugin.annotation.generated.OnCircleAnnotationClickListener { annotation -> - onCircleAnnotationClickListener.onCircleAnnotationClick(annotation.toFLTCircleAnnotation()) {} + onCircleAnnotationClickListener?.onCircleAnnotationClick(annotation.toFLTCircleAnnotation()) {} true } ) @@ -51,7 +51,7 @@ class AnnotationController(private val mapView: MapView) : mapView.annotations.createPointAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply { this.addClickListener( com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationClickListener { annotation -> - onPointAnnotationClickListener.onPointAnnotationClick(annotation.toFLTPointAnnotation()) {} + onPointAnnotationClickListener?.onPointAnnotationClick(annotation.toFLTPointAnnotation()) {} true } ) @@ -61,7 +61,7 @@ class AnnotationController(private val mapView: MapView) : mapView.annotations.createPolygonAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply { this.addClickListener( com.mapbox.maps.plugin.annotation.generated.OnPolygonAnnotationClickListener { annotation -> - onPolygonAnnotationClickListener.onPolygonAnnotationClick(annotation.toFLTPolygonAnnotation()) {} + onPolygonAnnotationClickListener?.onPolygonAnnotationClick(annotation.toFLTPolygonAnnotation()) {} true } ) @@ -71,7 +71,7 @@ class AnnotationController(private val mapView: MapView) : mapView.annotations.createPolylineAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply { this.addClickListener( com.mapbox.maps.plugin.annotation.generated.OnPolylineAnnotationClickListener { annotation -> - onPolylineAnnotationController.onPolylineAnnotationClick(annotation.toFLTPolylineAnnotation()) {} + onPolylineAnnotationClickListener?.onPolylineAnnotationClick(annotation.toFLTPolylineAnnotation()) {} true } ) @@ -94,31 +94,35 @@ class AnnotationController(private val mapView: MapView) : result.success(null) } - fun setup(messenger: BinaryMessenger) { - onPointAnnotationClickListener = OnPointAnnotationClickListener(messenger) - onCircleAnnotationClickListener = OnCircleAnnotationClickListener(messenger) - onPolygonAnnotationClickListener = OnPolygonAnnotationClickListener(messenger) - onPolylineAnnotationController = OnPolylineAnnotationClickListener(messenger) - _PointAnnotationMessenger.setUp(messenger, pointAnnotationController) + fun setup(messenger: BinaryMessenger, channelSuffix: String) { + onPointAnnotationClickListener = OnPointAnnotationClickListener(messenger, channelSuffix) + onCircleAnnotationClickListener = OnCircleAnnotationClickListener(messenger, channelSuffix) + onPolygonAnnotationClickListener = OnPolygonAnnotationClickListener(messenger, channelSuffix) + onPolylineAnnotationClickListener = OnPolylineAnnotationClickListener(messenger, channelSuffix) + _PointAnnotationMessenger.setUp(messenger, pointAnnotationController, channelSuffix) _CircleAnnotationMessenger.setUp( messenger, - circleAnnotationController + circleAnnotationController, channelSuffix ) _PolylineAnnotationMessenger.setUp( messenger, - polylineAnnotationController + polylineAnnotationController, channelSuffix ) _PolygonAnnotationMessenger.setUp( messenger, - polygonAnnotationController + polygonAnnotationController, channelSuffix ) } - fun dispose(messenger: BinaryMessenger) { - _PointAnnotationMessenger.setUp(messenger, null) - _CircleAnnotationMessenger.setUp(messenger, null) - _PolylineAnnotationMessenger.setUp(messenger, null) - _PolygonAnnotationMessenger.setUp(messenger, null) + fun dispose(messenger: BinaryMessenger, channelSuffix: String) { + _PointAnnotationMessenger.setUp(messenger, null, channelSuffix) + _CircleAnnotationMessenger.setUp(messenger, null, channelSuffix) + _PolylineAnnotationMessenger.setUp(messenger, null, channelSuffix) + _PolygonAnnotationMessenger.setUp(messenger, null, channelSuffix) + onPointAnnotationClickListener = null + onCircleAnnotationClickListener = null + onPolygonAnnotationClickListener = null + onPolylineAnnotationClickListener = null } override fun getManager(managerId: String): AnnotationManager<*, *, *, *, *, *, *> { diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineController.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineController.kt index 4496232b..0518f2cb 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineController.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineController.kt @@ -13,11 +13,10 @@ import io.flutter.plugin.common.BinaryMessenger import io.flutter.plugin.common.EventChannel import io.flutter.plugin.common.EventChannel.StreamHandler -private const val EVENT_CHANNEL_PREFIX = "com.mapbox.maps.flutter/offline" - class OfflineController( private val context: Context, - private val messenger: BinaryMessenger + private val messenger: BinaryMessenger, + private val channelSuffix: String, ) : _OfflineManager { private val offlineManager = OfflineManager() @@ -57,7 +56,7 @@ class OfflineController( } override fun addStylePackLoadProgressListener(styleURI: String) { - val eventChannel = EventChannel(messenger, "com.mapbox.maps.flutter/offline/$styleURI") + val eventChannel = EventChannel(messenger, "com.mapbox.maps.flutter/$channelSuffix/$styleURI") eventChannel.setStreamHandler( object : StreamHandler { override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineMapInstanceManager.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineMapInstanceManager.kt index 453cc678..b9ce6997 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineMapInstanceManager.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineMapInstanceManager.kt @@ -3,7 +3,6 @@ package com.mapbox.maps.mapbox_maps.offline import android.content.Context import com.mapbox.common.TileStore import com.mapbox.maps.MapboxMapsOptions -import com.mapbox.maps.mapbox_maps.ProxyBinaryMessenger import com.mapbox.maps.mapbox_maps.pigeons.* import io.flutter.plugin.common.BinaryMessenger @@ -12,31 +11,24 @@ class OfflineMapInstanceManager( private val messenger: BinaryMessenger, ) : _OfflineMapInstanceManager, _TileStoreInstanceManager { - private var proxies = HashMap() override fun setupOfflineManager(channelSuffix: String) { - val proxy = ProxyBinaryMessenger(messenger, channelSuffix) - val offlineControler = OfflineController(context, messenger) - _OfflineManager.setUp(proxy, offlineControler) - proxies["offline-manager/$channelSuffix"] = proxy + val offlineControler = OfflineController(context, messenger, channelSuffix) + _OfflineManager.setUp(messenger, offlineControler, channelSuffix) } override fun tearDownOfflineManager(channelSuffix: String) { - val proxy = proxies["offline-manager/$channelSuffix"] ?: return - _OfflineManager.setUp(proxy, null) + _OfflineManager.setUp(messenger, null, channelSuffix) } override fun setupTileStore(channelSuffix: String, filePath: String?) { - val proxy = ProxyBinaryMessenger(messenger, channelSuffix) val tileStore = filePath?.let { TileStore.create(it) } ?: TileStore.create() MapboxMapsOptions.tileStore = tileStore - val tileStoreController = TileStoreController(context, messenger, tileStore) - _TileStore.setUp(proxy, tileStoreController) - proxies["tilestore/$channelSuffix"] = proxy + val tileStoreController = TileStoreController(context, messenger, channelSuffix, tileStore) + _TileStore.setUp(messenger, tileStoreController, channelSuffix) } override fun tearDownTileStore(channelSuffix: String) { - val proxy = proxies["tilestore/$channelSuffix"] ?: return - _TileStore.setUp(proxy, null) + _TileStore.setUp(messenger, null, channelSuffix) MapboxMapsOptions.tileStore = null } } \ No newline at end of file diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/TileStoreController.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/TileStoreController.kt index 95f28cbf..b86a2ee8 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/TileStoreController.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/TileStoreController.kt @@ -26,6 +26,7 @@ private const val EVENT_CHANNEL_PREFIX = "com.mapbox.maps.flutter/tilestore" class TileStoreController( private val context: Context, private val binaryMessenger: BinaryMessenger, + private val channelSuffix: String, private val tileStore: TileStore ) : _TileStore { @@ -56,7 +57,7 @@ class TileStoreController( } override fun addTileRegionLoadProgressListener(id: String) { - val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/tilestore/tile-region-$id") + val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/$channelSuffix/tile-region-$id") eventChannel.setStreamHandler( object : EventChannel.StreamHandler { override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { @@ -96,7 +97,7 @@ class TileStoreController( } override fun addTileRegionEstimateProgressListener(id: String) { - val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/tilestore/tile-region-estimate$id") + val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/$channelSuffix/tile-region-estimate$id") eventChannel.setStreamHandler( object : EventChannel.StreamHandler { override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { diff --git a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/snapshotter/SnapshotterInstanceManager.kt b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/snapshotter/SnapshotterInstanceManager.kt index 4805e1fe..dc5513d6 100644 --- a/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/snapshotter/SnapshotterInstanceManager.kt +++ b/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/snapshotter/SnapshotterInstanceManager.kt @@ -5,7 +5,6 @@ import android.content.Context import com.mapbox.maps.MapboxStyleManager import com.mapbox.maps.Snapshotter import com.mapbox.maps.mapbox_maps.MapboxEventHandler -import com.mapbox.maps.mapbox_maps.ProxyBinaryMessenger import com.mapbox.maps.mapbox_maps.StyleController import com.mapbox.maps.mapbox_maps.pigeons.MapSnapshotOptions import com.mapbox.maps.mapbox_maps.pigeons.StyleManager @@ -21,8 +20,6 @@ class SnapshotterInstanceManager( private val messenger: BinaryMessenger, ) : _SnapshotterInstanceManager { - private var proxyMessengers = HashMap() - @SuppressLint("RestrictedApi") override fun setupSnapshotterForSuffix( suffix: String, @@ -34,9 +31,8 @@ class SnapshotterInstanceManager( options = options.toSnapshotOptions(context), overlayOptions = options.toSnapshotOverlayOptions() ) - val proxyBinaryMessenger = ProxyBinaryMessenger(messenger, suffix) val styleManager: com.mapbox.maps.StyleManager = snapshotter.styleManager() // TODO: expose this on Android - val eventHandler = MapboxEventHandler(styleManager, proxyBinaryMessenger, eventTypes.map { it }) + val eventHandler = MapboxEventHandler(styleManager, messenger, eventTypes.map { it }, suffix) val snapshotterController = SnapshotterController(context, snapshotter, eventHandler) val mapboxStyleManager = MapboxStyleManager( styleManager, @@ -45,16 +41,12 @@ class SnapshotterInstanceManager( ) val snapshotterStyleController = StyleController(context, mapboxStyleManager) - _SnapshotterMessenger.setUp(proxyBinaryMessenger, snapshotterController) - StyleManager.setUp(proxyBinaryMessenger, snapshotterStyleController) - - proxyMessengers[suffix] = proxyBinaryMessenger + _SnapshotterMessenger.setUp(messenger, snapshotterController, suffix) + StyleManager.setUp(messenger, snapshotterStyleController, suffix) } override fun tearDownSnapshotterForSuffix(suffix: String) { - val proxyBinaryMessenger = proxyMessengers[suffix] ?: return - - _SnapshotterMessenger.setUp(proxyBinaryMessenger, null) - StyleManager.setUp(proxyBinaryMessenger, null) + _SnapshotterMessenger.setUp(messenger, null, suffix) + StyleManager.setUp(messenger, null, suffix) } } \ No newline at end of file diff --git a/ios/Classes/AnnotationController.swift b/ios/Classes/AnnotationController.swift index fc9d9350..b2d92589 100644 --- a/ios/Classes/AnnotationController.swift +++ b/ios/Classes/AnnotationController.swift @@ -122,22 +122,22 @@ class AnnotationController: ControllerDelegate { result(nil) } - func setup(messenger: FlutterBinaryMessenger) { - _CircleAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: circleAnnotationController) - _PointAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: pointAnnotationController) - _PolygonAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: polygonAnnotationController) - _PolylineAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: polylineAnnotationController) - onPointAnnotationClickListener = OnPointAnnotationClickListener(binaryMessenger: messenger) - onCircleAnnotationClickListener = OnCircleAnnotationClickListener(binaryMessenger: messenger) - onPolygonAnnotationClickListener = OnPolygonAnnotationClickListener(binaryMessenger: messenger) - onPolylineAnnotationClickListener = OnPolylineAnnotationClickListener(binaryMessenger: messenger) + func setup(binaryMessenger: SuffixBinaryMessenger) { + _CircleAnnotationMessengerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: circleAnnotationController, messageChannelSuffix: binaryMessenger.suffix) + _PointAnnotationMessengerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: pointAnnotationController, messageChannelSuffix: binaryMessenger.suffix) + _PolygonAnnotationMessengerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: polygonAnnotationController, messageChannelSuffix: binaryMessenger.suffix) + _PolylineAnnotationMessengerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: polylineAnnotationController, messageChannelSuffix: binaryMessenger.suffix) + onPointAnnotationClickListener = OnPointAnnotationClickListener(binaryMessenger: binaryMessenger.messenger, messageChannelSuffix: binaryMessenger.suffix) + onCircleAnnotationClickListener = OnCircleAnnotationClickListener(binaryMessenger: binaryMessenger.messenger, messageChannelSuffix: binaryMessenger.suffix) + onPolygonAnnotationClickListener = OnPolygonAnnotationClickListener(binaryMessenger: binaryMessenger.messenger, messageChannelSuffix: binaryMessenger.suffix) + onPolylineAnnotationClickListener = OnPolylineAnnotationClickListener(binaryMessenger: binaryMessenger.messenger, messageChannelSuffix: binaryMessenger.suffix) } - func tearDown(messenger: FlutterBinaryMessenger) { - _CircleAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: nil) - _PointAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: nil) - _PolygonAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: nil) - _PolylineAnnotationMessengerSetup.setUp(binaryMessenger: messenger, api: nil) + func tearDown(messenger: SuffixBinaryMessenger) { + _CircleAnnotationMessengerSetup.setUp(binaryMessenger: messenger.messenger, api: nil, messageChannelSuffix: messenger.suffix) + _PointAnnotationMessengerSetup.setUp(binaryMessenger: messenger.messenger, api: nil, messageChannelSuffix: messenger.suffix) + _PolygonAnnotationMessengerSetup.setUp(binaryMessenger: messenger.messenger, api: nil, messageChannelSuffix: messenger.suffix) + _PolylineAnnotationMessengerSetup.setUp(binaryMessenger: messenger.messenger, api: nil, messageChannelSuffix: messenger.suffix) onPointAnnotationClickListener = nil onCircleAnnotationClickListener = nil onPolygonAnnotationClickListener = nil diff --git a/ios/Classes/EventHandler.swift b/ios/Classes/EventHandler.swift index 2d8bea61..d988acd3 100644 --- a/ios/Classes/EventHandler.swift +++ b/ios/Classes/EventHandler.swift @@ -45,12 +45,13 @@ final class MapboxEventHandler { private let channel: FlutterMethodChannel private var cancelables = Set() - init(eventProvider: EventProvider, binaryMessenger: FlutterBinaryMessenger, eventTypes: [Int]) { + init(eventProvider: EventProvider, binaryMessenger: FlutterBinaryMessenger, eventTypes: [Int], channelSuffix: String) { self.eventProvider = eventProvider self.binaryMessenger = binaryMessenger + let channelSuffix = channelSuffix.isEmpty ? "" : ".\(channelSuffix)" channel = FlutterMethodChannel( - name: "com.mapbox.maps.flutter.map_events", + name: "com.mapbox.maps.flutter.map_events\(channelSuffix)", binaryMessenger: binaryMessenger ) channel.setMethodCallHandler { [weak self] methodCall, result in diff --git a/ios/Classes/GesturesController.swift b/ios/Classes/GesturesController.swift index b6350243..06f2d6f7 100644 --- a/ios/Classes/GesturesController.swift +++ b/ios/Classes/GesturesController.swift @@ -106,11 +106,11 @@ final class GesturesController: NSObject, GesturesSettingsInterface, UIGestureRe ) } - func addListeners(messenger: FlutterBinaryMessenger) { + func addListeners(messenger: SuffixBinaryMessenger) { removeListeners() mapView.gestures.panGestureRecognizer.addTarget(self, action: #selector(onMapPan)) - onGestureListener = GestureListener(binaryMessenger: messenger) + onGestureListener = GestureListener(binaryMessenger: messenger.messenger, messageChannelSuffix: messenger.suffix) mapView.gestures.onMapTap.observe { [weak self] context in guard let self else { return } diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 1dc33e4a..f5e88d8c 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -2,42 +2,19 @@ import Flutter @_spi(Experimental) import MapboxMaps import UIKit -class ProxyBinaryMessenger: NSObject, FlutterBinaryMessenger { - - let channelSuffix: String +struct SuffixBinaryMessenger { let messenger: FlutterBinaryMessenger - - init(with messenger: FlutterBinaryMessenger, channelSuffix: String) { - self.messenger = messenger - self.channelSuffix = channelSuffix - } - - func send(onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply? = nil) { - messenger.send(onChannel: "\(channel)\(channelSuffix)", message: message, binaryReply: callback) - } - - func send(onChannel channel: String, message: Data?) { - messenger.send(onChannel: "\(channel)\(channelSuffix)", message: message) - } - - func setMessageHandlerOnChannel(_ channel: String, binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil) -> FlutterBinaryMessengerConnection { - messenger.setMessageHandlerOnChannel("\(channel)\(channelSuffix)", binaryMessageHandler: handler) - } - - func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) { - messenger.cleanUpConnection(connection) - } + let suffix: String } final class MapboxMapController: NSObject, FlutterPlatformView { - private let registrar: FlutterPluginRegistrar private let mapView: MapView private let mapboxMap: MapboxMap private let channel: FlutterMethodChannel private let annotationController: AnnotationController? private let gesturesController: GesturesController? - private let proxyBinaryMessenger: ProxyBinaryMessenger private let eventHandler: MapboxEventHandler + private let binaryMessenger: SuffixBinaryMessenger func view() -> UIView { return mapView @@ -47,65 +24,63 @@ final class MapboxMapController: NSObject, FlutterPlatformView { withFrame frame: CGRect, mapInitOptions: MapInitOptions, channelSuffix: Int, - arguments args: Any?, registrar: FlutterPluginRegistrar, pluginVersion: String, eventTypes: [Int] ) { - self.proxyBinaryMessenger = ProxyBinaryMessenger(with: registrar.messenger(), channelSuffix: "\(channelSuffix)") + binaryMessenger = SuffixBinaryMessenger(messenger: registrar.messenger(), suffix: String(channelSuffix)) _ = SettingsServiceFactory.getInstanceFor(.nonPersistent) .set(key: "com.mapbox.common.telemetry.internal.custom_user_agent_fragment", value: "FlutterPlugin/\(pluginVersion)") mapView = MapView(frame: frame, mapInitOptions: mapInitOptions) mapboxMap = mapView.mapboxMap - self.registrar = registrar - channel = FlutterMethodChannel( - name: "plugins.flutter.io", - binaryMessenger: proxyBinaryMessenger + name: "plugins.flutter.io.\(channelSuffix)", + binaryMessenger: binaryMessenger.messenger ) self.eventHandler = MapboxEventHandler( eventProvider: mapboxMap, - binaryMessenger: proxyBinaryMessenger, - eventTypes: eventTypes + binaryMessenger: binaryMessenger.messenger, + eventTypes: eventTypes, + channelSuffix: String(channelSuffix) ) let styleController = StyleController(styleManager: mapboxMap) - StyleManagerSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: styleController) + StyleManagerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: styleController, messageChannelSuffix: binaryMessenger.suffix) let cameraController = CameraController(withMapboxMap: mapboxMap) - _CameraManagerSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: cameraController) + _CameraManagerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: cameraController, messageChannelSuffix: binaryMessenger.suffix) let mapInterfaceController = MapInterfaceController(withMapboxMap: mapboxMap, mapView: mapView) - _MapInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: mapInterfaceController) + _MapInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: mapInterfaceController, messageChannelSuffix: binaryMessenger.suffix) let mapProjectionController = MapProjectionController() - ProjectionSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: mapProjectionController) + ProjectionSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: mapProjectionController, messageChannelSuffix: binaryMessenger.suffix) let animationController = AnimationController(withMapView: mapView) - _AnimationManagerSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: animationController) + _AnimationManagerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: animationController, messageChannelSuffix: binaryMessenger.suffix) let locationController = LocationController(withMapView: mapView) - _LocationComponentSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: locationController) + _LocationComponentSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: locationController, messageChannelSuffix: binaryMessenger.suffix) gesturesController = GesturesController(withMapView: mapView) - GesturesSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: gesturesController) + GesturesSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: gesturesController, messageChannelSuffix: binaryMessenger.suffix) let logoController = LogoController(withMapView: mapView) - LogoSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: logoController) + LogoSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: logoController, messageChannelSuffix: binaryMessenger.suffix) let attributionController = AttributionController(withMapView: mapView) - AttributionSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: attributionController) + AttributionSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: attributionController, messageChannelSuffix: binaryMessenger.suffix) let compassController = CompassController(withMapView: mapView) - CompassSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: compassController) + CompassSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: compassController, messageChannelSuffix: binaryMessenger.suffix) let scaleBarController = ScaleBarController(withMapView: mapView) - ScaleBarSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: scaleBarController) + ScaleBarSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: scaleBarController, messageChannelSuffix: binaryMessenger.suffix) annotationController = AnnotationController(withMapView: mapView) - annotationController!.setup(messenger: proxyBinaryMessenger) + annotationController!.setup(binaryMessenger: binaryMessenger) super.init() @@ -119,7 +94,7 @@ final class MapboxMapController: NSObject, FlutterPlatformView { case "annotation#remove_manager": annotationController!.handleRemoveManager(methodCall: methodCall, result: result) case "gesture#add_listeners": - gesturesController!.addListeners(messenger: proxyBinaryMessenger) + gesturesController!.addListeners(messenger: binaryMessenger) result(nil) case "gesture#remove_listeners": gesturesController!.removeListeners() @@ -141,17 +116,17 @@ final class MapboxMapController: NSObject, FlutterPlatformView { private func releaseMethodChannels() { channel.setMethodCallHandler(nil) - StyleManagerSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - _CameraManagerSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - _MapInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - ProjectionSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - _AnimationManagerSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - _LocationComponentSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - GesturesSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - LogoSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - AttributionSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - CompassSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - ScaleBarSettingsInterfaceSetup.setUp(binaryMessenger: proxyBinaryMessenger, api: nil) - annotationController?.tearDown(messenger: proxyBinaryMessenger) + StyleManagerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + _CameraManagerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + _MapInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + ProjectionSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + _AnimationManagerSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + _LocationComponentSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + GesturesSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + LogoSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + AttributionSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + CompassSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + ScaleBarSettingsInterfaceSetup.setUp(binaryMessenger: binaryMessenger.messenger, api: nil, messageChannelSuffix: binaryMessenger.suffix) + annotationController?.tearDown(messenger: binaryMessenger) } } diff --git a/ios/Classes/MapboxMapFactory.swift b/ios/Classes/MapboxMapFactory.swift index 16252ed2..2eacebc6 100644 --- a/ios/Classes/MapboxMapFactory.swift +++ b/ios/Classes/MapboxMapFactory.swift @@ -27,53 +27,35 @@ final class MapboxMapFactory: NSObject, FlutterPlatformViewFactory { arguments args: Any? ) -> FlutterPlatformView { - var mapInitOptions = MapInitOptions() - var pluginVersion = "" - var channelSuffix = 0 - guard let args = args as? [String: Any] else { return MapboxMapController( withFrame: frame, - mapInitOptions: mapInitOptions, - channelSuffix: channelSuffix, - arguments: args, + mapInitOptions: MapInitOptions(), + channelSuffix: 0, registrar: registrar, - pluginVersion: pluginVersion, + pluginVersion: "", eventTypes: [] ) } - var styleURI: StyleURI? = .streets - if let styleURIString = args["styleUri"] as? String { - styleURI = StyleURI(rawValue: styleURIString) - } + + let styleURI = (args["styleUri"] as? String).map(StyleURI.init(rawValue:)) let mapOptions = args["mapOptions"] as? MapOptions let cameraOptions = args["cameraOptions"] as? CameraOptions - mapInitOptions = MapInitOptions( + let mapInitOptions = MapInitOptions( mapOptions: mapOptions?.toMapOptions() ?? MapboxMaps.MapOptions(), cameraOptions: cameraOptions?.toCameraOptions(), - styleURI: styleURI + styleURI: styleURI ?? .standard ) - if let version = args["mapboxPluginVersion"] as? String { - pluginVersion = version - } - - if let suffix = args["channelSuffix"] as? Int { - channelSuffix = suffix - } - - let eventTypes = args["eventTypes"] as? [Int] ?? [] - Self.mapCounter.increment() return MapboxMapController( withFrame: frame, mapInitOptions: mapInitOptions, - channelSuffix: channelSuffix, - arguments: args, + channelSuffix: args["channelSuffix"] as? Int ?? 0, registrar: registrar, - pluginVersion: pluginVersion, - eventTypes: eventTypes + pluginVersion: args["mapboxPluginVersion"] as? String ?? "", + eventTypes: args["eventTypes"] as? [Int] ?? [] ) } } diff --git a/ios/Classes/Offline/OfflineController.swift b/ios/Classes/Offline/OfflineController.swift index 932156dd..cedec233 100644 --- a/ios/Classes/Offline/OfflineController.swift +++ b/ios/Classes/Offline/OfflineController.swift @@ -9,9 +9,9 @@ final class OfflineController: _OfflineManager { private lazy var offlineManager = MapboxCoreMaps.OfflineManager() private var progressHandlers: [String: AnyFlutterStreamHandler] = [:] - private let messenger: FlutterBinaryMessenger + private let messenger: SuffixBinaryMessenger - init(messenger: FlutterBinaryMessenger) { + init(messenger: SuffixBinaryMessenger) { self.messenger = messenger } @@ -41,7 +41,7 @@ final class OfflineController: _OfflineManager { func addStylePackLoadProgressListener(styleURI: String) { let handler = AnyFlutterStreamHandler() - let eventChannel = FlutterEventChannel(name: "com.mapbox.maps.flutter/offline/\(styleURI)", binaryMessenger: messenger) + let eventChannel = FlutterEventChannel(name: "com.mapbox.maps.flutter/\(messenger.suffix)/\(styleURI)", binaryMessenger: messenger.messenger) eventChannel.setStreamHandler(handler) progressHandlers[styleURI] = handler } diff --git a/ios/Classes/Offline/OfflineMapInstanceManager.swift b/ios/Classes/Offline/OfflineMapInstanceManager.swift index 3672509c..6359c37a 100644 --- a/ios/Classes/Offline/OfflineMapInstanceManager.swift +++ b/ios/Classes/Offline/OfflineMapInstanceManager.swift @@ -7,26 +7,21 @@ final class OfflineMapInstanceManager: _OfflineMapInstanceManager, _TileStoreIns } private let binaryMessenger: FlutterBinaryMessenger - private var proxies: [String: ProxyBinaryMessenger] = [:] init(binaryMessenger: FlutterBinaryMessenger) { self.binaryMessenger = binaryMessenger } func setupOfflineManager(channelSuffix: String) throws { - let proxy = ProxyBinaryMessenger(with: binaryMessenger, channelSuffix: channelSuffix) - let offlineController = OfflineController(messenger: binaryMessenger) - _OfflineManagerSetup.setUp(binaryMessenger: proxy, api: offlineController) - proxies["offline-manager/\(channelSuffix)"] = proxy + let offlineController = OfflineController(messenger: SuffixBinaryMessenger(messenger: binaryMessenger, suffix: channelSuffix)) + _OfflineManagerSetup.setUp(binaryMessenger: binaryMessenger, api: offlineController, messageChannelSuffix: channelSuffix) } func tearDownOfflineManager(channelSuffix: String) throws { - guard let proxy = proxies.removeValue(forKey: "offline-manager/\(channelSuffix)") else { return } - _OfflineManagerSetup.setUp(binaryMessenger: proxy, api: nil) + _OfflineManagerSetup.setUp(binaryMessenger: binaryMessenger, api: nil, messageChannelSuffix: channelSuffix) } func setupTileStore(channelSuffix: String, filePath: String?) throws { - let proxy = ProxyBinaryMessenger(with: binaryMessenger, channelSuffix: channelSuffix) let tileStore: TileStore if let filePath { tileStore = .shared(for: URL(fileURLWithPath: filePath)) @@ -35,15 +30,13 @@ final class OfflineMapInstanceManager: _OfflineMapInstanceManager, _TileStoreIns } MapboxMapsOptions.tileStore = tileStore - let tileStoreController = TileStoreController(proxy: proxy, tileStore: tileStore) + let tileStoreController = TileStoreController(messenger: SuffixBinaryMessenger(messenger: binaryMessenger, suffix: channelSuffix), tileStore: tileStore) - _TileStoreSetup.setUp(binaryMessenger: proxy, api: tileStoreController) - proxies["tilestore/\(channelSuffix)"] = proxy + _TileStoreSetup.setUp(binaryMessenger: binaryMessenger, api: tileStoreController, messageChannelSuffix: channelSuffix) } func tearDownTileStore(channelSuffix: String) throws { - guard let proxy = proxies.removeValue(forKey: "tilestore/\(channelSuffix)") else { return } - _TileStoreSetup.setUp(binaryMessenger: proxy, api: nil) + _TileStoreSetup.setUp(binaryMessenger: binaryMessenger, api: nil, messageChannelSuffix: channelSuffix) MapboxMapsOptions.tileStore = nil } } diff --git a/ios/Classes/Offline/TileStoreController.swift b/ios/Classes/Offline/TileStoreController.swift index 2a4cf2d3..48ae1b01 100644 --- a/ios/Classes/Offline/TileStoreController.swift +++ b/ios/Classes/Offline/TileStoreController.swift @@ -7,15 +7,15 @@ final class TileStoreController: _TileStore { case invalidTileRegionLoadOptions } - private let proxy: ProxyBinaryMessenger + private let messenger: SuffixBinaryMessenger private let tileStore: TileStore private lazy var offlineManager = OfflineManager() private var tileRegionLoadProgressHandlers: [String: AnyFlutterStreamHandler] = [:] private var tileRegionEstimateProgressHandlers: [String: AnyFlutterStreamHandler] = [:] - init(proxy: ProxyBinaryMessenger, tileStore: TileStore) { - self.proxy = proxy + init(messenger: SuffixBinaryMessenger, tileStore: TileStore) { + self.messenger = messenger self.tileStore = tileStore } @@ -36,7 +36,7 @@ final class TileStoreController: _TileStore { func addTileRegionLoadProgressListener(id: String) throws { let handler = AnyFlutterStreamHandler() - let eventChannel = FlutterEventChannel(name: "com.mapbox.maps.flutter/tilestore/tile-region-\(id)", binaryMessenger: proxy.messenger) + let eventChannel = FlutterEventChannel(name: "com.mapbox.maps.flutter/\(messenger.suffix)/tile-region-\(id)", binaryMessenger: messenger.messenger) eventChannel.setStreamHandler(handler) tileRegionLoadProgressHandlers[id] = handler } @@ -62,7 +62,7 @@ final class TileStoreController: _TileStore { func addTileRegionEstimateProgressListener(id: String) throws { let handler = AnyFlutterStreamHandler() - let eventChannel = FlutterEventChannel(name: "com.mapbox.maps.flutter/tilestore/tile-region-estimate-\(id)", binaryMessenger: proxy.messenger) + let eventChannel = FlutterEventChannel(name: "com.mapbox.maps.flutter/\(messenger.suffix)/tile-region-estimate-\(id)", binaryMessenger: messenger.messenger) eventChannel.setStreamHandler(handler) tileRegionEstimateProgressHandlers[id] = handler } diff --git a/ios/Classes/Snapshotter/SnapshotterController.swift b/ios/Classes/Snapshotter/SnapshotterController.swift index b1a2f362..560deb7b 100644 --- a/ios/Classes/Snapshotter/SnapshotterController.swift +++ b/ios/Classes/Snapshotter/SnapshotterController.swift @@ -10,13 +10,14 @@ final class SnapshotterController: _SnapshotterMessenger { private var snapshotter: Snapshotter! private let eventHandler: MapboxEventHandler - init(snapshotter: Snapshotter, eventTypes: [Int], binaryMessenger: FlutterBinaryMessenger) { + init(snapshotter: Snapshotter, eventTypes: [Int], binaryMessenger: FlutterBinaryMessenger, channelSuffix: String) { self.snapshotter = snapshotter eventHandler = MapboxEventHandler( eventProvider: snapshotter, binaryMessenger: binaryMessenger, - eventTypes: eventTypes + eventTypes: eventTypes, + channelSuffix: channelSuffix ) } diff --git a/ios/Classes/Snapshotter/SnapshotterInstanceManager.swift b/ios/Classes/Snapshotter/SnapshotterInstanceManager.swift index 5ebb98bc..201eec67 100644 --- a/ios/Classes/Snapshotter/SnapshotterInstanceManager.swift +++ b/ios/Classes/Snapshotter/SnapshotterInstanceManager.swift @@ -4,7 +4,6 @@ import Flutter final class SnapshotterInstanceManager: _SnapshotterInstanceManager { private let binaryMessenger: FlutterBinaryMessenger - private var proxyMessengers = [String: ProxyBinaryMessenger]() init(binaryMessenger: FlutterBinaryMessenger) { self.binaryMessenger = binaryMessenger @@ -13,26 +12,21 @@ final class SnapshotterInstanceManager: _SnapshotterInstanceManager { func setupSnapshotterForSuffix(suffix: String, eventTypes: [Int64], options: MapSnapshotOptions) throws { let snapshotter = Snapshotter(options: options.toMapSnapshotOptions()) - let proxyMessenger = ProxyBinaryMessenger(with: binaryMessenger, channelSuffix: suffix) let snapshotterController = SnapshotterController( snapshotter: snapshotter, eventTypes: eventTypes.map(Int.init), - binaryMessenger: proxyMessenger + binaryMessenger: binaryMessenger, + channelSuffix: suffix ) let snapshotStyleController = StyleController(styleManager: snapshotter) - _SnapshotterMessengerSetup.setUp(binaryMessenger: proxyMessenger, api: snapshotterController) - StyleManagerSetup.setUp(binaryMessenger: proxyMessenger, api: snapshotStyleController) + _SnapshotterMessengerSetup.setUp(binaryMessenger: binaryMessenger, api: snapshotterController, messageChannelSuffix: suffix) + StyleManagerSetup.setUp(binaryMessenger: binaryMessenger, api: snapshotStyleController, messageChannelSuffix: suffix) - proxyMessengers[suffix] = proxyMessenger } func tearDownSnapshotterForSuffix(suffix: String) throws { - guard let proxyMessenger = proxyMessengers.removeValue(forKey: suffix) else { - return - } - - StyleManagerSetup.setUp(binaryMessenger: proxyMessenger, api: nil) - _SnapshotterMessengerSetup.setUp(binaryMessenger: proxyMessenger, api: nil) + StyleManagerSetup.setUp(binaryMessenger: binaryMessenger, api: nil, messageChannelSuffix: suffix) + _SnapshotterMessengerSetup.setUp(binaryMessenger: binaryMessenger, api: nil, messageChannelSuffix: suffix) } } diff --git a/lib/mapbox_maps_flutter.dart b/lib/mapbox_maps_flutter.dart index 22d5689f..edc84b64 100644 --- a/lib/mapbox_maps_flutter.dart +++ b/lib/mapbox_maps_flutter.dart @@ -12,8 +12,6 @@ import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; import 'package:turf/turf.dart' as turf; -import 'src/proxy_binary_messenger.dart' show ProxyBinaryMessenger; - export 'package:turf/helpers.dart'; part 'src/annotation/circle_annotation_manager.dart'; diff --git a/lib/src/annotation/annotation_manager.dart b/lib/src/annotation/annotation_manager.dart index 5f4f5cfd..da97317f 100644 --- a/lib/src/annotation/annotation_manager.dart +++ b/lib/src/annotation/annotation_manager.dart @@ -15,7 +15,9 @@ class AnnotationManager { return _mapboxMapsPlatform .createAnnotationManager('point', id: id, belowLayerId: below) .then((value) => PointAnnotationManager._( - id: value, messenger: _mapboxMapsPlatform.binaryMessenger)); + id: value, + messenger: _mapboxMapsPlatform.binaryMessenger, + channelSuffix: _mapboxMapsPlatform.channelSuffix.toString())); } /// Create a [CircleAnnotationManager] to add/remove/update [CircleAnnotation]s on the map. @@ -27,7 +29,9 @@ class AnnotationManager { return _mapboxMapsPlatform .createAnnotationManager('circle', id: id, belowLayerId: below) .then((value) => CircleAnnotationManager._( - id: value, messenger: _mapboxMapsPlatform.binaryMessenger)); + id: value, + messenger: _mapboxMapsPlatform.binaryMessenger, + channelSuffix: _mapboxMapsPlatform.channelSuffix.toString())); } /// Create a [PolylineAnnotationManager] to add/remove/update [PolylineAnnotation]s on the map. @@ -39,7 +43,9 @@ class AnnotationManager { return _mapboxMapsPlatform .createAnnotationManager('polyline', id: id, belowLayerId: below) .then((value) => PolylineAnnotationManager._( - id: value, messenger: _mapboxMapsPlatform.binaryMessenger)); + id: value, + messenger: _mapboxMapsPlatform.binaryMessenger, + channelSuffix: _mapboxMapsPlatform.channelSuffix.toString())); } /// Create a [PolygonAnnotationManager] to add/remove/update [PolygonAnnotation]s on the map. @@ -51,7 +57,9 @@ class AnnotationManager { return _mapboxMapsPlatform .createAnnotationManager('polygon', id: id, belowLayerId: below) .then((value) => PolygonAnnotationManager._( - id: value, messenger: _mapboxMapsPlatform.binaryMessenger)); + id: value, + messenger: _mapboxMapsPlatform.binaryMessenger, + channelSuffix: _mapboxMapsPlatform.channelSuffix.toString())); } /// Remove an [AnnotationManager] and all the annotations created by it. @@ -68,8 +76,10 @@ class AnnotationManager { /// The super class for all AnnotationManagers. class BaseAnnotationManager { BaseAnnotationManager._( - {required this.id, required BinaryMessenger messenger}) - : _messenger = messenger; + {required String id, + required BinaryMessenger messenger}) + : this.id = id, + _messenger = messenger; final String id; final BinaryMessenger _messenger; } diff --git a/lib/src/annotation/circle_annotation_manager.dart b/lib/src/annotation/circle_annotation_manager.dart index dbe7b04c..7fa378b0 100644 --- a/lib/src/annotation/circle_annotation_manager.dart +++ b/lib/src/annotation/circle_annotation_manager.dart @@ -3,9 +3,12 @@ part of mapbox_maps_flutter; /// The CircleAnnotationManager to add/update/delete CircleAnnotationAnnotations on the map. class CircleAnnotationManager extends BaseAnnotationManager { - CircleAnnotationManager._({required super.id, required super.messenger}) - : _annotationMessenger = - _CircleAnnotationMessenger(binaryMessenger: messenger), + CircleAnnotationManager._( + {required super.id, + required super.messenger, + required String channelSuffix}) + : _annotationMessenger = _CircleAnnotationMessenger( + binaryMessenger: messenger, messageChannelSuffix: channelSuffix), super._(); final _CircleAnnotationMessenger _annotationMessenger; diff --git a/lib/src/annotation/point_annotation_manager.dart b/lib/src/annotation/point_annotation_manager.dart index f9441f40..117f490d 100644 --- a/lib/src/annotation/point_annotation_manager.dart +++ b/lib/src/annotation/point_annotation_manager.dart @@ -3,9 +3,12 @@ part of mapbox_maps_flutter; /// The PointAnnotationManager to add/update/delete PointAnnotationAnnotations on the map. class PointAnnotationManager extends BaseAnnotationManager { - PointAnnotationManager._({required super.id, required super.messenger}) - : _annotationMessenger = - _PointAnnotationMessenger(binaryMessenger: messenger), + PointAnnotationManager._( + {required super.id, + required super.messenger, + required String channelSuffix}) + : _annotationMessenger = _PointAnnotationMessenger( + binaryMessenger: messenger, messageChannelSuffix: channelSuffix), super._(); final _PointAnnotationMessenger _annotationMessenger; diff --git a/lib/src/annotation/polygon_annotation_manager.dart b/lib/src/annotation/polygon_annotation_manager.dart index 24afe347..454d1ceb 100644 --- a/lib/src/annotation/polygon_annotation_manager.dart +++ b/lib/src/annotation/polygon_annotation_manager.dart @@ -3,9 +3,12 @@ part of mapbox_maps_flutter; /// The PolygonAnnotationManager to add/update/delete PolygonAnnotationAnnotations on the map. class PolygonAnnotationManager extends BaseAnnotationManager { - PolygonAnnotationManager._({required super.id, required super.messenger}) - : _annotationMessenger = - _PolygonAnnotationMessenger(binaryMessenger: messenger), + PolygonAnnotationManager._( + {required super.id, + required super.messenger, + required String channelSuffix}) + : _annotationMessenger = _PolygonAnnotationMessenger( + binaryMessenger: messenger, messageChannelSuffix: channelSuffix), super._(); final _PolygonAnnotationMessenger _annotationMessenger; diff --git a/lib/src/annotation/polyline_annotation_manager.dart b/lib/src/annotation/polyline_annotation_manager.dart index b26d8ec3..6d080b78 100644 --- a/lib/src/annotation/polyline_annotation_manager.dart +++ b/lib/src/annotation/polyline_annotation_manager.dart @@ -3,9 +3,12 @@ part of mapbox_maps_flutter; /// The PolylineAnnotationManager to add/update/delete PolylineAnnotationAnnotations on the map. class PolylineAnnotationManager extends BaseAnnotationManager { - PolylineAnnotationManager._({required super.id, required super.messenger}) - : _annotationMessenger = - _PolylineAnnotationMessenger(binaryMessenger: messenger), + PolylineAnnotationManager._( + {required super.id, + required super.messenger, + required String channelSuffix}) + : _annotationMessenger = _PolylineAnnotationMessenger( + binaryMessenger: messenger, messageChannelSuffix: channelSuffix), super._(); final _PolylineAnnotationMessenger _annotationMessenger; diff --git a/lib/src/map_events.dart b/lib/src/map_events.dart index 483c4bba..9b9c6e47 100644 --- a/lib/src/map_events.dart +++ b/lib/src/map_events.dart @@ -40,9 +40,14 @@ final class _MapEvents { return listenersMap.values.toList(); } - _MapEvents({BinaryMessenger? binaryMessenger}) { - _channel = MethodChannel('com.mapbox.maps.flutter.map_events', - const StandardMethodCodec(), binaryMessenger); + _MapEvents( + {BinaryMessenger? binaryMessenger, required String channelSuffix}) { + final pigeon_channelSuffix = + channelSuffix.length > 0 ? '.${channelSuffix}' : ''; + _channel = MethodChannel( + 'com.mapbox.maps.flutter.map_events${pigeon_channelSuffix}', + const StandardMethodCodec(), + binaryMessenger); _channel.setMethodCallHandler(_handleMethodCall); } diff --git a/lib/src/map_widget.dart b/lib/src/map_widget.dart index 30909117..a7866bf2 100644 --- a/lib/src/map_widget.dart +++ b/lib/src/map_widget.dart @@ -171,10 +171,8 @@ class MapWidget extends StatefulWidget { class _MapWidgetState extends State { late final _MapboxMapsPlatform _mapboxMapsPlatform = - _MapboxMapsPlatform(binaryMessenger: _binaryMessenger); + _MapboxMapsPlatform.instance(_suffix); final int _suffix = _suffixesRegistry.getSuffix(); - late final BinaryMessenger _binaryMessenger = - ProxyBinaryMessenger(suffix: _suffix.toString()); late final _MapEvents _events; bool _platformViewCreated = false; MapboxMap? mapboxMap; @@ -186,7 +184,7 @@ class _MapWidgetState extends State { 'cameraOptions': widget.cameraOptions, 'textureView': widget.textureView, 'styleUri': widget.styleUri, - 'channelSuffix': _suffix, + 'channelSuffix': _mapboxMapsPlatform.channelSuffix, 'mapboxPluginVersion': '2.3.0', 'eventTypes': _events.eventTypes.map((e) => e.index).toList(), }; @@ -199,7 +197,9 @@ class _MapWidgetState extends State { void initState() { super.initState(); - _events = _MapEvents(binaryMessenger: _binaryMessenger); + _events = _MapEvents( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + channelSuffix: _suffix.toString()); _updateEventListeners(); } diff --git a/lib/src/mapbox_map.dart b/lib/src/mapbox_map.dart index 989d06c0..ede58108 100644 --- a/lib/src/mapbox_map.dart +++ b/lib/src/mapbox_map.dart @@ -143,8 +143,6 @@ class MapboxMap extends ChangeNotifier { this.onMapLongTapListener, this.onMapScrollListener, }) : _mapboxMapsPlatform = mapboxMapsPlatform { - _proxyBinaryMessenger = _mapboxMapsPlatform.binaryMessenger; - annotations = AnnotationManager._(mapboxMapsPlatform: _mapboxMapsPlatform); _setupGestures(); } @@ -152,50 +150,59 @@ class MapboxMap extends ChangeNotifier { final _MapboxMapsPlatform _mapboxMapsPlatform; /// The currently loaded Style]object. - late StyleManager style = - StyleManager(binaryMessenger: _proxyBinaryMessenger); + late StyleManager style = StyleManager( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to set the location puck. late LocationSettings location = LocationSettings._( _LocationComponentSettingsInterface( - binaryMessenger: _proxyBinaryMessenger)); - - late BinaryMessenger _proxyBinaryMessenger; - - late _CameraManager _cameraManager = - _CameraManager(binaryMessenger: _proxyBinaryMessenger); - late _MapInterface _mapInterface = - _MapInterface(binaryMessenger: _proxyBinaryMessenger); - late _AnimationManager _animationManager = - _AnimationManager(binaryMessenger: _proxyBinaryMessenger); + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString())); + + late _CameraManager _cameraManager = _CameraManager( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); + late _MapInterface _mapInterface = _MapInterface( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); + late _AnimationManager _animationManager = _AnimationManager( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to create and set annotations. late final AnnotationManager annotations; // Keep Projection visible for users as iOS doesn't include it in MapboxMaps. /// The map projection of the style. - late Projection projection = - Projection(binaryMessenger: _proxyBinaryMessenger); + late Projection projection = Projection( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to access the gesture settings. - late GesturesSettingsInterface gestures = - GesturesSettingsInterface(binaryMessenger: _proxyBinaryMessenger); + late GesturesSettingsInterface gestures = GesturesSettingsInterface( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to set the logo settings. - late LogoSettingsInterface logo = - LogoSettingsInterface(binaryMessenger: _proxyBinaryMessenger); + late LogoSettingsInterface logo = LogoSettingsInterface( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to access the compass settings. - late CompassSettingsInterface compass = - CompassSettingsInterface(binaryMessenger: _proxyBinaryMessenger); + late CompassSettingsInterface compass = CompassSettingsInterface( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to access the compass settings. - late ScaleBarSettingsInterface scaleBar = - ScaleBarSettingsInterface(binaryMessenger: _proxyBinaryMessenger); + late ScaleBarSettingsInterface scaleBar = ScaleBarSettingsInterface( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); /// The interface to access the attribution settings. - late AttributionSettingsInterface attribution = - AttributionSettingsInterface(binaryMessenger: _proxyBinaryMessenger); + late AttributionSettingsInterface attribution = AttributionSettingsInterface( + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); OnMapTapListener? onMapTapListener; OnMapLongTapListener? onMapLongTapListener; @@ -204,7 +211,9 @@ class MapboxMap extends ChangeNotifier { @override void dispose() { _mapboxMapsPlatform.dispose(); - GestureListener.setUp(null, binaryMessenger: _proxyBinaryMessenger); + GestureListener.setUp(null, + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); super.dispose(); } @@ -586,7 +595,8 @@ class MapboxMap extends ChangeNotifier { onMapLongTapListener: onMapLongTapListener, onMapScrollListener: onMapScrollListener, ), - binaryMessenger: _mapboxMapsPlatform.binaryMessenger); + binaryMessenger: _mapboxMapsPlatform.binaryMessenger, + messageChannelSuffix: _mapboxMapsPlatform.channelSuffix.toString()); _mapboxMapsPlatform.addGestureListeners(); } } diff --git a/lib/src/mapbox_maps_platform.dart b/lib/src/mapbox_maps_platform.dart index 63796520..9e8c6236 100644 --- a/lib/src/mapbox_maps_platform.dart +++ b/lib/src/mapbox_maps_platform.dart @@ -4,13 +4,22 @@ typedef OnPlatformViewCreatedCallback = void Function(int); class _MapboxMapsPlatform { late final MethodChannel _channel = MethodChannel( - 'plugins.flutter.io', const StandardMethodCodec(), binaryMessenger); + 'plugins.flutter.io.${channelSuffix.toString()}', + const StandardMethodCodec(), + binaryMessenger); final BinaryMessenger binaryMessenger; + final int channelSuffix; - _MapboxMapsPlatform({required this.binaryMessenger}) { + _MapboxMapsPlatform( + {required this.binaryMessenger, required this.channelSuffix}) { _channel.setMethodCallHandler(_handleMethodCall); } + _MapboxMapsPlatform.instance(int channelSuffix) + : this( + binaryMessenger: ServicesBinding.instance.defaultBinaryMessenger, + channelSuffix: channelSuffix); + Future _handleMethodCall(MethodCall call) async { print( "Handle method call ${call.method}, arguments: ${call.arguments} not supported"); diff --git a/lib/src/offline/offline_manager.dart b/lib/src/offline/offline_manager.dart index 4e852f90..8616f423 100644 --- a/lib/src/offline/offline_manager.dart +++ b/lib/src/offline/offline_manager.dart @@ -6,6 +6,7 @@ final _OfflineMapInstanceManager _offlineMapInstanceManager = /// The [OfflineManager] provides a configuration interface and entrypoint for offline map functionality. final class OfflineManager { final int _suffix = _suffixesRegistry.getSuffix(); + String get _messageChannel => "offline-manager/${_suffix.toString()}"; late final _OfflineManager _api; static final Finalizer _finalizer = Finalizer((suffix) { @@ -17,16 +18,16 @@ final class OfflineManager { }); OfflineManager._() { - final messenger = - ProxyBinaryMessenger(suffix: "offline-manager/${_suffix.toString()}"); - _api = _OfflineManager(binaryMessenger: messenger); + _api = _OfflineManager( + binaryMessenger: ServicesBinding.instance.defaultBinaryMessenger, + messageChannelSuffix: _messageChannel); } /// Creates a new instance of [OfflineManager]. static Future create() async { final manager = OfflineManager._(); await _offlineMapInstanceManager - .setupOfflineManager("offline-manager/${manager._suffix.toString()}"); + .setupOfflineManager(manager._messageChannel); _finalizer.attach(manager, manager._suffix, detach: manager); return manager; @@ -65,7 +66,7 @@ final class OfflineManager { if (progressListener != null) { await _api.addStylePackLoadProgressListener(styleURI); final eventChannel = - EventChannel("com.mapbox.maps.flutter/offline/${styleURI}"); + EventChannel("com.mapbox.maps.flutter/${_messageChannel}/${styleURI}"); eventChannel.receiveBroadcastStream().listen((event) { progressListener(StylePackLoadProgress.decode(event)); }); diff --git a/lib/src/offline/tile_store.dart b/lib/src/offline/tile_store.dart index eafa4c71..34556a3f 100644 --- a/lib/src/offline/tile_store.dart +++ b/lib/src/offline/tile_store.dart @@ -8,6 +8,7 @@ final _TileStoreInstanceManager _tileStoreInstanceManager = /// app developer to set the disk quota. The rest of TileStore API is intended for native SDK consumption only. final class TileStore { final int _suffix = _suffixesRegistry.getSuffix(); + String get _messageChannel => "tilestore/${_suffix.toString()}"; static final Finalizer _finalizer = Finalizer((suffix) { try { _tileStoreInstanceManager @@ -19,9 +20,9 @@ final class TileStore { late final _TileStore _api; TileStore._() { - final messenger = - ProxyBinaryMessenger(suffix: "tilestore/${_suffix.toString()}"); - _api = _TileStore(binaryMessenger: messenger); + _api = _TileStore( + binaryMessenger: ServicesBinding.instance.defaultBinaryMessenger, + messageChannelSuffix: _messageChannel); } /// Returns a shared [TileStore] at the given storage [filePath]. @@ -31,7 +32,7 @@ final class TileStore { static Future createAt(Uri filePath) async { final tileStore = TileStore._(); await _tileStoreInstanceManager.setupTileStore( - "tilestore/${tileStore._suffix.toString()}", filePath.path); + tileStore._messageChannel, filePath.path); _finalizer.attach(tileStore, tileStore._suffix, detach: tileStore); return tileStore; } @@ -41,7 +42,7 @@ final class TileStore { static Future createDefault() async { final tileStore = TileStore._(); await _tileStoreInstanceManager.setupTileStore( - "tilestore/${tileStore._suffix.toString()}", null); + tileStore._messageChannel, null); _finalizer.attach(tileStore, tileStore._suffix, detach: tileStore); return tileStore; } @@ -88,7 +89,7 @@ final class TileStore { if (progressListener != null) { await _api.addTileRegionLoadProgressListener(id); final eventChannel = - EventChannel("com.mapbox.maps.flutter/tilestore/tile-region-${id}"); + EventChannel("com.mapbox.maps.flutter/${_messageChannel}/tile-region-${id}"); eventChannel.receiveBroadcastStream().listen((event) { progressListener(TileRegionLoadProgress.decode(event)); }); @@ -118,7 +119,7 @@ final class TileStore { if (progressListener != null) { await _api.addTileRegionEstimateProgressListener(id); final eventChannel = EventChannel( - "com.mapbox.maps.flutter/tilestore/tile-region-estimate-${id}"); + "com.mapbox.maps.flutter/${_messageChannel}/tile-region-estimate-${id}"); eventChannel.receiveBroadcastStream().listen((event) { progressListener(TileRegionEstimateProgress.decode(event)); }); diff --git a/lib/src/proxy_binary_messenger.dart b/lib/src/proxy_binary_messenger.dart deleted file mode 100644 index d4c6455c..00000000 --- a/lib/src/proxy_binary_messenger.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:ui' as ui; -import 'package:flutter/services.dart'; - -class ProxyBinaryMessenger implements BinaryMessenger { - ProxyBinaryMessenger( - {required String suffix, BinaryMessenger? binaryMessenger}) - : _suffix = suffix, - _binaryMessenger = - binaryMessenger ?? ServicesBinding.instance.defaultBinaryMessenger; - - final BinaryMessenger _binaryMessenger; - final String _suffix; - - @override - Future handlePlatformMessage( - String channel, - ByteData? data, - ui.PlatformMessageResponseCallback? callback, - ) { - return _binaryMessenger.handlePlatformMessage( - "$channel$_suffix", data, callback); - } - - @override - Future? send(String channel, ByteData? data) { - return _binaryMessenger.send("$channel$_suffix", data); - } - - @override - void setMessageHandler( - String channel, - MessageHandler? handler, - ) { - _binaryMessenger.setMessageHandler("$channel$_suffix", handler); - } -} diff --git a/lib/src/snapshotter/snapshotter.dart b/lib/src/snapshotter/snapshotter.dart index 5d5f4656..bdac972e 100644 --- a/lib/src/snapshotter/snapshotter.dart +++ b/lib/src/snapshotter/snapshotter.dart @@ -45,10 +45,10 @@ final class Snapshotter { this.onStyleDataLoadedListener, this.onStyleImageMissingListener, }) { - final messenger = ProxyBinaryMessenger(suffix: _suffix.toString()); - _snapshotterMessenger = _SnapshotterMessenger(binaryMessenger: messenger); - style = StyleManager(binaryMessenger: messenger); - _mapEvents = _MapEvents(binaryMessenger: messenger); + _snapshotterMessenger = + _SnapshotterMessenger(messageChannelSuffix: _suffix.toString()); + style = StyleManager(messageChannelSuffix: _suffix.toString()); + _mapEvents = _MapEvents(channelSuffix: _suffix.toString()); } /// Creates a new [Snapshotter] instance.