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

优化事件处理代码

parent aecb6355
......@@ -107,11 +107,9 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
fun setIconView(overlay: AMapOverlay) {
overlay.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> updateIconView(overlay) }
overlay.setOnUpdateListener(object : AMapOverlay.OnUpdateListener {
override fun onUpdate() {
updateIconView(overlay)
}
})
overlay.onUpdate {
updateIconView(overlay)
}
}
private fun updateIconView(overlay: AMapOverlay) {
......
......@@ -4,17 +4,13 @@ import android.content.Context
import com.facebook.react.views.view.ReactViewGroup
class AMapOverlay(context: Context) : ReactViewGroup(context) {
private var onUpdateListener: OnUpdateListener? = null
private var updateHandler: (() -> Unit)? = null
fun setOnUpdateListener(listener: OnUpdateListener) {
onUpdateListener = listener
fun onUpdate(handler: () -> Unit) {
updateHandler = handler
}
fun update() {
onUpdateListener?.onUpdate()
}
interface OnUpdateListener {
fun onUpdate()
updateHandler?.invoke()
}
}
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