@react-native-kakao/map 2.2.6 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +5 -38
  3. package/RNCKakaoMap.podspec +16 -52
  4. package/android/build.gradle +12 -107
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +3 -1
  7. package/android/src/main/java/net/mjstudio/rnkakao/map/CameraOptions.kt +61 -0
  8. package/android/src/main/java/net/mjstudio/rnkakao/map/KakaoMapModule.kt +131 -0
  9. package/android/src/main/java/net/mjstudio/rnkakao/map/KakaoMapView.kt +1257 -0
  10. package/android/src/main/java/net/mjstudio/rnkakao/map/MapCameraCommands.kt +306 -0
  11. package/android/src/main/java/net/mjstudio/rnkakao/map/MapDimScreen.kt +431 -0
  12. package/android/src/main/java/net/mjstudio/rnkakao/map/MapGui.kt +899 -0
  13. package/android/src/main/java/net/mjstudio/rnkakao/map/MapImageLoader.kt +232 -0
  14. package/android/src/main/java/net/mjstudio/rnkakao/map/MapLabels.kt +1572 -0
  15. package/android/src/main/java/net/mjstudio/rnkakao/map/MapOptions.kt +360 -0
  16. package/android/src/main/java/net/mjstudio/rnkakao/map/MapRoutes.kt +805 -0
  17. package/android/src/main/java/net/mjstudio/rnkakao/map/MapShapes.kt +1096 -0
  18. package/android/src/main/java/net/mjstudio/rnkakao/map/MapUtilities.kt +495 -0
  19. package/expo-module.config.json +5 -0
  20. package/ios/CameraOptions.swift +41 -0
  21. package/ios/KakaoMapModule.swift +204 -0
  22. package/ios/KakaoMapView.swift +1018 -0
  23. package/ios/MapCameraCommands.swift +451 -0
  24. package/ios/MapDimScreen.swift +463 -0
  25. package/ios/MapGui.swift +1099 -0
  26. package/ios/MapImageLoader.swift +177 -0
  27. package/ios/MapLabels.swift +1676 -0
  28. package/ios/MapOptions.swift +374 -0
  29. package/ios/MapRoutes.swift +903 -0
  30. package/ios/MapShapes.swift +1294 -0
  31. package/ios/MapUnits.swift +20 -0
  32. package/ios/MapUtilities.swift +365 -0
  33. package/lib/commonjs/index.js +180 -29
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/index.web.js +18 -0
  36. package/lib/commonjs/index.web.js.map +1 -0
  37. package/lib/commonjs/package.json +1 -0
  38. package/lib/commonjs/types-assets.js +2 -0
  39. package/lib/commonjs/types-assets.js.map +1 -0
  40. package/lib/commonjs/types-camera.js +6 -0
  41. package/lib/commonjs/types-camera.js.map +1 -0
  42. package/lib/commonjs/types-dim.js +6 -0
  43. package/lib/commonjs/types-dim.js.map +1 -0
  44. package/lib/commonjs/types-gui.js +6 -0
  45. package/lib/commonjs/types-gui.js.map +1 -0
  46. package/lib/commonjs/types-labels.js +6 -0
  47. package/lib/commonjs/types-labels.js.map +1 -0
  48. package/lib/commonjs/types-routes.js +6 -0
  49. package/lib/commonjs/types-routes.js.map +1 -0
  50. package/lib/commonjs/types-shapes.js +6 -0
  51. package/lib/commonjs/types-shapes.js.map +1 -0
  52. package/lib/commonjs/types-utilities.js +6 -0
  53. package/lib/commonjs/types-utilities.js.map +1 -0
  54. package/lib/commonjs/types.js +6 -0
  55. package/lib/commonjs/types.js.map +1 -0
  56. package/lib/module/index.js +180 -22
  57. package/lib/module/index.js.map +1 -1
  58. package/lib/module/index.web.js +13 -0
  59. package/lib/module/index.web.js.map +1 -0
  60. package/lib/module/types-assets.js +2 -0
  61. package/lib/module/types-assets.js.map +1 -0
  62. package/lib/module/types-camera.js +4 -0
  63. package/lib/module/types-camera.js.map +1 -0
  64. package/lib/module/types-dim.js +4 -0
  65. package/lib/module/types-dim.js.map +1 -0
  66. package/lib/module/types-gui.js +4 -0
  67. package/lib/module/types-gui.js.map +1 -0
  68. package/lib/module/types-labels.js +4 -0
  69. package/lib/module/types-labels.js.map +1 -0
  70. package/lib/module/types-routes.js +4 -0
  71. package/lib/module/types-routes.js.map +1 -0
  72. package/lib/module/types-shapes.js +4 -0
  73. package/lib/module/types-shapes.js.map +1 -0
  74. package/lib/module/types-utilities.js +4 -0
  75. package/lib/module/types-utilities.js.map +1 -0
  76. package/lib/module/types.js +4 -0
  77. package/lib/module/types.js.map +1 -0
  78. package/lib/typescript/src/index.d.ts +59 -9
  79. package/lib/typescript/src/index.d.ts.map +1 -1
  80. package/lib/typescript/src/types-assets.d.ts +9 -0
  81. package/lib/typescript/src/types-assets.d.ts.map +1 -0
  82. package/lib/typescript/src/types-camera.d.ts +123 -0
  83. package/lib/typescript/src/types-camera.d.ts.map +1 -0
  84. package/lib/typescript/src/types-dim.d.ts +54 -0
  85. package/lib/typescript/src/types-dim.d.ts.map +1 -0
  86. package/lib/typescript/src/types-gui.d.ts +189 -0
  87. package/lib/typescript/src/types-gui.d.ts.map +1 -0
  88. package/lib/typescript/src/types-labels.d.ts +246 -0
  89. package/lib/typescript/src/types-labels.d.ts.map +1 -0
  90. package/lib/typescript/src/types-routes.d.ts +162 -0
  91. package/lib/typescript/src/types-routes.d.ts.map +1 -0
  92. package/lib/typescript/src/types-shapes.d.ts +253 -0
  93. package/lib/typescript/src/types-shapes.d.ts.map +1 -0
  94. package/lib/typescript/src/types-utilities.d.ts +130 -0
  95. package/lib/typescript/src/types-utilities.d.ts.map +1 -0
  96. package/lib/typescript/src/types.d.ts +222 -0
  97. package/lib/typescript/src/types.d.ts.map +1 -0
  98. package/package.json +24 -77
  99. package/src/index.tsx +322 -0
  100. package/src/index.web.tsx +46 -0
  101. package/src/types-assets.ts +8 -0
  102. package/src/types-camera.ts +97 -0
  103. package/src/types-dim.ts +54 -0
  104. package/src/types-gui.ts +171 -0
  105. package/src/types-labels.ts +207 -0
  106. package/src/types-routes.ts +118 -0
  107. package/src/types-shapes.ts +244 -0
  108. package/src/types-utilities.ts +115 -0
  109. package/src/types.ts +223 -0
  110. package/android/gradle.properties +0 -1
  111. package/android/src/main/AndroidManifestNew.xml +0 -2
  112. package/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapModule.kt +0 -25
  113. package/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapPackage.kt +0 -35
  114. package/android/src/newarch/KakaoMapSpec.kt +0 -7
  115. package/android/src/oldarch/KakaoMapSpec.kt +0 -14
  116. package/ios/Component/Map/RNCKakaoMapView.h +0 -23
  117. package/ios/Component/Map/RNCKakaoMapView.mm +0 -209
  118. package/ios/Component/Map/RNCKakaoMapViewManager.mm +0 -19
  119. package/ios/NativeModule/RNCKakaoMap.h +0 -7
  120. package/ios/NativeModule/RNCKakaoMap.mm +0 -19
  121. package/ios/NativeModule/RNCKakaoMapManager.swift +0 -7
  122. package/ios/Util/Util.h +0 -97
  123. package/lib/commonjs/component/KakaoMapView.js +0 -54
  124. package/lib/commonjs/component/KakaoMapView.js.map +0 -1
  125. package/lib/commonjs/spec/NativeKakaoMap.js +0 -9
  126. package/lib/commonjs/spec/NativeKakaoMap.js.map +0 -1
  127. package/lib/commonjs/spec/RNCKakaoMapViewNativeComponent.js +0 -15
  128. package/lib/commonjs/spec/RNCKakaoMapViewNativeComponent.js.map +0 -1
  129. package/lib/commonjs/type/type.js +0 -2
  130. package/lib/commonjs/type/type.js.map +0 -1
  131. package/lib/commonjs/util/Const.js +0 -14
  132. package/lib/commonjs/util/Const.js.map +0 -1
  133. package/lib/commonjs/util/Util.js +0 -15
  134. package/lib/commonjs/util/Util.js.map +0 -1
  135. package/lib/module/component/KakaoMapView.js +0 -48
  136. package/lib/module/component/KakaoMapView.js.map +0 -1
  137. package/lib/module/spec/NativeKakaoMap.js +0 -3
  138. package/lib/module/spec/NativeKakaoMap.js.map +0 -1
  139. package/lib/module/spec/RNCKakaoMapViewNativeComponent.js +0 -10
  140. package/lib/module/spec/RNCKakaoMapViewNativeComponent.js.map +0 -1
  141. package/lib/module/type/type.js +0 -2
  142. package/lib/module/type/type.js.map +0 -1
  143. package/lib/module/util/Const.js +0 -8
  144. package/lib/module/util/Const.js.map +0 -1
  145. package/lib/module/util/Util.js +0 -9
  146. package/lib/module/util/Util.js.map +0 -1
  147. package/lib/typescript/src/component/KakaoMapView.d.ts +0 -25
  148. package/lib/typescript/src/component/KakaoMapView.d.ts.map +0 -1
  149. package/lib/typescript/src/spec/NativeKakaoMap.d.ts +0 -7
  150. package/lib/typescript/src/spec/NativeKakaoMap.d.ts.map +0 -1
  151. package/lib/typescript/src/spec/RNCKakaoMapViewNativeComponent.d.ts +0 -32
  152. package/lib/typescript/src/spec/RNCKakaoMapViewNativeComponent.d.ts.map +0 -1
  153. package/lib/typescript/src/type/type.d.ts +0 -8
  154. package/lib/typescript/src/type/type.d.ts.map +0 -1
  155. package/lib/typescript/src/util/Const.d.ts +0 -8
  156. package/lib/typescript/src/util/Const.d.ts.map +0 -1
  157. package/lib/typescript/src/util/Util.d.ts +0 -3
  158. package/lib/typescript/src/util/Util.d.ts.map +0 -1
  159. package/src/component/KakaoMapView.tsx +0 -82
  160. package/src/index.ts +0 -43
  161. package/src/spec/NativeKakaoMap.ts +0 -8
  162. package/src/spec/RNCKakaoMapViewNativeComponent.ts +0 -38
  163. package/src/type/type.ts +0 -7
  164. package/src/util/Const.ts +0 -7
  165. package/src/util/Util.ts +0 -11
