Skip to content

Commit

Permalink
fix: events in bridgeless mode (#3656)
Browse files Browse the repository at this point in the history
  • Loading branch information
WoLewicki authored Oct 13, 2024
1 parent c05ecad commit 2980630
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNMBXRasterSourceManagerInterface
import com.rnmapbox.rnmbx.events.constants.EventKeys
import com.rnmapbox.rnmbx.events.constants.eventMapOf
import javax.annotation.Nonnull

class RNMBXRasterSourceManager(reactApplicationContext: ReactApplicationContext) :
Expand All @@ -26,7 +28,10 @@ class RNMBXRasterSourceManager(reactApplicationContext: ReactApplicationContext)
}

override fun customEvents(): Map<String, String>? {
return null
return eventMapOf(
EventKeys.RASTER_SOURCE_LAYER_CLICK to "onMapboxRasterSourcePress",
EventKeys.MAP_ANDROID_CALLBACK to "onAndroidCallback"
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ private fun ns(name: String): String {
val namespace = "rct.mapbox"
return String.format("%s.%s", namespace, name)
}

enum class EventKeys(val value: String) {
// map events
MAP_CLICK(ns("map.press")),
MAP_LONG_CLICK(ns("map.longpress")),
MAP_ONCHANGE(ns("map.change")),
MAP_ON_LOCATION_CHANGE(ns("map.location.change")),
MAP_ANDROID_CALLBACK(ns("map.androidcallback")),
MAP_USER_TRACKING_MODE_CHANGE(ns("map.usertrackingmodechange")),
MAP_CLICK("topPress"),
MAP_LONG_CLICK("topLongPress"),
MAP_ONCHANGE("topMapChange"),
MAP_ON_LOCATION_CHANGE("topLocationChange"),
MAP_ANDROID_CALLBACK("topAndroidCallback"),
MAP_USER_TRACKING_MODE_CHANGE("topUserTrackingModeChange"),

// point annotation events
POINT_ANNOTATION_SELECTED(ns("pointannotation.selected")),
POINT_ANNOTATION_DESELECTED(ns("pointannotation.deselected")),
POINT_ANNOTATION_DRAG_START(ns("pointannotation.dragstart")),
POINT_ANNOTATION_DRAG(ns("pointannotation.drag")),
POINT_ANNOTATION_DRAG_END(ns("pointannotation.dragend")),
POINT_ANNOTATION_SELECTED("topMapboxPointAnnotationSelected"),
POINT_ANNOTATION_DESELECTED("topMapboxPointAnnotationDeselected"),
POINT_ANNOTATION_DRAG_START("topMapboxPointAnnotationDragStart"),
POINT_ANNOTATION_DRAG("topMapboxPointAnnotationDrag"),
POINT_ANNOTATION_DRAG_END("topMapboxPointAnnotationDragEnd"),

// source events
SHAPE_SOURCE_LAYER_CLICK(ns("shapesource.layer.pressed")),
VECTOR_SOURCE_LAYER_CLICK(ns("vectorsource.layer.pressed")),
RASTER_SOURCE_LAYER_CLICK(ns("rastersource.layer.pressed")),
SHAPE_SOURCE_LAYER_CLICK("topMapboxShapeSourcePress"),
VECTOR_SOURCE_LAYER_CLICK("topMapboxVectorSourcePress"),
RASTER_SOURCE_LAYER_CLICK("topMapboxRasterSourcePress"),

// images event
IMAGES_MISSING(ns("images.missing")),
IMAGES_MISSING("topImageMissing"),

// location events
// TODO: not sure about this one since it is not registered anywhere
USER_LOCATION_UPDATE(ns("user.location.update")),

// viewport events
VIEWPORT_STATUS_CHANGE(ns("viewport.statuschange"))
VIEWPORT_STATUS_CHANGE("topStatusChanged")
}

fun eventMapOf(vararg values: Pair<EventKeys, String>): Map<String, String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainApplication : Application(), ReactApplication {
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load(bridgelessEnabled=false)
load()
}
}
}

0 comments on commit 2980630

Please sign in to comment.