Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rnmbxcodegen #3552

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 42 additions & 121 deletions android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.rnmapbox.rnmbx.components.images.RNMBXImageManager
import com.rnmapbox.rnmbx.components.images.RNMBXImageModule
import com.rnmapbox.rnmbx.components.images.RNMBXImagesManager
import com.rnmapbox.rnmbx.components.location.RNMBXCustomLocationProviderManager
import com.rnmapbox.rnmbx.components.location.RNMBXLocationManager
import com.rnmapbox.rnmbx.components.location.RNMBXNativeUserLocationManager
import com.rnmapbox.rnmbx.components.mapview.NativeMapViewModule
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapViewManager
Expand Down Expand Up @@ -60,7 +61,7 @@ import com.rnmapbox.rnmbx.utils.ViewTagResolver
class RNMBXPackage : TurboReactPackage() {

var viewTagResolver: ViewTagResolver? = null
fun getViewTagResolver(context: ReactApplicationContext, module: String) : ViewTagResolver {
fun getViewTagResolver(context: ReactApplicationContext, @Suppress("UNUSED_PARAMETER") module: String) : ViewTagResolver {
val viewTagResolver = viewTagResolver
if (viewTagResolver == null) {
val result = ViewTagResolver(context)
Expand All @@ -71,7 +72,7 @@ class RNMBXPackage : TurboReactPackage() {
}

var shapeAnimators: ShapeAnimatorManager? = null
fun getShapeAnimators(module: String): ShapeAnimatorManager {
fun getShapeAnimators(@Suppress("UNUSED_PARAMETER") module: String): ShapeAnimatorManager {
val shapeAnimators = shapeAnimators
if (shapeAnimators == null) {
val result = ShapeAnimatorManager()
Expand Down Expand Up @@ -123,6 +124,7 @@ class RNMBXPackage : TurboReactPackage() {
managers.add(RNMBXMapViewManager(reactApplicationContext, getViewTagResolver(reactApplicationContext, "RNMBXMapViewManager")))
managers.add(RNMBXStyleImportManager(reactApplicationContext))
managers.add(RNMBXModelsManager(reactApplicationContext))
managers.add(RNMBXLocationManager(reactApplicationContext, getViewTagResolver(reactApplicationContext, "RNMBXLocationManager")))

// annotations
managers.add(RNMBXMarkerViewManager(reactApplicationContext))
Expand Down Expand Up @@ -163,145 +165,64 @@ class RNMBXPackage : TurboReactPackage() {
return managers
}

fun reactModuleInfo(
name: String,
isTurboModule: Boolean = false
): ReactModuleInfo {
return ReactModuleInfo(
/*name=*/name,
/*className=*/name,
/*canOverrideExistingModule=*/false,
/*needsEagerInit=*/false,
/*hasConstants=*/true,
/*isCxxModule=*/false,
/*isTurboModule=*/isTurboModule
)
}

override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
resetViewTagResolver()
return ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
moduleInfos[RNMBXModule.REACT_CLASS] = ReactModuleInfo(
RNMBXModule.REACT_CLASS,
RNMBXModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[RNMBXLocationModule.REACT_CLASS] = ReactModuleInfo(
RNMBXLocationModule.REACT_CLASS,
RNMBXLocationModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[RNMBXOfflineModule.REACT_CLASS] = ReactModuleInfo(
RNMBXOfflineModule.REACT_CLASS,
RNMBXOfflineModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[RNMBXTileStoreModule.REACT_CLASS] = ReactModuleInfo(
RNMBXTileStoreModule.REACT_CLASS,
RNMBXTileStoreModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[RNMBXOfflineModuleLegacy.REACT_CLASS] = ReactModuleInfo(
RNMBXOfflineModuleLegacy.REACT_CLASS,
RNMBXOfflineModuleLegacy.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[RNMBXSnapshotModule.REACT_CLASS] = ReactModuleInfo(
RNMBXSnapshotModule.REACT_CLASS,
RNMBXSnapshotModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[RNMBXLogging.REACT_CLASS] = ReactModuleInfo(
RNMBXLogging.REACT_CLASS,
RNMBXLogging.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
)
moduleInfos[NativeMapViewModule.NAME] = ReactModuleInfo(
moduleInfos[RNMBXModule.REACT_CLASS] = reactModuleInfo(RNMBXModule.REACT_CLASS)
moduleInfos[RNMBXLocationModule.REACT_CLASS] = reactModuleInfo(RNMBXLocationModule.REACT_CLASS)
moduleInfos[RNMBXOfflineModule.REACT_CLASS] = reactModuleInfo(RNMBXOfflineModule.REACT_CLASS)
moduleInfos[RNMBXTileStoreModule.REACT_CLASS] = reactModuleInfo(RNMBXTileStoreModule.REACT_CLASS)
moduleInfos[RNMBXOfflineModuleLegacy.REACT_CLASS] = reactModuleInfo(RNMBXOfflineModuleLegacy.REACT_CLASS)
moduleInfos[RNMBXSnapshotModule.REACT_CLASS] = reactModuleInfo(RNMBXSnapshotModule.REACT_CLASS)
moduleInfos[RNMBXLogging.REACT_CLASS] = reactModuleInfo(RNMBXLogging.REACT_CLASS)
moduleInfos[NativeMapViewModule.NAME] = reactModuleInfo(
NativeMapViewModule.NAME,
NativeMapViewModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
isTurboModule=isTurboModule
)
moduleInfos[RNMBXViewportModule.NAME] = ReactModuleInfo(
RNMBXViewportModule.NAME,
moduleInfos[RNMBXViewportModule.NAME] = reactModuleInfo(
RNMBXViewportModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
isTurboModule= isTurboModule
)
moduleInfos[RNMBXCameraModule.NAME] = ReactModuleInfo(
moduleInfos[RNMBXCameraModule.NAME] = reactModuleInfo(
RNMBXCameraModule.NAME,
RNMBXCameraModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
isTurboModule= isTurboModule
)
moduleInfos[RNMBXShapeSourceModule.NAME] = ReactModuleInfo(
RNMBXShapeSourceModule.NAME,
moduleInfos[RNMBXShapeSourceModule.NAME] = reactModuleInfo(
RNMBXShapeSourceModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
isTurboModule= isTurboModule
)
moduleInfos[RNMBXImageModule.NAME] = ReactModuleInfo(
moduleInfos[RNMBXImageModule.NAME] = reactModuleInfo(
RNMBXImageModule.NAME,
RNMBXImageModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
isTurboModule= isTurboModule
)
moduleInfos[RNMBXPointAnnotationModule.NAME] = ReactModuleInfo(
RNMBXPointAnnotationModule.NAME,
moduleInfos[RNMBXPointAnnotationModule.NAME] = reactModuleInfo(
RNMBXPointAnnotationModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
isTurboModule= isTurboModule
)
moduleInfos[RNMBXMovePointShapeAnimatorModule.NAME] = ReactModuleInfo(
moduleInfos[RNMBXMovePointShapeAnimatorModule.NAME] = reactModuleInfo(
RNMBXMovePointShapeAnimatorModule.NAME,
RNMBXMovePointShapeAnimatorModule.NAME,
false,
false,
false,
false,
isTurboModule
isTurboModule= isTurboModule
)
moduleInfos[RNMBXChangeLineOffsetsShapeAnimatorModule.NAME] = ReactModuleInfo(
RNMBXChangeLineOffsetsShapeAnimatorModule.NAME,
moduleInfos[RNMBXChangeLineOffsetsShapeAnimatorModule.NAME] = reactModuleInfo(
RNMBXChangeLineOffsetsShapeAnimatorModule.NAME,
false,
false,
false,
false,
isTurboModule
isTurboModule= isTurboModule
)
moduleInfos
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,9 @@ import com.mapbox.maps.EdgeInsets
import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateBearing
import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateOptions
import com.mapbox.maps.plugin.viewport.data.OverviewViewportStateOptions
import com.rnmapbox.rnmbx.events.BaseEvent
import com.rnmapbox.rnmbx.events.constants.EventKeys

class BaseEvent(
private val surfaceId: Int,
private val viewTag: Int,
private val eventName: String,
private val eventData: WritableMap,
private val canCoalesce: Boolean = false
): Event<BaseEvent>(surfaceId, viewTag) {
override fun getEventName(): String {
return eventName
}

override fun canCoalesce(): Boolean {
return canCoalesce
}

override fun getEventData(): WritableMap? {
return eventData
}
}

class RNMBXViewport(private val mContext: Context, private val mManager: RNMBXViewportManager) :
AbstractMapFeature(
mContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.rnmapbox.rnmbx.components.location

import com.rnmapbox.rnmbx.v11compat.Cancelable
import com.mapbox.maps.MapView
import com.mapbox.maps.plugin.locationcomponent.DefaultLocationProvider
import com.mapbox.maps.plugin.locationcomponent.LocationProvider
import com.mapbox.maps.plugin.locationcomponent.location
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
import java.lang.ref.WeakReference

typealias CallbackType = (old: LocationProvider, new: LocationProvider) -> Unit;


class CallbackList<T> {
class Entry<T>(val callback: T, val list: WeakReference<CallbackList<T>>): Cancelable {

override fun cancel() {
list.get()?.remove(this)
}
}
private val callbacks = mutableListOf<Entry<T>>()

fun add(callback: T): Cancelable {
val result = Entry<T>(callback, WeakReference(this));
callbacks.add(result)
return result;
}

internal fun remove(entry: Entry<T>) {
callbacks.remove(entry)
}

fun forEach(callback: (it: T) -> Unit) {
callbacks.map { it.callback }.forEach(callback)
}
}


class LocationProviderManager(val mapView: RNMBXMapView) {
var callbacks = CallbackList<CallbackType>()

fun getLocationProvider(mapView: MapView): LocationProvider {
val location = mapView.location
val result = location.getLocationProvider()

if (result != null) {
return result
} else {
val result = DefaultLocationProvider(mapView.context)
location.setLocationProvider(result)
return result
}
}

fun update(provider: LocationProvider) {
mapView.withMapView { mapView: MapView ->
val location = mapView.location
val oldProvider = location.getLocationProvider()
location.setLocationProvider(provider)

if (oldProvider != null) {
apply(oldProvider, provider)
}
}
}

fun onChange(callback: CallbackType): Cancelable =
callbacks.add(callback)

fun apply(old: LocationProvider, new: LocationProvider) {
callbacks.forEach { it(old, new) }
}
}
Loading
Loading