@@ -0,0 +1,177 @@
1
+ import ExpoModulesCore
2
+ import UIKit
3
+
4
+ private let mapImageLoadError = "ERR_KAKAO_MAP_IMAGE_LOAD"
5
+ private let supportedMapImageSchemes = Set([
6
+ "asset", "content", "data", "file", "http", "https"
7
+ ])
8
+
9
+ final class MapImageLoadException: Exception {
10
+ init(_ message: String) {
11
+ super.init(name: "KakaoMapImageError", description: message, code: mapImageLoadError)
12
+ }
13
+ }
14
+
15
+ final class MapImageLoadToken {
16
+ fileprivate let id: UUID
17
+ private let lock = NSLock()
18
+ private var cancellation: (() -> Void)?
19
+ private var isFinished = false
20
+
21
+ fileprivate init(id: UUID = UUID(), cancellation: @escaping () -> Void) {
22
+ self.id = id
23
+ self.cancellation = cancellation
24
+ }
25
+
26
+ func cancel() {
27
+ lock.lock()
28
+ guard !isFinished else {
29
+ lock.unlock()
30
+ return
31
+ }
32
+ isFinished = true
33
+ let cancellation = cancellation
34
+ self.cancellation = nil
35
+ lock.unlock()
36
+ cancellation?()
37
+ }
38
+
39
+ @discardableResult
40
+ fileprivate func finish() -> Bool {
41
+ lock.lock()
42
+ guard !isFinished else {
43
+ lock.unlock()
44
+ return false
45
+ }
46
+ isFinished = true
47
+ cancellation = nil
48
+ lock.unlock()
49
+ return true
50
+ }
51
+ }
52
+
53
+ final class MapImageLoader {
54
+ private struct Request {
55
+ let token: MapImageLoadToken
56
+ let completion: (Result<UIImage, Error>) -> Void
57
+ }
58
+
59
+ private let imageLoader: EXImageLoaderInterface?
60
+ private let cache = NSCache<NSURL, UIImage>()
61
+ private var requests: [UUID: Request] = [:]
62
+ private var isDisposed = false
63
+
64
+ init(appContext: AppContext?) {
65
+ imageLoader = appContext?.imageLoader
66
+ cache.countLimit = 64
67
+ cache.totalCostLimit = 16 * 1024 * 1024
68
+ }
69
+
70
+ @discardableResult
71
+ func load(
72
+ _ uri: String,
73
+ completion: @escaping (Result<UIImage, Error>) -> Void
74
+ ) -> MapImageLoadToken {
75
+ dispatchPrecondition(condition: .onQueue(.main))
76
+ let requestId = UUID()
77
+ let token = MapImageLoadToken(id: requestId) { [weak self] in
78
+ if Thread.isMainThread {
79
+ self?.cancel(requestId)
80
+ } else {
81
+ DispatchQueue.main.async { [weak self] in
82
+ self?.cancel(requestId)
83
+ }
84
+ }
85
+ }
86
+
87
+ guard !isDisposed else {
88
+ fail(token, completion: completion, message: "The map image loader was destroyed.")
89
+ return token
90
+ }
91
+ requests[token.id] = Request(token: token, completion: completion)
92
+ guard let url = URL(string: uri), let scheme = url.scheme?.lowercased(),
93
+ supportedMapImageSchemes.contains(scheme)
94
+ else {
95
+ reject(token.id, message: "Image URI must use a supported scheme.")
96
+ return token
97
+ }
98
+ guard let imageLoader else {
99
+ reject(token.id, message: "The Expo image loader is unavailable.")
100
+ return token
101
+ }
102
+
103
+ let key = url as NSURL
104
+ if let image = cache.object(forKey: key) {
105
+ DispatchQueue.main.async { [weak self] in
106
+ self?.finish(token.id, result: .success(image))
107
+ }
108
+ return token
109
+ }
110
+
111
+ imageLoader.loadImage(for: url) { [weak self] error, image in
112
+ DispatchQueue.main.async { [weak self] in
113
+ guard let self, !self.isDisposed else { return }
114
+ if let image {
115
+ finish(token.id, result: .success(image), cacheKey: key)
116
+ } else {
117
+ finish(
118
+ token.id,
119
+ result: .failure(MapImageLoadException(error?
120
+ .localizedDescription ?? "Could not decode the map image."))
121
+ )
122
+ }
123
+ }
124
+ }
125
+ return token
126
+ }
127
+
128
+ func dispose() {
129
+ dispatchPrecondition(condition: .onQueue(.main))
130
+ guard !isDisposed else { return }
131
+ isDisposed = true
132
+ let currentRequests = requests.values
133
+ requests.removeAll()
134
+ currentRequests.forEach { $0.token.finish() }
135
+ cache.removeAllObjects()
136
+ }
137
+
138
+ private func cancel(_ id: UUID) {
139
+ requests.removeValue(forKey: id)
140
+ }
141
+
142
+ private func finish(
143
+ _ id: UUID,
144
+ result: Result<UIImage, Error>,
145
+ cacheKey: NSURL? = nil
146
+ ) {
147
+ guard !isDisposed, let request = requests.removeValue(forKey: id) else { return }
148
+ guard request.token.finish() else { return }
149
+ if case let .success(image) = result, let cacheKey {
150
+ cache.setObject(image, forKey: cacheKey, cost: imageCost(image))
151
+ }
152
+ request.completion(result)
153
+ }
154
+
155
+ private func reject(_ id: UUID, message: String) {
156
+ DispatchQueue.main.async { [weak self] in
157
+ self?.finish(id, result: .failure(MapImageLoadException(message)))
158
+ }
159
+ }
160
+
161
+ private func fail(
162
+ _ token: MapImageLoadToken,
163
+ completion: @escaping (Result<UIImage, Error>) -> Void,
164
+ message: String
165
+ ) {
166
+ DispatchQueue.main.async {
167
+ if token.finish() {
168
+ completion(.failure(MapImageLoadException(message)))
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+ private func imageCost(_ image: UIImage) -> Int {
175
+ guard let cgImage = image.cgImage else { return 0 }
176
+ return cgImage.bytesPerRow * cgImage.height
177
+ }