-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathRNCNaverMapUtilModule.kt
More file actions
104 lines (87 loc) · 2.86 KB
/
RNCNaverMapUtilModule.kt
File metadata and controls
104 lines (87 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.mjstudio.reactnativenavermap.module
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.module.annotations.ReactModule
import com.mjstudio.reactnativenavermap.RNCNaverMapUtilSpec
import com.naver.maps.map.overlay.InfoWindow
@ReactModule(name = RNCNaverMapUtilModule.NAME)
class RNCNaverMapUtilModule(
reactContext: ReactApplicationContext,
) : RNCNaverMapUtilSpec(reactContext) {
companion object {
const val NAME = "RNCNaverMapUtil"
}
private val infoWindows = mutableMapOf<String, InfoWindow>()
private val infoWindowContents = mutableMapOf<String, InfoWindowContent>()
private val openInfoWindows = mutableSetOf<String>()
override fun getName(): String = NAME
@ReactMethod
override fun createInfoWindow(id: String) {
if (infoWindows.containsKey(id)) return
val infoWindow =
InfoWindow().apply {
adapter =
object : InfoWindow.DefaultTextAdapter(reactApplicationContext) {
override fun getText(infoWindow: InfoWindow): CharSequence {
val content = infoWindowContents[id]
return content?.let {
if (it.subtitle.isNullOrEmpty()) {
it.title
} else {
"${it.title}\n${it.subtitle}"
}
} ?: ""
}
}
// todo
// setOnClickListener {
// true
// }
}
infoWindows[id] = infoWindow
}
@ReactMethod
override fun destroyInfoWindow(id: String) {
infoWindows[id]?.let { infoWindow ->
infoWindow.close()
infoWindows.remove(id)
infoWindowContents.remove(id)
openInfoWindows.remove(id)
}
}
@ReactMethod
override fun closeInfoWindow(id: String) {
infoWindows[id]?.let { infoWindow ->
infoWindow.close()
openInfoWindows.remove(id)
}
}
@ReactMethod
override fun setInfoWindowContent(
id: String,
title: String,
subtitle: String?,
) {
infoWindowContents[id] = InfoWindowContent(title, subtitle)
val infoWindow = infoWindows[id] ?: return
// 이미 열려있다면 업데이트
if (isInfoWindowActuallyOpen(infoWindow)) {
infoWindow.invalidate()
}
}
@ReactMethod(isBlockingSynchronousMethod = true)
override fun isInfoWindowOpen(id: String): Boolean = infoWindows[id]?.let(::isInfoWindowActuallyOpen) ?: false
// ViewManager에서 접근할 내부 메서드들
fun getInfoWindow(id: String): InfoWindow? = infoWindows[id]
fun markAsOpen(id: String) {
openInfoWindows.add(id)
}
fun markAsClosed(id: String) {
openInfoWindows.remove(id)
}
private fun isInfoWindowActuallyOpen(infoWindow: InfoWindow): Boolean = infoWindow.map != null || infoWindow.marker != null
private data class InfoWindowContent(
val title: String,
val subtitle: String?,
)
}