diff --git a/.husky/_/commit-msg b/.husky/_/commit-msg index 21c69a40..450ab876 100755 --- a/.husky/_/commit-msg +++ b/.husky/_/commit-msg @@ -1,2 +1,53 @@ -#!/usr/bin/env sh -. "${0%/*}/h" \ No newline at end of file +#!/bin/sh + +if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then + set -x +fi + +if [ "$LEFTHOOK" = "0" ]; then + exit 0 +fi + +call_lefthook() +{ + dir="$(git rev-parse --show-toplevel)" + osArch=$(uname | tr '[:upper:]' '[:lower:]') + cpuArch=$(uname -m | sed 's/aarch64/arm64/') + + if test -n "$LEFTHOOK_BIN" + then + "$LEFTHOOK_BIN" "$@" + elif lefthook -h >/dev/null 2>&1 + then + lefthook "$@" + elif test -f "$dir/node_modules/lefthook/bin/index.js" + then + "$dir/node_modules/lefthook/bin/index.js" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + + elif bundle exec lefthook -h >/dev/null 2>&1 + then + bundle exec lefthook "$@" + elif yarn lefthook -h >/dev/null 2>&1 + then + yarn lefthook "$@" + elif pnpm lefthook -h >/dev/null 2>&1 + then + pnpm lefthook "$@" + elif swift package plugin lefthook >/dev/null 2>&1 + then + swift package --disable-sandbox plugin lefthook "$@" + elif command -v npx >/dev/null 2>&1 + then + npx lefthook "$@" + else + echo "Can't find lefthook in PATH" + fi +} + +call_lefthook run "commit-msg" "$@" diff --git a/.husky/_/lint b/.husky/_/lint deleted file mode 100755 index 44d60ef4..00000000 --- a/.husky/_/lint +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then - set -x -fi - -if [ "$LEFTHOOK" = "0" ]; then - exit 0 -fi - -call_lefthook() -{ - dir="$(git rev-parse --show-toplevel)" - osArch=$(uname | tr '[:upper:]' '[:lower:]') - cpuArch=$(uname -m | sed 's/aarch64/arm64/') - - if test -n "$LEFTHOOK_BIN" - then - "$LEFTHOOK_BIN" "$@" - elif lefthook -h >/dev/null 2>&1 - then - lefthook "$@" - elif test -f "$dir/node_modules/lefthook/bin/index.js" - then - "$dir/node_modules/lefthook/bin/index.js" "$@" - elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" - then - "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" - elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" - then - "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" - - elif bundle exec lefthook -h >/dev/null 2>&1 - then - bundle exec lefthook "$@" - elif yarn lefthook -h >/dev/null 2>&1 - then - yarn lefthook "$@" - elif pnpm lefthook -h >/dev/null 2>&1 - then - pnpm lefthook "$@" - elif swift package plugin lefthook >/dev/null 2>&1 - then - swift package --disable-sandbox plugin lefthook "$@" - elif command -v npx >/dev/null 2>&1 - then - npx lefthook "$@" - else - echo "Can't find lefthook in PATH" - fi -} - -call_lefthook run "lint" "$@" diff --git a/.husky/_/pre-commit b/.husky/_/pre-commit index 21c69a40..27e9906a 100755 --- a/.husky/_/pre-commit +++ b/.husky/_/pre-commit @@ -1,2 +1,53 @@ -#!/usr/bin/env sh -. "${0%/*}/h" \ No newline at end of file +#!/bin/sh + +if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then + set -x +fi + +if [ "$LEFTHOOK" = "0" ]; then + exit 0 +fi + +call_lefthook() +{ + dir="$(git rev-parse --show-toplevel)" + osArch=$(uname | tr '[:upper:]' '[:lower:]') + cpuArch=$(uname -m | sed 's/aarch64/arm64/') + + if test -n "$LEFTHOOK_BIN" + then + "$LEFTHOOK_BIN" "$@" + elif lefthook -h >/dev/null 2>&1 + then + lefthook "$@" + elif test -f "$dir/node_modules/lefthook/bin/index.js" + then + "$dir/node_modules/lefthook/bin/index.js" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + + elif bundle exec lefthook -h >/dev/null 2>&1 + then + bundle exec lefthook "$@" + elif yarn lefthook -h >/dev/null 2>&1 + then + yarn lefthook "$@" + elif pnpm lefthook -h >/dev/null 2>&1 + then + pnpm lefthook "$@" + elif swift package plugin lefthook >/dev/null 2>&1 + then + swift package --disable-sandbox plugin lefthook "$@" + elif command -v npx >/dev/null 2>&1 + then + npx lefthook "$@" + else + echo "Can't find lefthook in PATH" + fi +} + +call_lefthook run "pre-commit" "$@" diff --git a/.husky/_/pre-push b/.husky/_/pre-push deleted file mode 100755 index 21c69a40..00000000 --- a/.husky/_/pre-push +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -. "${0%/*}/h" \ No newline at end of file diff --git a/.husky/_/prepare-commit-msg b/.husky/_/prepare-commit-msg index 21c69a40..115dba76 100755 --- a/.husky/_/prepare-commit-msg +++ b/.husky/_/prepare-commit-msg @@ -1,2 +1,53 @@ -#!/usr/bin/env sh -. "${0%/*}/h" \ No newline at end of file +#!/bin/sh + +if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then + set -x +fi + +if [ "$LEFTHOOK" = "0" ]; then + exit 0 +fi + +call_lefthook() +{ + dir="$(git rev-parse --show-toplevel)" + osArch=$(uname | tr '[:upper:]' '[:lower:]') + cpuArch=$(uname -m | sed 's/aarch64/arm64/') + + if test -n "$LEFTHOOK_BIN" + then + "$LEFTHOOK_BIN" "$@" + elif lefthook -h >/dev/null 2>&1 + then + lefthook "$@" + elif test -f "$dir/node_modules/lefthook/bin/index.js" + then + "$dir/node_modules/lefthook/bin/index.js" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" + then + "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@" + + elif bundle exec lefthook -h >/dev/null 2>&1 + then + bundle exec lefthook "$@" + elif yarn lefthook -h >/dev/null 2>&1 + then + yarn lefthook "$@" + elif pnpm lefthook -h >/dev/null 2>&1 + then + pnpm lefthook "$@" + elif swift package plugin lefthook >/dev/null 2>&1 + then + swift package --disable-sandbox plugin lefthook "$@" + elif command -v npx >/dev/null 2>&1 + then + npx lefthook "$@" + else + echo "Can't find lefthook in PATH" + fi +} + +call_lefthook run "prepare-commit-msg" "$@" diff --git a/README.md b/README.md index 0596a721..b6d20022 100644 --- a/README.md +++ b/README.md @@ -618,14 +618,6 @@ iOS에선 단순히 `UIView`를 `UIImage`로 캔버스에 그려 표시해줍니 | caption-fontFamily | ❓ | ❓ | | subcaption-fontFamily | ❓ | ❓ | -### `NaverMapPathOverlay` - -#### Props - -| Prop | iOS | Android | -|------------------------|-----|---------| -| patternImage | 📦 | 📦 | - ## Supporting Table - Architecture | | iOS | Android | diff --git a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/ground/RNCNaverMapGround.kt b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/ground/RNCNaverMapGround.kt index e07e0b4a..eaa4d12c 100644 --- a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/ground/RNCNaverMapGround.kt +++ b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/ground/RNCNaverMapGround.kt @@ -2,16 +2,10 @@ package com.mjstudio.reactnativenavermap.overlay.ground import android.annotation.SuppressLint import android.graphics.Bitmap -import com.facebook.drawee.generic.GenericDraweeHierarchy -import com.facebook.drawee.view.DraweeHolder -import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.ThemedReactContext import com.mjstudio.reactnativenavermap.event.NaverMapOverlayTapEvent -import com.mjstudio.reactnativenavermap.overlay.RNCNaverMapOverlay -import com.mjstudio.reactnativenavermap.util.ImageRequestCanceller -import com.mjstudio.reactnativenavermap.util.createDraweeHierarchy +import com.mjstudio.reactnativenavermap.util.RNCNaverMapImageRenderableOverlay import com.mjstudio.reactnativenavermap.util.emitEvent -import com.mjstudio.reactnativenavermap.util.getOverlayImage import com.naver.maps.map.NaverMap import com.naver.maps.map.overlay.GroundOverlay import com.naver.maps.map.overlay.OverlayImage @@ -19,14 +13,7 @@ import com.naver.maps.map.util.MarkerIcons @SuppressLint("ViewConstructor") class RNCNaverMapGround(private val reactContext: ThemedReactContext) : - RNCNaverMapOverlay(reactContext) { - private val imageHolder: DraweeHolder? by lazy { - DraweeHolder.create(createDraweeHierarchy(resources), reactContext)?.apply { - onAttach() - } - } - private var lastImage: ReadableMap? = null - private var imageRequestCanceller: ImageRequestCanceller? = null + RNCNaverMapImageRenderableOverlay(reactContext) { private var isImageSet = false override val overlay: GroundOverlay by lazy { @@ -58,23 +45,15 @@ class RNCNaverMapGround(private val reactContext: ThemedReactContext) : override fun onDropViewInstance() { overlay.map = null overlay.onClickListener = null - imageHolder?.onDetach() - imageRequestCanceller?.invoke() + super.onDropViewInstance() } - fun setImage(image: ReadableMap?) { - lastImage = image - overlay.alpha = 0f - imageRequestCanceller?.invoke() - imageRequestCanceller = - getOverlayImage(imageHolder!!, context, image?.toHashMap()) { - setOverlayImage(it) - isImageSet = true - overlay.alpha = 1f - } + override fun setOverlayAlpha(alpha: Float) { + overlay.alpha = alpha } - private fun setOverlayImage(image: OverlayImage?) { + override fun setOverlayImage(image: OverlayImage?) { + isImageSet = true overlay.image = image ?: OverlayImage.fromBitmap(Bitmap.createBitmap(0, 0, Bitmap.Config.ARGB_8888)) } diff --git a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/marker/RNCNaverMapMarker.kt b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/marker/RNCNaverMapMarker.kt index c2b7a9b1..60fb599f 100644 --- a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/marker/RNCNaverMapMarker.kt +++ b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/marker/RNCNaverMapMarker.kt @@ -8,16 +8,10 @@ import android.view.View import androidx.core.view.children import com.airbnb.android.react.maps.TrackableView import com.airbnb.android.react.maps.ViewChangesTracker -import com.facebook.drawee.generic.GenericDraweeHierarchy -import com.facebook.drawee.view.DraweeHolder -import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.ThemedReactContext import com.mjstudio.reactnativenavermap.event.NaverMapOverlayTapEvent -import com.mjstudio.reactnativenavermap.overlay.RNCNaverMapOverlay -import com.mjstudio.reactnativenavermap.util.ImageRequestCanceller -import com.mjstudio.reactnativenavermap.util.createDraweeHierarchy +import com.mjstudio.reactnativenavermap.util.RNCNaverMapImageRenderableOverlay import com.mjstudio.reactnativenavermap.util.emitEvent -import com.mjstudio.reactnativenavermap.util.getOverlayImage import com.naver.maps.map.NaverMap import com.naver.maps.map.overlay.Marker import com.naver.maps.map.overlay.OverlayImage @@ -25,16 +19,10 @@ import kotlin.math.max @SuppressLint("ViewConstructor") class RNCNaverMapMarker(val reactContext: ThemedReactContext) : - RNCNaverMapOverlay(reactContext), TrackableView { - private val imageHolder: DraweeHolder? by lazy { - DraweeHolder.create(createDraweeHierarchy(resources), reactContext)?.apply { - onAttach() - } - } + RNCNaverMapImageRenderableOverlay(reactContext), TrackableView { private var customView: View? = null private var customViewBitmap: Bitmap? = null - private var lastImage: ReadableMap? = null - private var imageRequestCanceller: ImageRequestCanceller? = null + private var isImageSetFromSubview = false override val overlay: Marker by lazy { @@ -62,8 +50,7 @@ class RNCNaverMapMarker(val reactContext: ThemedReactContext) : override fun onDropViewInstance() { overlay.map = null overlay.onClickListener = null - imageHolder?.onDetach() - imageRequestCanceller?.invoke() + super.onDropViewInstance() } fun setCustomView( @@ -91,7 +78,7 @@ class RNCNaverMapMarker(val reactContext: ThemedReactContext) : ViewChangesTracker.getInstance().removeMarker(this) if (customViewBitmap != null && !customViewBitmap!!.isRecycled) customViewBitmap!!.recycle() isImageSetFromSubview = false - setImage(lastImage) + setImageWithLastImage() super.removeView(children.elementAt(index)) } @@ -125,6 +112,10 @@ class RNCNaverMapMarker(val reactContext: ThemedReactContext) : } } + override fun skipTryRender(): Boolean { + return isImageSetFromSubview + } + override fun updateCustomForTracking(): Boolean { return true } @@ -136,19 +127,11 @@ class RNCNaverMapMarker(val reactContext: ThemedReactContext) : updateCustomView() } - 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 - } + override fun setOverlayAlpha(alpha: Float) { + overlay.alpha = alpha } - private fun setOverlayImage(image: OverlayImage?) { + override fun setOverlayImage(image: OverlayImage?) { overlay.icon = image ?: OverlayImage.fromBitmap(Bitmap.createBitmap(0, 0, Bitmap.Config.ARGB_8888)) } diff --git a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPath.kt b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPath.kt index f86620e2..43eab384 100644 --- a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPath.kt +++ b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPath.kt @@ -3,14 +3,15 @@ package com.mjstudio.reactnativenavermap.overlay.path import android.annotation.SuppressLint import com.facebook.react.uimanager.ThemedReactContext import com.mjstudio.reactnativenavermap.event.NaverMapOverlayTapEvent -import com.mjstudio.reactnativenavermap.overlay.RNCNaverMapOverlay +import com.mjstudio.reactnativenavermap.util.RNCNaverMapImageRenderableOverlay import com.mjstudio.reactnativenavermap.util.emitEvent import com.naver.maps.map.NaverMap +import com.naver.maps.map.overlay.OverlayImage import com.naver.maps.map.overlay.PathOverlay @SuppressLint("ViewConstructor") class RNCNaverMapPath(val reactContext: ThemedReactContext) : - RNCNaverMapOverlay(reactContext) { + RNCNaverMapImageRenderableOverlay(reactContext) { override val overlay: PathOverlay by lazy { PathOverlay().apply { setOnClickListener { @@ -36,5 +37,13 @@ class RNCNaverMapPath(val reactContext: ThemedReactContext) : override fun onDropViewInstance() { overlay.map = null overlay.onClickListener = null + super.onDropViewInstance() + } + + override fun setOverlayAlpha(alpha: Float) { + } + + override fun setOverlayImage(image: OverlayImage?) { + overlay.patternImage = image } } diff --git a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPathManager.kt b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPathManager.kt index fc9bd07e..d7a56c1f 100644 --- a/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPathManager.kt +++ b/android/src/main/java/com/mjstudio/reactnativenavermap/overlay/path/RNCNaverMapPathManager.kt @@ -1,6 +1,7 @@ package com.mjstudio.reactnativenavermap.overlay.path import com.facebook.react.bridge.ReadableArray +import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.annotations.ReactProp import com.mjstudio.reactnativenavermap.RNCNaverMapPathManagerSpec @@ -132,7 +133,15 @@ class RNCNaverMapPathManager : RNCNaverMapPathManagerSpec() { it.passedColor = value } - @ReactProp(name = "pattern") + @ReactProp(name = "patternImage") + override fun setPatternImage( + view: RNCNaverMapPath?, + value: ReadableMap?, + ) { + view?.setImage(value) + } + + @ReactProp(name = "patternInterval") override fun setPatternInterval( view: RNCNaverMapPath?, value: Int, diff --git a/android/src/main/java/com/mjstudio/reactnativenavermap/util/RNCNaverMapImageRenderableOverlay.kt b/android/src/main/java/com/mjstudio/reactnativenavermap/util/RNCNaverMapImageRenderableOverlay.kt new file mode 100644 index 00000000..9a78100c --- /dev/null +++ b/android/src/main/java/com/mjstudio/reactnativenavermap/util/RNCNaverMapImageRenderableOverlay.kt @@ -0,0 +1,48 @@ +package com.mjstudio.reactnativenavermap.util + +import android.content.Context +import androidx.annotation.CallSuper +import com.facebook.drawee.generic.GenericDraweeHierarchy +import com.facebook.drawee.view.DraweeHolder +import com.facebook.react.bridge.ReadableMap +import com.mjstudio.reactnativenavermap.overlay.RNCNaverMapOverlay +import com.naver.maps.map.overlay.Overlay +import com.naver.maps.map.overlay.OverlayImage + +abstract class RNCNaverMapImageRenderableOverlay(private val context: Context) : RNCNaverMapOverlay(context) { + private val imageHolder: DraweeHolder? by lazy { + DraweeHolder.create(createDraweeHierarchy(resources), context)?.apply { + onAttach() + } + } + private var imageRequestCanceller: ImageRequestCanceller? = null + private var lastImage: ReadableMap? = null + + @CallSuper + override fun onDropViewInstance() { + imageHolder?.onDetach() + imageRequestCanceller?.invoke() + } + + protected abstract fun setOverlayAlpha(alpha: Float) + + protected abstract fun setOverlayImage(image: OverlayImage?) + + protected open fun skipTryRender() = false + + protected fun setImageWithLastImage() { + setImage(lastImage) + } + + fun setImage(image: ReadableMap?) { + lastImage = image + if (skipTryRender()) return + setOverlayAlpha(0f) + imageRequestCanceller?.invoke() + imageRequestCanceller = + getOverlayImage(imageHolder!!, context, image?.toHashMap()) { + setOverlayImage(it) + setOverlayAlpha(1f) + } + } +} diff --git a/android/src/oldarch/RNCNaverMapPathManagerSpec.kt b/android/src/oldarch/RNCNaverMapPathManagerSpec.kt index 00e14c13..54252fe4 100644 --- a/android/src/oldarch/RNCNaverMapPathManagerSpec.kt +++ b/android/src/oldarch/RNCNaverMapPathManagerSpec.kt @@ -2,6 +2,7 @@ package com.mjstudio.reactnativenavermap import android.view.View import com.facebook.react.bridge.ReadableArray +import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.SimpleViewManager internal interface RNCNaverMapPathManagerInterface { @@ -50,6 +51,11 @@ internal interface RNCNaverMapPathManagerInterface { value: Double, ) + fun setPatternImage( + view: T, + value: ReadableMap?, + ) + fun setPatternInterval( view: T, value: Int, diff --git a/example/src/App.tsx b/example/src/App.tsx index e6d4a091..b8002abf 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -7,7 +7,6 @@ import { type Camera, NaverMapView, type ClusterMarkerProp, - NaverMapArrowheadPathOverlay, NaverMapPathOverlay, NaverMapGroundOverlay, type Region, @@ -274,21 +273,23 @@ export default function App() { passedColor={'black'} outlineWidth={1} zIndex={1} + patternInterval={100} + patternImage={{ symbol: 'blue' }} /> - + {/**/} -#import -#import +#import #import #import #import diff --git a/ios/Overlay/ArrowheadPath/RNCNaverMapArrowheadPathManager.mm b/ios/Overlay/ArrowheadPath/RNCNaverMapArrowheadPathManager.mm index a0da66f2..3cacfbe7 100644 --- a/ios/Overlay/ArrowheadPath/RNCNaverMapArrowheadPathManager.mm +++ b/ios/Overlay/ArrowheadPath/RNCNaverMapArrowheadPathManager.mm @@ -8,8 +8,8 @@ #import "RCTConvert+NMFMapView.h" #import "RNCNaverMapArrowheadPath.h" #import -#import -#import +#import +#import #import #import #import diff --git a/ios/Overlay/Circle/RNCNaverMapCircle.h b/ios/Overlay/Circle/RNCNaverMapCircle.h index 5aaab09e..d679e844 100644 --- a/ios/Overlay/Circle/RNCNaverMapCircle.h +++ b/ios/Overlay/Circle/RNCNaverMapCircle.h @@ -9,7 +9,7 @@ #import "MacroUtil.h" #import "Utils.h" #import -#import +#import #import #import #import diff --git a/ios/Overlay/Circle/RNCNaverMapCircleManager.mm b/ios/Overlay/Circle/RNCNaverMapCircleManager.mm index c4b95202..3944e033 100644 --- a/ios/Overlay/Circle/RNCNaverMapCircleManager.mm +++ b/ios/Overlay/Circle/RNCNaverMapCircleManager.mm @@ -8,8 +8,8 @@ #import "RCTConvert+NMFMapView.h" #import "RNCNaverMapCircle.h" #import -#import -#import +#import +#import #import #import #import diff --git a/ios/Overlay/Cluster/RNCNaverMapClusterKey.h b/ios/Overlay/Cluster/RNCNaverMapClusterKey.h index d799b90a..e79c2a3d 100644 --- a/ios/Overlay/Cluster/RNCNaverMapClusterKey.h +++ b/ios/Overlay/Cluster/RNCNaverMapClusterKey.h @@ -6,8 +6,8 @@ // #import -#import -#import +#import +#import #import NS_ASSUME_NONNULL_BEGIN diff --git a/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.h b/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.h index c2162db9..fb86afc5 100644 --- a/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.h +++ b/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.h @@ -5,17 +5,7 @@ // Created by mj on 4/18/24. // #import "RNCNaverMapClusterKey.h" -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import +#import @interface RNCNaverMapClusterMarkerUpdater : NMCDefaultClusterMarkerUpdater @end diff --git a/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.mm b/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.mm index 40f4e8d8..10d91c70 100644 --- a/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.mm +++ b/ios/Overlay/Cluster/RNCNaverMapClusterMarkerUpdater.mm @@ -6,17 +6,7 @@ // #import "RNCNaverMapClusterMarkerUpdater.h" #import "RNCNaverMapClusterKey.h" -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import +#import @implementation RNCNaverMapClusterMarkerUpdater #pragma clang diagnostic push diff --git a/ios/Overlay/Cluster/RNCNaverMapLeafMarkerUpdater.h b/ios/Overlay/Cluster/RNCNaverMapLeafMarkerUpdater.h index a9943cc1..61202610 100644 --- a/ios/Overlay/Cluster/RNCNaverMapLeafMarkerUpdater.h +++ b/ios/Overlay/Cluster/RNCNaverMapLeafMarkerUpdater.h @@ -9,11 +9,7 @@ #import "RNCNaverMapClusterKey.h" #import "Utils.h" #import -#import -#import -#import -#import -#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/ios/Overlay/Ground/RNCNaverMapGround.h b/ios/Overlay/Ground/RNCNaverMapGround.h index 7cd029a6..eff8e76b 100644 --- a/ios/Overlay/Ground/RNCNaverMapGround.h +++ b/ios/Overlay/Ground/RNCNaverMapGround.h @@ -10,7 +10,7 @@ #import "RCTConvert+NMFMapView.h" #import "Utils.h" #import -#import +#import #import #import #import diff --git a/ios/Overlay/Ground/RNCNaverMapGround.mm b/ios/Overlay/Ground/RNCNaverMapGround.mm index 9cd6e8ec..ca121bde 100644 --- a/ios/Overlay/Ground/RNCNaverMapGround.mm +++ b/ios/Overlay/Ground/RNCNaverMapGround.mm @@ -128,19 +128,7 @@ - (void)updateProps:(Props::Shared const&)props oldProps:(Props::Shared const&)o } } - { - auto p = prev.image, n = next.image; - if (p.reuseIdentifier != n.reuseIdentifier || p.assetName != n.assetName || - p.httpUri != n.httpUri || p.rnAssetUri != n.rnAssetUri || p.symbol != n.symbol) { - self.image = @{ - @"reuseIdentifier" : getNsStr(n.reuseIdentifier), - @"assetName" : getNsStr(n.assetName), - @"httpUri" : getNsStr(n.httpUri), - @"rnAssetUri" : getNsStr(n.rnAssetUri), - @"symbol" : getNsStr(n.symbol), - }; - } - } + NMAP_REMAP_IMAGE_PROP(image, self.image) [super updateProps:props oldProps:oldProps]; } diff --git a/ios/Overlay/Ground/RNCNaverMapGroundManager.mm b/ios/Overlay/Ground/RNCNaverMapGroundManager.mm index ee82cb4e..f06a2246 100644 --- a/ios/Overlay/Ground/RNCNaverMapGroundManager.mm +++ b/ios/Overlay/Ground/RNCNaverMapGroundManager.mm @@ -8,7 +8,7 @@ #import "RCTConvert+NMFMapView.h" #import "RNCNaverMapGround.h" #import -#import +#import #import #import #import diff --git a/ios/Overlay/Marker/RNCNaverMapMarker.h b/ios/Overlay/Marker/RNCNaverMapMarker.h index d313a48f..363f8418 100644 --- a/ios/Overlay/Marker/RNCNaverMapMarker.h +++ b/ios/Overlay/Marker/RNCNaverMapMarker.h @@ -10,10 +10,7 @@ #import "RCTConvert+NMFMapView.h" #import "Utils.h" #import -#import -#import -#import -#import +#import #import #import #import diff --git a/ios/Overlay/Marker/RNCNaverMapMarker.mm b/ios/Overlay/Marker/RNCNaverMapMarker.mm index b81c956f..9fff9128 100644 --- a/ios/Overlay/Marker/RNCNaverMapMarker.mm +++ b/ios/Overlay/Marker/RNCNaverMapMarker.mm @@ -18,11 +18,7 @@ @implementation RNCNaverMapMarker { void (^_imageCanceller)(void); BOOL _isImageSetFromSubview; } -static NSMutableDictionary* _overlayImageHolder; -/** - https://github.com/software-mansion/react-native-screens/blob/a8bb418a8428befbb264ef958a5d7f7ea743048a/ios/RNSScreenStackHeaderSubview.mm#L100 - */ - (RCTBridge*)bridge { #ifdef RCT_NEW_ARCH_ENABLED return [RCTBridge currentBridge]; @@ -31,8 +27,6 @@ - (RCTBridge*)bridge { #endif } -// static NSMutableDictionary* _overlayImageHolder; - //+ (void)initialize { // _overlayImageHolder = [[NSMutableDictionary alloc] init]; //} @@ -41,9 +35,6 @@ - (instancetype)init { if ((self = [super init])) { _inner = [NMFMarker new]; _isImageSetFromSubview = NO; - if (!_overlayImageHolder) { - _overlayImageHolder = [NSMutableDictionary new]; - } #ifdef RCT_NEW_ARCH_ENABLED self.onTapOverlay = [self](NSDictionary* dict) { @@ -253,19 +244,7 @@ - (void)updateProps:(Props::Shared const&)props oldProps:(Props::Shared const&)o NMAP_REMAP_SELF_PROP(isForceShowIcon); NMAP_REMAP_SELF_PROP(tintColor); - { - auto p = prev.image, n = next.image; - if (p.reuseIdentifier != n.reuseIdentifier || p.assetName != n.assetName || - p.httpUri != n.httpUri || p.rnAssetUri != n.rnAssetUri || p.symbol != n.symbol) { - self.image = @{ - @"reuseIdentifier" : getNsStr(n.reuseIdentifier), - @"assetName" : getNsStr(n.assetName), - @"httpUri" : getNsStr(n.httpUri), - @"rnAssetUri" : getNsStr(n.rnAssetUri), - @"symbol" : getNsStr(n.symbol), - }; - } - } + NMAP_REMAP_IMAGE_PROP(image, self.image) if (next.caption.key != prev.caption.key) { self.caption = @{ diff --git a/ios/Overlay/Marker/RNCNaverMapMarkerManager.h b/ios/Overlay/Marker/RNCNaverMapMarkerManager.h index 944a20fe..0cf7f2b6 100644 --- a/ios/Overlay/Marker/RNCNaverMapMarkerManager.h +++ b/ios/Overlay/Marker/RNCNaverMapMarkerManager.h @@ -9,7 +9,7 @@ #import "RNCNaverMapMarker.h" #import #import -#import +#import #import #import #import diff --git a/ios/Overlay/Path/RNCNaverMapPath.h b/ios/Overlay/Path/RNCNaverMapPath.h index a0557242..548b803b 100644 --- a/ios/Overlay/Path/RNCNaverMapPath.h +++ b/ios/Overlay/Path/RNCNaverMapPath.h @@ -10,8 +10,9 @@ #import "RCTConvert+NMFMapView.h" #import "Utils.h" #import -#import -#import +#import +#import +#import #import #import #import @@ -29,6 +30,8 @@ @interface RNCNaverMapPath : RCTView #endif +@property(nonatomic, weak) RCTBridge* bridge; + @property(nonatomic, strong) NMFPath* inner; @property(nonatomic, assign) NSInteger zIndexValue; @@ -42,6 +45,7 @@ @property(nonatomic, copy) NSArray* coords; @property(nonatomic, assign) double width; @property(nonatomic, assign) double outlineWidth; +@property(nonatomic, copy) NSDictionary* patternImage; @property(nonatomic, assign) NSInteger patternInterval; @property(nonatomic, assign) double progress; @property(nonatomic, assign) NSInteger color; diff --git a/ios/Overlay/Path/RNCNaverMapPath.mm b/ios/Overlay/Path/RNCNaverMapPath.mm index a00e9adf..e7b0f95d 100644 --- a/ios/Overlay/Path/RNCNaverMapPath.mm +++ b/ios/Overlay/Path/RNCNaverMapPath.mm @@ -16,6 +16,15 @@ @interface RNCNaverMapPath () #endif @implementation RNCNaverMapPath { + void (^_imageCanceller)(void); +} + +- (RCTBridge*)bridge { +#ifdef RCT_NEW_ARCH_ENABLED + return [RCTBridge currentBridge]; +#else + return _bridge; +#endif } - (instancetype)init { @@ -46,6 +55,13 @@ - (instancetype)init { return self; } +- (void)dealloc { + if (_imageCanceller) { + _imageCanceller(); + _imageCanceller = nil; + } +} + NMAP_SETTER(Z, z, IndexValue, inner.zIndex, NSInteger) NMAP_SETTER(I, i, sHidden, inner.hidden, BOOL) NMAP_INNER_SETTER(M, m, inZoom, double) @@ -54,6 +70,27 @@ - (instancetype)init { NMAP_INNER_SETTER(I, i, sMaxZoomInclusive, BOOL) NMAP_INNER_SETTER(W, w, idth, double) + +- (void)setPatternImage:(NSDictionary*)patternImage { + _patternImage = patternImage; + if (!patternImage) { + _inner.patternIcon = nil; + return; + } + + // Cancel pending request + if (_imageCanceller) { + _imageCanceller(); + _imageCanceller = nil; + } + + _imageCanceller = [Utils getImage:[self bridge] + json:patternImage + callback:^(NMFOverlayImage* image) { + dispatch_async(dispatch_get_main_queue(), + [self, image]() { self.inner.patternIcon = image; }); + }]; +} NMAP_INNER_SETTER(P, p, atternInterval, NSInteger) NMAP_INNER_SETTER(P, p, rogress, double) @@ -152,6 +189,7 @@ - (void)updateProps:(Props::Shared const&)props oldProps:(Props::Shared const&)o } } + NMAP_REMAP_IMAGE_PROP(patternImage, self.patternImage) [super updateProps:props oldProps:oldProps]; } diff --git a/ios/Overlay/Path/RNCNaverMapPathManager.mm b/ios/Overlay/Path/RNCNaverMapPathManager.mm index 0fb25951..23d8be26 100644 --- a/ios/Overlay/Path/RNCNaverMapPathManager.mm +++ b/ios/Overlay/Path/RNCNaverMapPathManager.mm @@ -8,8 +8,8 @@ #import "RCTConvert+NMFMapView.h" #import "RNCNaverMapPath.h" #import -#import -#import +#import +#import #import #import #import @@ -26,7 +26,9 @@ + (BOOL)requiresMainQueueSetup { } - (UIView*)view { - return [RNCNaverMapPath new]; + auto ret = [RNCNaverMapPath new]; + ret.bridge = self.bridge; + return ret; } // MARK: - COMMON PROPS @@ -42,6 +44,7 @@ - (UIView*)view { RCT_EXPORT_VIEW_PROPERTY(coords, NSArray*) RCT_EXPORT_VIEW_PROPERTY(width, double) RCT_EXPORT_VIEW_PROPERTY(outlineWidth, double) +RCT_EXPORT_VIEW_PROPERTY(patternImage, NSDictionary) RCT_EXPORT_VIEW_PROPERTY(patternInterval, NSInteger) RCT_EXPORT_VIEW_PROPERTY(progress, double) RCT_EXPORT_VIEW_PROPERTY(color, NSInteger) diff --git a/ios/Overlay/Polygon/RNCNaverMapPolygon.h b/ios/Overlay/Polygon/RNCNaverMapPolygon.h index fefa8464..325b569e 100644 --- a/ios/Overlay/Polygon/RNCNaverMapPolygon.h +++ b/ios/Overlay/Polygon/RNCNaverMapPolygon.h @@ -10,7 +10,7 @@ #import "RCTConvert+NMFMapView.h" #import "Utils.h" #import -#import +#import #import #import #import diff --git a/ios/Overlay/Polygon/RNCNaverMapPolygonManager.mm b/ios/Overlay/Polygon/RNCNaverMapPolygonManager.mm index 14daa05c..39d4a90b 100644 --- a/ios/Overlay/Polygon/RNCNaverMapPolygonManager.mm +++ b/ios/Overlay/Polygon/RNCNaverMapPolygonManager.mm @@ -8,8 +8,8 @@ #import "RCTConvert+NMFMapView.h" #import "RNCNaverMapPolygon.h" #import -#import -#import +#import +#import #import #import #import diff --git a/ios/Overlay/Polyline/RNCNaverMapPolyline.h b/ios/Overlay/Polyline/RNCNaverMapPolyline.h index 7601c9e2..bcc23312 100644 --- a/ios/Overlay/Polyline/RNCNaverMapPolyline.h +++ b/ios/Overlay/Polyline/RNCNaverMapPolyline.h @@ -10,7 +10,7 @@ #import "RCTConvert+NMFMapView.h" #import "Utils.h" #import -#import +#import #import #import #import diff --git a/ios/Overlay/Polyline/RNCNaverMapPolylineManager.mm b/ios/Overlay/Polyline/RNCNaverMapPolylineManager.mm index edc644a2..7398a559 100644 --- a/ios/Overlay/Polyline/RNCNaverMapPolylineManager.mm +++ b/ios/Overlay/Polyline/RNCNaverMapPolylineManager.mm @@ -8,8 +8,8 @@ #import "RCTConvert+NMFMapView.h" #import "RNCNaverMapPolyline.h" #import -#import -#import +#import +#import #import #import #import diff --git a/ios/RNCNaverMapViewImpl.h b/ios/RNCNaverMapViewImpl.h index ba044a94..e59b8d34 100644 --- a/ios/RNCNaverMapViewImpl.h +++ b/ios/RNCNaverMapViewImpl.h @@ -23,23 +23,8 @@ #import "RNCNaverMapPolyline.h" #import "Utils.h" #import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import +#import +#import #import #import #import diff --git a/ios/Util/MacroUtil.h b/ios/Util/MacroUtil.h index 61b77185..9ec49852 100644 --- a/ios/Util/MacroUtil.h +++ b/ios/Util/MacroUtil.h @@ -45,4 +45,17 @@ RNCNaverMapRectMake(next.name.top, next.name.right, next.name.bottom, next.name.left); \ } +#define NMAP_REMAP_IMAGE_PROP(name, setter) \ + auto p = prev.name, n = next.name; \ + if (p.reuseIdentifier != n.reuseIdentifier || p.assetName != n.assetName || \ + p.httpUri != n.httpUri || p.rnAssetUri != n.rnAssetUri || p.symbol != n.symbol) { \ + setter = @{ \ + @"reuseIdentifier" : getNsStr(n.reuseIdentifier), \ + @"assetName" : getNsStr(n.assetName), \ + @"httpUri" : getNsStr(n.httpUri), \ + @"rnAssetUri" : getNsStr(n.rnAssetUri), \ + @"symbol" : getNsStr(n.symbol), \ + }; \ + } + #endif /* MacroUtil_h */ diff --git a/ios/Util/RCTConvert+NMFMapView.h b/ios/Util/RCTConvert+NMFMapView.h index 0740e070..346787e6 100644 --- a/ios/Util/RCTConvert+NMFMapView.h +++ b/ios/Util/RCTConvert+NMFMapView.h @@ -9,11 +9,8 @@ #import "RNCNaverMapRect.h" #import "RNCNaverMapRegion.h" -#import -#import -#import -#import -#import +#import +#import @interface RCTConvert (NMFMapView) diff --git a/ios/Util/Utils.h b/ios/Util/Utils.h index 8460fea8..a80a5dd9 100644 --- a/ios/Util/Utils.h +++ b/ios/Util/Utils.h @@ -3,8 +3,7 @@ #import "FnUtil.h" #import -#import -#import +#import #import #import #import diff --git a/src/component/NaverMapPathOverlay.tsx b/src/component/NaverMapPathOverlay.tsx index 09bdad8d..2328d0e5 100644 --- a/src/component/NaverMapPathOverlay.tsx +++ b/src/component/NaverMapPathOverlay.tsx @@ -3,8 +3,9 @@ import React from 'react'; import type { BaseOverlayProps } from '../types/BaseOverlayProps'; import { type ColorValue, processColor } from 'react-native'; import { Const } from '../internal/util/Const'; -import type { Coord } from '@mj-studio/react-native-naver-map'; +import type { Coord, MarkerImageProp } from '@mj-studio/react-native-naver-map'; import { nAssert } from '../internal/util/Assert'; +import { convertJsImagePropToNativeProp } from '../internal/Util'; export interface NaverMapPathOverlayProps extends BaseOverlayProps { /** @@ -27,6 +28,13 @@ export interface NaverMapPathOverlayProps extends BaseOverlayProps { * @default 0 */ outlineWidth?: number; + /** + * 패턴을 의미하는 이미지를 삽입할 수 있습니다. + * 패턴 이미지의 크기가 경로선의 두께보다 클 경우 경로선의 두께에 맞게 축소됩니다. undefined일 경우 패턴을 표시하지 않습니다. + * + * @default undefined + */ + patternImage?: MarkerImageProp; /** * patternInterval 속성을 사용하면 패턴 이미지 간 간격을 지정할 수 있습니다. 0일 경우 패턴이 그려지지 않습니다. * @@ -109,6 +117,7 @@ export const NaverMapPathOverlay = ({ outlineWidth = 0, passedColor = 'black', passedOutlineColor = 'black', + patternImage, patternInterval = 0, progress = 0, onTap, @@ -141,6 +150,9 @@ export const NaverMapPathOverlay = ({ passedColor={processColor(passedColor) as number} passedOutlineColor={processColor(passedOutlineColor) as number} outlineColor={processColor(outlineColor) as number} + patternImage={ + patternImage ? convertJsImagePropToNativeProp(patternImage) : undefined + } patternInterval={patternInterval} outlineWidth={outlineWidth} progress={progress} diff --git a/src/spec/RNCNaverMapPathNativeComponent.ts b/src/spec/RNCNaverMapPathNativeComponent.ts index c28c05e2..5c794ec5 100644 --- a/src/spec/RNCNaverMapPathNativeComponent.ts +++ b/src/spec/RNCNaverMapPathNativeComponent.ts @@ -23,6 +23,16 @@ type Coord = { latitude: Double; longitude: Double; }; +type NativeImageProp = + | undefined + | Readonly<{ + symbol?: string; + rnAssetUri?: string; + httpUri?: string; + assetName?: string; + reuseIdentifier?: string; + }>; + //////////////////// interface Props extends BaseOverlay, ViewProps { @@ -31,6 +41,7 @@ interface Props extends BaseOverlay, ViewProps { width?: Double; outlineWidth?: Double; patternInterval?: Int32; + patternImage?: NativeImageProp; progress?: Double; color?: Int32; passedColor?: Int32;