-
-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate RNMBXPointAnnotation to new arch (#3130)
* feat: implement proper native ref resolving * feat: add specs * feat: migrate android code * feat: migrate ios code * fix: tests * fix: remove command on android * fix: small fixes for atmosphere * feat: migrate js code of Callout and MarkerView * feat: migrate ios code of Callout and MarkerView * feat: migrate Android code of Callout and MarkerView * fix: add missing method
- Loading branch information
Showing
48 changed files
with
1,119 additions
and
474 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
18 changes: 0 additions & 18 deletions
18
android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXCalloutManager.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXCalloutManager.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,33 @@ | ||
package com.rnmapbox.rnmbx.components.annotation | ||
|
||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.ViewGroupManager | ||
import com.facebook.react.uimanager.ViewManagerDelegate | ||
import com.facebook.react.viewmanagers.RNMBXCalloutManagerDelegate | ||
import com.facebook.react.viewmanagers.RNMBXCalloutManagerInterface | ||
|
||
class RNMBXCalloutManager : ViewGroupManager<RNMBXCallout>(), | ||
RNMBXCalloutManagerInterface<RNMBXCallout> { | ||
|
||
private val mDelegate: ViewManagerDelegate<RNMBXCallout> | ||
|
||
init { | ||
mDelegate = RNMBXCalloutManagerDelegate(this) | ||
} | ||
|
||
override fun getDelegate(): ViewManagerDelegate<RNMBXCallout> { | ||
return mDelegate | ||
} | ||
|
||
override fun getName(): String { | ||
return REACT_CLASS | ||
} | ||
|
||
override fun createViewInstance(reactContext: ThemedReactContext): RNMBXCallout { | ||
return RNMBXCallout(reactContext) | ||
} | ||
|
||
companion object { | ||
const val REACT_CLASS = "RNMBXCallout" | ||
} | ||
} |
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
84 changes: 0 additions & 84 deletions
84
...d/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationManager.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...oid/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationManager.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,70 @@ | ||
package com.rnmapbox.rnmbx.components.annotation | ||
|
||
import com.facebook.react.bridge.Dynamic | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.common.MapBuilder | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.ViewManagerDelegate | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
import com.facebook.react.viewmanagers.RNMBXPointAnnotationManagerDelegate | ||
import com.facebook.react.viewmanagers.RNMBXPointAnnotationManagerInterface | ||
import com.rnmapbox.rnmbx.components.AbstractEventEmitter | ||
import com.rnmapbox.rnmbx.events.constants.EventKeys | ||
import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toPointGeometry | ||
|
||
class RNMBXPointAnnotationManager(reactApplicationContext: ReactApplicationContext) : AbstractEventEmitter<RNMBXPointAnnotation>(reactApplicationContext), | ||
RNMBXPointAnnotationManagerInterface<RNMBXPointAnnotation> { | ||
|
||
private val mDelegate: ViewManagerDelegate<RNMBXPointAnnotation> | ||
|
||
init { | ||
mDelegate = RNMBXPointAnnotationManagerDelegate(this) | ||
} | ||
|
||
override fun getDelegate(): ViewManagerDelegate<RNMBXPointAnnotation> { | ||
return mDelegate | ||
} | ||
|
||
override fun getName(): String { | ||
return REACT_CLASS | ||
} | ||
|
||
override fun customEvents(): Map<String, String> { | ||
return MapBuilder.builder<String, String>() | ||
.put(EventKeys.POINT_ANNOTATION_SELECTED, "onMapboxPointAnnotationSelected") | ||
.put(EventKeys.POINT_ANNOTATION_DESELECTED, "onMapboxPointAnnotationDeselected") | ||
.put(EventKeys.POINT_ANNOTATION_DRAG_START, "onMapboxPointAnnotationDragStart") | ||
.put(EventKeys.POINT_ANNOTATION_DRAG, "onMapboxPointAnnotationDrag") | ||
.put(EventKeys.POINT_ANNOTATION_DRAG_END, "onMapboxPointAnnotationDragEnd") | ||
.build() | ||
} | ||
|
||
// TODO: check why it does not work correctly | ||
override fun createViewInstance(reactContext: ThemedReactContext): RNMBXPointAnnotation { | ||
return RNMBXPointAnnotation(reactContext!!, this) | ||
} | ||
|
||
@ReactProp(name = "id") | ||
override fun setId(annotation: RNMBXPointAnnotation, id: Dynamic) { | ||
annotation.iD = id.asString() | ||
} | ||
|
||
@ReactProp(name = "coordinate") | ||
override fun setCoordinate(annotation: RNMBXPointAnnotation, geoJSONStr: Dynamic) { | ||
annotation.setCoordinate(toPointGeometry(geoJSONStr.asString())!!) | ||
} | ||
|
||
@ReactProp(name = "anchor") | ||
override fun setAnchor(annotation: RNMBXPointAnnotation, map: Dynamic) { | ||
annotation.setAnchor(map.asMap().getDouble("x").toFloat(), map.asMap().getDouble("y").toFloat()) | ||
} | ||
|
||
@ReactProp(name = "draggable") | ||
override fun setDraggable(annotation: RNMBXPointAnnotation, draggable: Dynamic) { | ||
annotation.setDraggable(draggable.asBoolean()) | ||
} | ||
|
||
companion object { | ||
const val REACT_CLASS = "RNMBXPointAnnotation" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationModule.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,33 @@ | ||
package com.rnmapbox.rnmbx.components.annotation | ||
|
||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactMethod | ||
import com.facebook.react.module.annotations.ReactModule | ||
import com.rnmapbox.rnmbx.NativeRNMBXPointAnnotationModuleSpec | ||
import com.rnmapbox.rnmbx.utils.ViewTagResolver | ||
|
||
@ReactModule(name = RNMBXPointAnnotationModule.NAME) | ||
class RNMBXPointAnnotationModule(reactContext: ReactApplicationContext?, private val viewTagResolver: ViewTagResolver) : | ||
NativeRNMBXPointAnnotationModuleSpec(reactContext) { | ||
|
||
companion object { | ||
const val NAME = "RNMBXPointAnnotationModule" | ||
} | ||
|
||
private fun withPointAnnotationOnUIThread(viewRef: Double?, reject: Promise, fn: (RNMBXPointAnnotation) -> Unit) { | ||
if (viewRef == null) { | ||
reject.reject(Exception("viewRef is null for RNMBXPointAnnotation")) | ||
} else { | ||
viewTagResolver.withViewResolved(viewRef.toInt(), reject, fn) | ||
} | ||
} | ||
|
||
@ReactMethod | ||
override fun refresh(viewRef: Double?, promise: Promise) { | ||
withPointAnnotationOnUIThread(viewRef, promise) { | ||
it.refresh() | ||
promise.resolve(null) | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXCalloutManagerDelegate.java
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,25 @@ | ||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GeneratePropsJavaDelegate.js | ||
*/ | ||
|
||
package com.facebook.react.viewmanagers; | ||
|
||
import android.view.View; | ||
import androidx.annotation.Nullable; | ||
import com.facebook.react.uimanager.BaseViewManagerDelegate; | ||
import com.facebook.react.uimanager.BaseViewManagerInterface; | ||
|
||
public class RNMBXCalloutManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNMBXCalloutManagerInterface<T>> extends BaseViewManagerDelegate<T, U> { | ||
public RNMBXCalloutManagerDelegate(U viewManager) { | ||
super(viewManager); | ||
} | ||
@Override | ||
public void setProperty(T view, String propName, @Nullable Object value) { | ||
super.setProperty(view, propName, value); | ||
} | ||
} |
Oops, something went wrong.