Skip to content

Commit

Permalink
feat: fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed Apr 23, 2024
1 parent b232e12 commit 01e878d
Show file tree
Hide file tree
Showing 22 changed files with 361 additions and 230 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

리액트 네이티브 [Naver Map](https://www.ncloud.com/product/applicationService/maps) 컴포넌트입니다.

<img src="https://raw.githubusercontent.com/mym0404/image-archive/master/202404152351235.webp" width="500" alt="preview">
<img src="https://raw.githubusercontent.com/mym0404/image-archive/master/202404240329848.gif" width="400" alt="preview">

## 왜 이 라이브러리를 써야하나요?

Expand Down Expand Up @@ -383,7 +383,7 @@ yarn add react-native-permissions
```

`react-native-permission`의 각 플랫폼별 설정 방법은 [사용법](https://github.com/zoontek/react-native-permissions#setup)을 직접 참고해
`Podfile(iOS)`, `AndroidManifest.xml(Android)` 를 적절히 변경해주시길 바랍니다.
`Podfile(iOS)`, `AndroidManifest.xml(Android)` 를 적절히 변경해주시길 바랍니다.

#### iOS

Expand Down Expand Up @@ -485,7 +485,7 @@ useEffect(() => {
/**
* Note: Foreground permissions should be granted before asking for the background permissions
* (your app can't obtain background permission without foreground permission).
*/
*/
if(granted) {
await Location.requestBackgroundPermissionsAsync();
}
Expand Down Expand Up @@ -532,7 +532,7 @@ useEffect(() => {
> [!TIP]
> `reuseIdentifier`는 전달하지 않아도 모두 자동으로 캐싱이 됩니다.
>
>
> 되도록이면 마커는 모두 `width`, `height` prop을 사용해야합니다. 2번 타입의 경우 현재 debug/release 빌드의 크기가 `width`, `height`없이 다르게 나오는 현상이 있습니다.
> release에서는 제대로 나옵니다.
Expand Down Expand Up @@ -571,7 +571,7 @@ image={{httpUri: 'https://example.com/image.png'}}
iOS(new arch)에선 현재 View들에 `collapsable=false`를 설정해야 동작합니다.

> [!TIP]
> 마커의 생김새를 바꿔야 한다면 그것에 대한 의존성들을 제일 상위 자식의 `key`로 전달해야합니다.
> 마커의 생김새를 바꿔야 한다면 그것에 대한 의존성들을 제일 상위 자식의 `key`로 전달해야합니다.
```tsx
<NaverMapMarkerOverlay width={width} height={height} ...>
Expand Down Expand Up @@ -607,8 +607,6 @@ iOS에선 단순히 `UIView`를 `UIImage`로 캔버스에 그려 표시해줍니
| Prop | iOS | Android |
|--------------------------|-----|---------|
| isLogoInteractionEnabled |||
| isUseTextureViewAndroid |||
| markerClustering | 📦 | 📦 |
| fpsLimit | 📦 | 📦 |
| gestureFrictions | 📦 | 📦 |

Expand All @@ -626,7 +624,6 @@ iOS에선 단순히 `UIView`를 `UIImage`로 캔버스에 그려 표시해줍니
|----------------------------|-----|---------|
| screenToCoordinate | 📦 | 📦 |
| coordinateToScreen | 📦 | 📦 |
| clusterMarkers | 📦 | 📦 |

### Marker Common

Expand Down Expand Up @@ -672,8 +669,8 @@ iOS에선 단순히 `UIView`를 `UIImage`로 캔버스에 그려 표시해줍니
- [x] Release (23.04.11)
- [x] Support Expo with config plugin (23.04.12)
- [x] Docs
- [ ] Implement Clustering <- 🔥
- [ ] Implement MutlPath, Arrow, Geometry Overlays
- [x] Implement Clustering (23.04.24)
- [ ] Implement MutlPath, Arrow, Geometry Overlays <- 🔥

## Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,15 @@ class RNCNaverMapViewManager : RNCNaverMapViewManagerSpec<RNCNaverMapViewWrapper
val latitude = marker["latitude"] as Double
val longitude = marker["longitude"] as Double
val image = marker["image"] as? Map<*, *>
val width = marker["width"] as? Double
val height = marker["height"] as? Double

RNCNaverMapClusterKey(
identifier,
LatLng(latitude, longitude),
image,
width,
height,
RNCNaverMapLeafMarkerHolder(identifier, reactAppContext),
) to null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class RNCNaverMapMarker(val reactContext: ThemedReactContext) :
ViewChangesTracker.getInstance().addMarker(this)
customView = view
updateCustomView()
overlay.alpha = 1f
}

fun removeCustomView(index: Int) {
Expand Down Expand Up @@ -142,10 +143,12 @@ class RNCNaverMapMarker(val reactContext: ThemedReactContext) :
fun setImage(image: ReadableMap?) {
lastImage = image
if (isImageSetFromSubview) return
overlay.alpha = 0f
imageRequestCanceller?.invoke()
imageRequestCanceller =
getOverlayImage(imageHolder!!, context, image?.toHashMap()) {
setOverlayImage(it)
overlay.alpha = 1f
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ internal data class RNCNaverMapClusterKey(
val identifier: String,
val latlng: LatLng,
val image: Map<*, *>? = null,
val width: Double?,
val height: Double?,
val holder: RNCNaverMapLeafMarkerHolder,
) : ClusteringKey {
override fun getPosition(): LatLng {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mjstudio.reactnativenavermap.overlay.marker.cluster

import com.mjstudio.reactnativenavermap.util.ImageRequestCanceller
import com.mjstudio.reactnativenavermap.util.getOverlayImage
import com.mjstudio.reactnativenavermap.util.px
import com.naver.maps.map.clustering.DefaultLeafMarkerUpdater
import com.naver.maps.map.clustering.LeafMarkerInfo
import com.naver.maps.map.overlay.Marker
Expand All @@ -17,11 +18,28 @@ internal class RNCNaverMapLeafMarkerUpdater : DefaultLeafMarkerUpdater() {
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
}
(info.key as? RNCNaverMapClusterKey)?.let {
(
id, _,
image, width, height, holder,
),
->
if (width != null) {
marker.width = width.px
}
if (height != null) {
marker.height = height.px
}
if (image != null) {
marker.alpha = 0f
imageRequestCanceller =
getOverlayImage(holder.imageHolder, holder.context, image) {
marker.icon = it ?: MarkerIcons.GREEN
marker.alpha = 1f
}
} else {
marker.alpha = 1f
}
}
}
}
5 changes: 5 additions & 0 deletions android/src/oldarch/RNCNaverMapViewManagerSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ internal interface RNCNaverMapViewManagerInterface<T : ViewGroup?> {
view: T,
mode: String?,
)

fun setClusters(
view: T,
value: ReadableMap?,
)
}

abstract class RNCNaverMapViewManagerSpec<T : ViewGroup> :
Expand Down
Loading

0 comments on commit 01e878d

Please sign in to comment.