-
-
Notifications
You must be signed in to change notification settings - Fork 847
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
554 additions
and
16 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
168 changes: 168 additions & 0 deletions
168
android/src/main/java/com/rnmapbox/rnmbx/RCTMGLPackage.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,168 @@ | ||
package com.rnmapbox.rnmbx | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.JavaScriptModule | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import com.facebook.react.uimanager.ViewManager | ||
import com.rnmapbox.rnmbx.components.annotation.RCTMGLCalloutManager | ||
import com.rnmapbox.rnmbx.components.annotation.RCTMGLMarkerViewManager | ||
import com.rnmapbox.rnmbx.components.annotation.RCTMGLPointAnnotationManager | ||
import com.rnmapbox.rnmbx.components.camera.RCTMGLCameraManager | ||
import com.rnmapbox.rnmbx.components.images.RCTMGLImageManager | ||
import com.rnmapbox.rnmbx.components.images.RCTMGLImagesManager | ||
import com.rnmapbox.rnmbx.components.location.RCTMGLNativeUserLocationManager | ||
import com.rnmapbox.rnmbx.components.mapview.NativeMapViewModule | ||
import com.rnmapbox.rnmbx.components.mapview.RCTMGLAndroidTextureMapViewManager | ||
import com.rnmapbox.rnmbx.components.mapview.RCTMGLMapViewManager | ||
import com.rnmapbox.rnmbx.components.styles.RNMBXStyleImportManager | ||
import com.rnmapbox.rnmbx.components.styles.atmosphere.RCTMGLAtmosphereManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLBackgroundLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLCircleLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLFillExtrusionLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLFillLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLHeatmapLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLLineLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLRasterLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLSkyLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.layers.RCTMGLSymbolLayerManager | ||
import com.rnmapbox.rnmbx.components.styles.light.RCTMGLLightManager | ||
import com.rnmapbox.rnmbx.components.styles.sources.RCTMGLImageSourceManager | ||
import com.rnmapbox.rnmbx.components.styles.sources.RCTMGLRasterDemSourceManager | ||
import com.rnmapbox.rnmbx.components.styles.sources.RCTMGLRasterSourceManager | ||
import com.rnmapbox.rnmbx.components.styles.sources.RCTMGLShapeSourceManager | ||
import com.rnmapbox.rnmbx.components.styles.sources.RCTMGLVectorSourceManager | ||
import com.rnmapbox.rnmbx.components.styles.terrain.RCTMGLTerrainManager | ||
import com.rnmapbox.rnmbx.modules.RCTMGLLocationModule | ||
import com.rnmapbox.rnmbx.modules.RCTMGLLogging | ||
import com.rnmapbox.rnmbx.modules.RCTMGLModule | ||
import com.rnmapbox.rnmbx.modules.RCTMGLOfflineModule | ||
import com.rnmapbox.rnmbx.modules.RCTMGLSnapshotModule | ||
|
||
class RCTMGLPackage : TurboReactPackage() { | ||
override fun getModule( | ||
s: String, | ||
reactApplicationContext: ReactApplicationContext | ||
): NativeModule? { | ||
when (s) { | ||
RCTMGLModule.REACT_CLASS -> return RCTMGLModule(reactApplicationContext) | ||
RCTMGLLocationModule.REACT_CLASS -> return RCTMGLLocationModule(reactApplicationContext) | ||
RCTMGLOfflineModule.REACT_CLASS -> return RCTMGLOfflineModule(reactApplicationContext) | ||
RCTMGLSnapshotModule.REACT_CLASS -> return RCTMGLSnapshotModule(reactApplicationContext) | ||
RCTMGLLogging.REACT_CLASS -> return RCTMGLLogging(reactApplicationContext) | ||
NativeMapViewModule.NAME -> return NativeMapViewModule(reactApplicationContext) | ||
} | ||
return null | ||
} | ||
|
||
@Deprecated("") | ||
fun createJSModules(): List<Class<out JavaScriptModule?>> { | ||
return emptyList() | ||
} | ||
|
||
override fun createViewManagers(reactApplicationContext: ReactApplicationContext): List<ViewManager<*, *>> { | ||
val managers: MutableList<ViewManager<*, *>> = ArrayList() | ||
|
||
// components | ||
managers.add(RCTMGLCameraManager(reactApplicationContext)) | ||
managers.add(RCTMGLAndroidTextureMapViewManager(reactApplicationContext)) | ||
managers.add(RCTMGLMapViewManager(reactApplicationContext)) | ||
managers.add(RNMBXStyleImportManager(reactApplicationContext)) | ||
|
||
// annotations | ||
managers.add(RCTMGLMarkerViewManager(reactApplicationContext)) | ||
managers.add(RCTMGLPointAnnotationManager(reactApplicationContext)) | ||
managers.add(RCTMGLCalloutManager()) | ||
managers.add(RCTMGLNativeUserLocationManager()) | ||
|
||
// sources | ||
managers.add(RCTMGLVectorSourceManager(reactApplicationContext)) | ||
managers.add(RCTMGLShapeSourceManager(reactApplicationContext)) | ||
managers.add(RCTMGLRasterDemSourceManager(reactApplicationContext)) | ||
managers.add(RCTMGLRasterSourceManager(reactApplicationContext)) | ||
managers.add(RCTMGLImageSourceManager()) | ||
|
||
// images | ||
managers.add(RCTMGLImagesManager(reactApplicationContext)) | ||
managers.add(RCTMGLImageManager(reactApplicationContext)) | ||
|
||
// layers | ||
managers.add(RCTMGLFillLayerManager()) | ||
managers.add(RCTMGLFillExtrusionLayerManager()) | ||
managers.add(RCTMGLHeatmapLayerManager()) | ||
managers.add(RCTMGLLineLayerManager()) | ||
managers.add(RCTMGLCircleLayerManager()) | ||
managers.add(RCTMGLSymbolLayerManager()) | ||
managers.add(RCTMGLRasterLayerManager()) | ||
managers.add(RCTMGLSkyLayerManager()) | ||
managers.add(RCTMGLTerrainManager()) | ||
managers.add(RCTMGLAtmosphereManager()) | ||
managers.add(RCTMGLBackgroundLayerManager()) | ||
managers.add(RCTMGLLightManager()) | ||
return managers | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { | ||
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap() | ||
val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED | ||
moduleInfos[RCTMGLModule.REACT_CLASS] = ReactModuleInfo( | ||
RCTMGLModule.REACT_CLASS, | ||
RCTMGLModule.REACT_CLASS, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
false // isTurboModule | ||
) | ||
moduleInfos[RCTMGLLocationModule.REACT_CLASS] = ReactModuleInfo( | ||
RCTMGLLocationModule.REACT_CLASS, | ||
RCTMGLLocationModule.REACT_CLASS, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
false // isTurboModule | ||
) | ||
moduleInfos[RCTMGLOfflineModule.REACT_CLASS] = ReactModuleInfo( | ||
RCTMGLOfflineModule.REACT_CLASS, | ||
RCTMGLOfflineModule.REACT_CLASS, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
false // isTurboModule | ||
) | ||
moduleInfos[RCTMGLSnapshotModule.REACT_CLASS] = ReactModuleInfo( | ||
RCTMGLSnapshotModule.REACT_CLASS, | ||
RCTMGLSnapshotModule.REACT_CLASS, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
false // isTurboModule | ||
) | ||
moduleInfos[RCTMGLLogging.REACT_CLASS] = ReactModuleInfo( | ||
RCTMGLLogging.REACT_CLASS, | ||
RCTMGLLogging.REACT_CLASS, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
false // isTurboModule | ||
) | ||
moduleInfos[NativeMapViewModule.NAME] = ReactModuleInfo( | ||
NativeMapViewModule.NAME, | ||
NativeMapViewModule.NAME, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
false, // hasConstants | ||
false, // isCxxModule | ||
isTurboModule // isTurboModule | ||
) | ||
moduleInfos | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleImport.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,35 @@ | ||
package com.mapbox.rctmgl.components.styles | ||
|
||
import android.content.Context | ||
import android.view.ViewGroup | ||
import com.mapbox.bindgen.Value | ||
import com.mapbox.rctmgl.components.AbstractMapFeature | ||
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView | ||
|
||
class RNMBXStyleImport(context: Context) : AbstractMapFeature(context) { | ||
var id: String? = null; | ||
|
||
var config: HashMap<String, Value> = hashMapOf() | ||
set(value: HashMap<String, Value>) { | ||
field = value | ||
if (mMapView != null) { updateConfig() } | ||
} | ||
|
||
override fun addToMap(mapView: RCTMGLMapView) { | ||
super.addToMap(mapView) | ||
updateConfig() | ||
} | ||
|
||
fun updateConfig() { | ||
withMapView {mapView -> | ||
id?.let { id -> | ||
val config = this.config | ||
if (config.isNotEmpty()) { | ||
mapView.mapView.getMapboxMap().getStyle() | ||
?.setStyleImportConfigProperties(id, config) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleImportManager.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,57 @@ | ||
package com.mapbox.rctmgl.components.styles | ||
|
||
import com.facebook.react.bridge.Dynamic | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.bridge.ReadableType | ||
import com.facebook.react.common.MapBuilder | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
import com.facebook.react.viewmanagers.RNMBXStyleImportManagerInterface | ||
import com.mapbox.rctmgl.components.AbstractEventEmitter | ||
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView | ||
import com.mapbox.bindgen.Value | ||
import com.mapbox.rctmgl.utils.Logger | ||
import com.mapbox.rctmgl.utils.extensions.toValueHashMap | ||
import org.json.JSONObject | ||
|
||
class RNMBXStyleImportManager(context: ReactApplicationContext) : | ||
AbstractEventEmitter<RNMBXStyleImport>(context), | ||
RNMBXStyleImportManagerInterface<RNMBXStyleImport> { | ||
override fun customEvents(): Map<String, String>? { | ||
return MapBuilder.builder<String, String>().build() | ||
} | ||
|
||
override fun getName(): String { | ||
return REACT_CLASS | ||
} | ||
|
||
override fun createViewInstance(context: ThemedReactContext): RNMBXStyleImport { | ||
return RNMBXStyleImport(context) | ||
} | ||
|
||
companion object { | ||
const val REACT_CLASS = "RNMBXStyleImport" | ||
} | ||
|
||
@ReactProp(name = "id") | ||
override fun setId(view: RNMBXStyleImport, value: String?) { | ||
if (value != null) { | ||
view.id = value | ||
} | ||
} | ||
|
||
@ReactProp(name = "existing") | ||
override fun setExisting(view: RNMBXStyleImport, value: Boolean) { | ||
|
||
} | ||
|
||
@ReactProp(name = "config") | ||
override fun setConfig(view: RNMBXStyleImport, value: Dynamic) { | ||
if (value.type != ReadableType.Map) { | ||
Logger.e(REACT_CLASS, "config expected Map but received: ${value.type}") | ||
} else { | ||
view.config = value.asMap().toValueHashMap() | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Dynamic.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,57 @@ | ||
package com.rnmapbox.rnmbx.utils.extensions | ||
|
||
import com.facebook.react.bridge.Dynamic; | ||
import com.facebook.react.bridge.ReadableArray | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.bridge.ReadableType | ||
import com.mapbox.bindgen.Value | ||
|
||
fun ReadableMap.toValueHashMap(): HashMap<String, Value> { | ||
var result = hashMapOf<String, Value>() | ||
var iterator = keySetIterator() | ||
while (iterator.hasNextKey()) { | ||
val i = iterator.nextKey() | ||
|
||
result[i] = when (getType(i)) { | ||
ReadableType.Null -> Value.nullValue() | ||
ReadableType.Boolean -> Value.valueOf(getBoolean(i)) | ||
ReadableType.Number -> Value.valueOf(getDouble(i)) | ||
ReadableType.String -> Value.valueOf(getString(i)!!) | ||
ReadableType.Array -> getArray(i)!!.toValue() | ||
ReadableType.Map -> getMap(i)!!.toValue() | ||
} | ||
} | ||
return result | ||
} | ||
|
||
fun ReadableMap.toValue() : Value { | ||
return Value.valueOf(toValueHashMap()) | ||
} | ||
|
||
fun ReadableArray.toValue(): Value { | ||
var result = ArrayList<Value>(size()) | ||
|
||
for (i in 0 until size()) { | ||
result.add( | ||
when (getType(i)) { | ||
ReadableType.Null -> Value.nullValue() | ||
ReadableType.Boolean -> Value.valueOf(getBoolean(i)) | ||
ReadableType.Number -> Value.valueOf(getDouble(i)) | ||
ReadableType.String -> Value.valueOf(getString(i)) | ||
ReadableType.Array -> getArray(i).toValue() | ||
ReadableType.Map -> getMap(i).toValue() | ||
}) | ||
} | ||
return Value.valueOf(result) | ||
} | ||
|
||
fun Dynamic.toValue(): Value { | ||
return when (type) { | ||
ReadableType.Null -> Value.nullValue() | ||
ReadableType.Boolean -> Value.valueOf(asBoolean()) | ||
ReadableType.Number -> Value.valueOf(asDouble()) | ||
ReadableType.String -> Value.valueOf(asString()) | ||
ReadableType.Array -> asArray().toValue() | ||
ReadableType.Map -> asMap().toValue() | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...n/old-arch/com/facebook/react/viewmanagers/RNMBXAndroidTextureMapViewManagerDelegate.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
3 changes: 2 additions & 1 deletion
3
.../old-arch/com/facebook/react/viewmanagers/RNMBXAndroidTextureMapViewManagerInterface.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
3 changes: 2 additions & 1 deletion
3
android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.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
3 changes: 2 additions & 1 deletion
3
android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.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
Oops, something went wrong.