Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class OpenMobileMapsViewState(
cameraPosition: MapCameraPosition = MapCameraPosition.Default,
) : MapViewState<OpenMobileMapsMapDesignTypeInterface>(cameraPosition),
OpenMobileMapsViewStateInterface {
private var controller: OpenMobileMapsMapViewController? = null
// Read through the base so that letting go of the controller there (MapViewBase
// does it when the map is torn down) leaves nothing behind here.
private val controller: OpenMobileMapsMapViewController?
get() = attachedMapController as? OpenMobileMapsMapViewController
private var current: OpenMobileMapsMapDesignTypeInterface = mapDesignType

override var mapDesignType: OpenMobileMapsMapDesignTypeInterface
Expand All @@ -75,7 +78,6 @@ class OpenMobileMapsViewState(
}

internal fun setController(controller: OpenMobileMapsMapViewController) {
this.controller = controller
attachController(controller)
}

Expand Down Expand Up @@ -280,6 +282,16 @@ fun OpenMobileMapsMapView(
},
style = style,
onStyleDiagnostics = onStyleDiagnostics,
// registerLifecycle() put the MapView on the Activity's lifecycle, and
// its own onDestroy() does not take it off again: left there, the
// Activity keeps every map the user switched away from (and through
// its callbacks the controller with every overlay). Take it off first
// so the Activity's ON_DESTROY cannot destroy it a second time.
onDestroyMapView = { surface ->
lifecycleOwner.lifecycle.removeObserver(surface.mapView)
surface.mapView.onPause()
surface.mapView.onDestroy()
},
content = content,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,17 @@ class OpenMobileMapsMapViewController(
}
}

/**
* 地図に挿したタッチリスナー。SDK はネイティブ側から JNI の global 参照で掴むので、
* [destroy] で外さないとこのコントローラ(と全オーバーレイ)がプロセスに残る。
*/
private var touchListener: OpenMobileMapsTouchListener? = null

/** SDK のイベントをコアの受け口へ転送する。 */
fun installListeners() {
holder.map.getTouchHandler().insertListener(OpenMobileMapsTouchListener(this), 0)
val listener = OpenMobileMapsTouchListener(this)
touchListener = listener
holder.map.getTouchHandler().insertListener(listener, 0)
holder.map.getCamera().addListener(cameraListener)
notifyMapInitialized()
}
Expand Down Expand Up @@ -467,6 +475,8 @@ class OpenMobileMapsMapViewController(
override fun destroy() {
cancelCameraAnimation()
runCatching { holder.map.getCamera().removeListener(cameraListener) }
touchListener?.let { listener -> runCatching { holder.map.getTouchHandler().removeListener(listener) } }
touchListener = null
removeDragTouchInterceptor()
super.destroy()
}
Expand Down
Loading