-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from mym0404/ground-overlay
Ground Overlay
- Loading branch information
Showing
20 changed files
with
735 additions
and
57 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
81 changes: 81 additions & 0 deletions
81
android/src/main/java/com/mjstudio/reactnativenavermap/overlay/ground/RNCNaverMapGround.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,81 @@ | ||
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.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 | ||
import com.naver.maps.map.util.MarkerIcons | ||
|
||
@SuppressLint("ViewConstructor") | ||
class RNCNaverMapGround(private val reactContext: ThemedReactContext) : | ||
RNCNaverMapOverlay<GroundOverlay>(reactContext) { | ||
private val imageHolder: DraweeHolder<GenericDraweeHierarchy>? by lazy { | ||
DraweeHolder.create(createDraweeHierarchy(resources), reactContext)?.apply { | ||
onAttach() | ||
} | ||
} | ||
private var lastImage: ReadableMap? = null | ||
private var imageRequestCanceller: ImageRequestCanceller? = null | ||
private var isImageSet = false | ||
|
||
override val overlay: GroundOverlay by lazy { | ||
GroundOverlay().apply { | ||
setOnClickListener { | ||
reactContext.emitEvent(id) { surfaceId, reactTag -> | ||
NaverMapOverlayTapEvent( | ||
surfaceId, | ||
reactTag, | ||
) | ||
} | ||
true | ||
} | ||
} | ||
} | ||
|
||
override fun addToMap(map: NaverMap) { | ||
if (!isImageSet) { | ||
overlay.image = MarkerIcons.GREEN | ||
overlay.alpha = 0f | ||
} | ||
overlay.map = map | ||
} | ||
|
||
override fun removeFromMap(map: NaverMap) { | ||
overlay.map = null | ||
} | ||
|
||
override fun onDropViewInstance() { | ||
overlay.map = null | ||
overlay.onClickListener = null | ||
imageHolder?.onDetach() | ||
imageRequestCanceller?.invoke() | ||
} | ||
|
||
fun setImage(image: ReadableMap?) { | ||
lastImage = image | ||
overlay.alpha = 0f | ||
imageRequestCanceller?.invoke() | ||
imageRequestCanceller = | ||
getOverlayImage(imageHolder!!, context, image?.toHashMap()) { | ||
setOverlayImage(it) | ||
isImageSet = true | ||
overlay.alpha = 1f | ||
} | ||
} | ||
|
||
private fun setOverlayImage(image: OverlayImage?) { | ||
overlay.image = | ||
image ?: OverlayImage.fromBitmap(Bitmap.createBitmap(0, 0, Bitmap.Config.ARGB_8888)) | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...src/main/java/com/mjstudio/reactnativenavermap/overlay/ground/RNCNaverMapGroundManager.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,106 @@ | ||
package com.mjstudio.reactnativenavermap.overlay.ground | ||
|
||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
import com.mjstudio.reactnativenavermap.RNCNaverMapGroundManagerSpec | ||
import com.mjstudio.reactnativenavermap.event.NaverMapOverlayTapEvent | ||
import com.mjstudio.reactnativenavermap.util.getLatLngBoundsOrNull | ||
import com.mjstudio.reactnativenavermap.util.registerDirectEvent | ||
import com.naver.maps.map.overlay.GroundOverlay | ||
|
||
class RNCNaverMapGroundManager : RNCNaverMapGroundManagerSpec<RNCNaverMapGround>() { | ||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
override fun createViewInstance(context: ThemedReactContext): RNCNaverMapGround { | ||
return RNCNaverMapGround(context) | ||
} | ||
|
||
override fun onDropViewInstance(view: RNCNaverMapGround) { | ||
super.onDropViewInstance(view) | ||
view.onDropViewInstance() | ||
} | ||
|
||
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> = | ||
(super.getExportedCustomDirectEventTypeConstants() ?: mutableMapOf()).apply { | ||
registerDirectEvent(this, NaverMapOverlayTapEvent.EVENT_NAME) | ||
} | ||
|
||
private fun RNCNaverMapGround?.withOverlay(fn: (GroundOverlay) -> Unit) { | ||
this?.overlay?.run(fn) | ||
} | ||
|
||
@ReactProp(name = "zIndexValue") | ||
override fun setZIndexValue( | ||
view: RNCNaverMapGround?, | ||
value: Int, | ||
) = view.withOverlay { | ||
it.zIndex = value | ||
} | ||
|
||
@ReactProp(name = "isHidden") | ||
override fun setIsHidden( | ||
view: RNCNaverMapGround?, | ||
value: Boolean, | ||
) = view.withOverlay { | ||
it.isVisible = !value | ||
} | ||
|
||
@ReactProp(name = "minZoom") | ||
override fun setMinZoom( | ||
view: RNCNaverMapGround?, | ||
value: Double, | ||
) = view.withOverlay { | ||
it.minZoom = value | ||
} | ||
|
||
@ReactProp(name = "maxZoom") | ||
override fun setMaxZoom( | ||
view: RNCNaverMapGround?, | ||
value: Double, | ||
) = view.withOverlay { | ||
it.maxZoom = value | ||
} | ||
|
||
@ReactProp(name = "isMinZoomInclusive") | ||
override fun setIsMinZoomInclusive( | ||
view: RNCNaverMapGround?, | ||
value: Boolean, | ||
) = view.withOverlay { | ||
it.isMinZoomInclusive = value | ||
} | ||
|
||
@ReactProp(name = "isMaxZoomInclusive") | ||
override fun setIsMaxZoomInclusive( | ||
view: RNCNaverMapGround?, | ||
value: Boolean, | ||
) = view.withOverlay { | ||
it.isMaxZoomInclusive = value | ||
} | ||
|
||
@ReactProp(name = "image") | ||
override fun setImage( | ||
view: RNCNaverMapGround?, | ||
value: ReadableMap?, | ||
) { | ||
view?.setImage(value) | ||
} | ||
|
||
@ReactProp(name = "region") | ||
override fun setRegion( | ||
view: RNCNaverMapGround?, | ||
value: ReadableMap?, | ||
) = view.withOverlay { | ||
value?.getLatLngBoundsOrNull()?. run { | ||
it.bounds = this | ||
} | ||
} | ||
|
||
// region PROPS | ||
|
||
companion object { | ||
const val NAME = "RNCNaverMapGround" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mjstudio.reactnativenavermap | ||
|
||
import android.view.View | ||
import com.facebook.react.uimanager.SimpleViewManager | ||
import com.facebook.react.uimanager.ViewManagerDelegate | ||
import com.facebook.react.viewmanagers.RNCNaverMapGroundManagerDelegate | ||
import com.facebook.react.viewmanagers.RNCNaverMapGroundManagerInterface | ||
|
||
abstract class RNCNaverMapGroundManagerSpec<T : View> : | ||
SimpleViewManager<T>(), | ||
RNCNaverMapGroundManagerInterface<T?> { | ||
private val mDelegate: ViewManagerDelegate<T> | ||
|
||
init { | ||
mDelegate = RNCNaverMapGroundManagerDelegate(this) | ||
} | ||
|
||
override fun getDelegate(): ViewManagerDelegate<T>? { | ||
return mDelegate | ||
} | ||
} |
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,51 @@ | ||
package com.mjstudio.reactnativenavermap | ||
|
||
import android.view.View | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.uimanager.SimpleViewManager | ||
|
||
internal interface RNCNaverMapGroundManagerInterface<T : View?> { | ||
fun setZIndexValue( | ||
view: T, | ||
value: Int, | ||
) | ||
|
||
fun setIsHidden( | ||
view: T, | ||
value: Boolean, | ||
) | ||
|
||
fun setMinZoom( | ||
view: T, | ||
value: Double, | ||
) | ||
|
||
fun setMaxZoom( | ||
view: T, | ||
value: Double, | ||
) | ||
|
||
fun setIsMinZoomInclusive( | ||
view: T, | ||
value: Boolean, | ||
) | ||
|
||
fun setIsMaxZoomInclusive( | ||
view: T, | ||
value: Boolean, | ||
) | ||
|
||
fun setImage( | ||
view: T, | ||
value: ReadableMap?, | ||
) | ||
|
||
fun setRegion( | ||
view: T, | ||
value: ReadableMap?, | ||
) | ||
} | ||
|
||
abstract class RNCNaverMapGroundManagerSpec<T : View> : | ||
SimpleViewManager<T>(), | ||
RNCNaverMapGroundManagerInterface<T?> |
Oops, something went wrong.