-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): clustering impl + fix android, ios memory leak?
- Loading branch information
Showing
11 changed files
with
215 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ava/com/mjstudio/reactnativenavermap/overlay/marker/cluster/RNCNaverMapClustererHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mjstudio.reactnativenavermap.overlay.marker.cluster | ||
|
||
import com.facebook.drawee.generic.GenericDraweeHierarchy | ||
import com.facebook.drawee.view.DraweeHolder | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.mjstudio.reactnativenavermap.util.createDraweeHierarchy | ||
import com.naver.maps.map.clustering.Clusterer | ||
|
||
internal data class RNCNaverMapClustererHolder internal constructor( | ||
val identifier: String, | ||
val clusterer: Clusterer<RNCNaverMapClusterKey>, | ||
val context: ReactApplicationContext, | ||
val markers: List<RNCNaverMapLeafMarkerHolder>, | ||
) { | ||
private val imageHolder: DraweeHolder<GenericDraweeHierarchy> by lazy { | ||
DraweeHolder.create(createDraweeHierarchy(context.resources), context).apply { | ||
onAttach() | ||
} | ||
} | ||
|
||
fun onDetach() { | ||
markers.forEach { it.onDetach() } | ||
clusterer.map = null | ||
imageHolder.onDetach() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...va/com/mjstudio/reactnativenavermap/overlay/marker/cluster/RNCNaverMapLeafMarkerHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mjstudio.reactnativenavermap.overlay.marker.cluster | ||
|
||
import com.facebook.drawee.generic.GenericDraweeHierarchy | ||
import com.facebook.drawee.view.DraweeHolder | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.mjstudio.reactnativenavermap.util.createDraweeHierarchy | ||
|
||
internal data class RNCNaverMapLeafMarkerHolder( | ||
val identifier: String, | ||
val context: ReactApplicationContext, | ||
) { | ||
val imageHolder: DraweeHolder<GenericDraweeHierarchy> by lazy { | ||
DraweeHolder.create(createDraweeHierarchy(context.resources), context).apply { | ||
onAttach() | ||
} | ||
} | ||
|
||
fun onDetach() { | ||
imageHolder.onDetach() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...a/com/mjstudio/reactnativenavermap/overlay/marker/cluster/RNCNaverMapLeafMarkerUpdater.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mjstudio.reactnativenavermap.overlay.marker.cluster | ||
|
||
import com.mjstudio.reactnativenavermap.util.ImageRequestCanceller | ||
import com.mjstudio.reactnativenavermap.util.getOverlayImage | ||
import com.naver.maps.map.clustering.DefaultLeafMarkerUpdater | ||
import com.naver.maps.map.clustering.LeafMarkerInfo | ||
import com.naver.maps.map.overlay.Marker | ||
import com.naver.maps.map.util.MarkerIcons | ||
|
||
internal class RNCNaverMapLeafMarkerUpdater : DefaultLeafMarkerUpdater() { | ||
private var imageRequestCanceller: ImageRequestCanceller? = null | ||
|
||
override fun updateLeafMarker( | ||
info: LeafMarkerInfo, | ||
marker: Marker, | ||
) { | ||
super.updateLeafMarker(info, marker) | ||
|
||
imageRequestCanceller?.invoke() | ||
(info.key as? RNCNaverMapClusterKey)?.let { (id, _, image, holder) -> | ||
imageRequestCanceller = | ||
getOverlayImage(holder.imageHolder, holder.context, image) { | ||
marker.icon = it ?: MarkerIcons.GREEN | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.