Commit 48e84d00 authored by Qiu Xiang's avatar Qiu Xiang

优化事件处理代码

parent aecb6355
...@@ -107,11 +107,9 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) { ...@@ -107,11 +107,9 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
fun setIconView(overlay: AMapOverlay) { fun setIconView(overlay: AMapOverlay) {
overlay.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> updateIconView(overlay) } overlay.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> updateIconView(overlay) }
overlay.setOnUpdateListener(object : AMapOverlay.OnUpdateListener { overlay.onUpdate {
override fun onUpdate() {
updateIconView(overlay) updateIconView(overlay)
} }
})
} }
private fun updateIconView(overlay: AMapOverlay) { private fun updateIconView(overlay: AMapOverlay) {
......
...@@ -4,17 +4,13 @@ import android.content.Context ...@@ -4,17 +4,13 @@ import android.content.Context
import com.facebook.react.views.view.ReactViewGroup import com.facebook.react.views.view.ReactViewGroup
class AMapOverlay(context: Context) : ReactViewGroup(context) { class AMapOverlay(context: Context) : ReactViewGroup(context) {
private var onUpdateListener: OnUpdateListener? = null private var updateHandler: (() -> Unit)? = null
fun setOnUpdateListener(listener: OnUpdateListener) { fun onUpdate(handler: () -> Unit) {
onUpdateListener = listener updateHandler = handler
} }
fun update() { fun update() {
onUpdateListener?.onUpdate() updateHandler?.invoke()
}
interface OnUpdateListener {
fun onUpdate()
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment