@rnmapbox/maps 10.0.0-rc.2 → 10.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.kt +75 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapViewManager.kt +28 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +4 -3
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLRasterSourceManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLTileSourceManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLVectorSourceManager.kt +1 -1
- package/package.json +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.java +0 -82
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapViewManager.java +0 -31
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.components
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.view.ViewGroup
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.common.MapBuilder
|
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
+
import com.facebook.react.uimanager.UIManagerModule
|
|
9
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
10
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
11
|
+
import com.mapbox.rctmgl.events.IEvent
|
|
12
|
+
import javax.annotation.Nonnull
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Created by nickitaliano on 8/23/17.
|
|
16
|
+
*/
|
|
17
|
+
abstract class AbstractEventEmitter<T : ViewGroup?>(reactApplicationContext: ReactApplicationContext) :
|
|
18
|
+
ViewGroupManager<T>() {
|
|
19
|
+
private val mRateLimitedEvents: MutableMap<String, Long>
|
|
20
|
+
private var mEventDispatcher: EventDispatcher? = null
|
|
21
|
+
private val mRCTAppContext: ReactApplicationContext
|
|
22
|
+
|
|
23
|
+
init {
|
|
24
|
+
mRateLimitedEvents = HashMap()
|
|
25
|
+
mRCTAppContext = reactApplicationContext
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
val activity : Activity?
|
|
29
|
+
get() = mRCTAppContext.currentActivity
|
|
30
|
+
|
|
31
|
+
fun handleEvent(event: IEvent) {
|
|
32
|
+
val eventCacheKey = getEventCacheKey(event)
|
|
33
|
+
|
|
34
|
+
// fail safe to protect bridge from being spammed
|
|
35
|
+
if (shouldDropEvent(eventCacheKey, event)) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
mRateLimitedEvents[eventCacheKey] = System.currentTimeMillis()
|
|
39
|
+
mEventDispatcher!!.dispatchEvent(
|
|
40
|
+
AbstractEvent(
|
|
41
|
+
event.id,
|
|
42
|
+
event.key,
|
|
43
|
+
event.canCoalesce(),
|
|
44
|
+
event.toJSON()
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun addEventEmitters(context: ThemedReactContext, @Nonnull view: T) {
|
|
50
|
+
mEventDispatcher = context.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
|
|
54
|
+
val events = customEvents() ?: return null
|
|
55
|
+
val exportedEvents: MutableMap<String, Any> = HashMap()
|
|
56
|
+
for ((key, value) in events) {
|
|
57
|
+
exportedEvents[key] = MapBuilder.of("registrationName", value)
|
|
58
|
+
}
|
|
59
|
+
return exportedEvents
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
abstract fun customEvents(): Map<String, String>?
|
|
63
|
+
private fun shouldDropEvent(cacheKey: String, event: IEvent): Boolean {
|
|
64
|
+
val lastEventTimestamp = mRateLimitedEvents[cacheKey]
|
|
65
|
+
return lastEventTimestamp != null && event.timestamp - lastEventTimestamp <= BRIDGE_TIMEOUT_MS
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private fun getEventCacheKey(event: IEvent): String {
|
|
69
|
+
return String.format("%s-%s", event.key, event.type)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
companion object {
|
|
73
|
+
private const val BRIDGE_TIMEOUT_MS = 10.0
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -14,7 +14,7 @@ import com.mapbox.maps.viewannotation.OnViewAnnotationUpdatedListener
|
|
|
14
14
|
import com.mapbox.maps.viewannotation.ViewAnnotationManager
|
|
15
15
|
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
16
16
|
|
|
17
|
-
class RCTMGLMarkerViewManager(reactApplicationContext: ReactApplicationContext
|
|
17
|
+
class RCTMGLMarkerViewManager(reactApplicationContext: ReactApplicationContext) :
|
|
18
18
|
AbstractEventEmitter<RCTMGLMarkerView?>(reactApplicationContext) {
|
|
19
19
|
override fun getName(): String {
|
|
20
20
|
return REACT_CLASS
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.components.mapview
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
|
|
6
|
+
//import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Created by hernanmateo on 12/11/18.
|
|
9
|
+
*/
|
|
10
|
+
class RCTMGLAndroidTextureMapViewManager(context: ReactApplicationContext?) : RCTMGLMapViewManager(
|
|
11
|
+
context!!
|
|
12
|
+
) {
|
|
13
|
+
override fun getName(): String {
|
|
14
|
+
return REACT_CLASS
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun createViewInstance(themedReactContext: ThemedReactContext): RCTMGLAndroidTextureMapView {
|
|
18
|
+
//MapboxMapOptions options = new MapboxMapOptions();
|
|
19
|
+
//options.textureMode(true);
|
|
20
|
+
val context = activity ?: themedReactContext
|
|
21
|
+
return RCTMGLAndroidTextureMapView(context, this /*, options*/)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
companion object {
|
|
25
|
+
const val LOG_TAG = "RCTMGLAndroidTextureMapViewManager"
|
|
26
|
+
const val REACT_CLASS = "RCTMGLAndroidTextureMapView"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -36,8 +36,8 @@ fun ReadableArray.asArrayString(): Array<String> {
|
|
|
36
36
|
return result
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
open class RCTMGLMapViewManager(context: ReactApplicationContext
|
|
40
|
-
AbstractEventEmitter<RCTMGLMapView
|
|
39
|
+
open class RCTMGLMapViewManager(context: ReactApplicationContext) :
|
|
40
|
+
AbstractEventEmitter<RCTMGLMapView>(context) {
|
|
41
41
|
private val mViews: MutableMap<Int, RCTMGLMapView>
|
|
42
42
|
override fun getName(): String {
|
|
43
43
|
return REACT_CLASS
|
|
@@ -76,7 +76,8 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
override fun createViewInstance(themedReactContext: ThemedReactContext): RCTMGLMapView {
|
|
79
|
-
|
|
79
|
+
val context = activity ?: themedReactContext
|
|
80
|
+
return RCTMGLMapView(context, this /*, null*/)
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
override fun onDropViewInstance(mapView: RCTMGLMapView) {
|
|
@@ -5,7 +5,7 @@ import com.facebook.react.uimanager.ThemedReactContext
|
|
|
5
5
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
6
6
|
import javax.annotation.Nonnull
|
|
7
7
|
|
|
8
|
-
class RCTMGLRasterSourceManager(reactApplicationContext: ReactApplicationContext
|
|
8
|
+
class RCTMGLRasterSourceManager(reactApplicationContext: ReactApplicationContext) :
|
|
9
9
|
RCTMGLTileSourceManager<RCTMGLRasterSource?>(reactApplicationContext) {
|
|
10
10
|
@Nonnull
|
|
11
11
|
override fun getName(): String {
|
|
@@ -8,7 +8,7 @@ import com.facebook.react.uimanager.annotations.ReactProp
|
|
|
8
8
|
import com.mapbox.rctmgl.components.AbstractEventEmitter
|
|
9
9
|
|
|
10
10
|
abstract class RCTMGLTileSourceManager<T : RCTMGLTileSource<*>?> internal constructor(
|
|
11
|
-
reactApplicationContext: ReactApplicationContext
|
|
11
|
+
reactApplicationContext: ReactApplicationContext
|
|
12
12
|
) : AbstractEventEmitter<T>(reactApplicationContext) {
|
|
13
13
|
override fun getChildAt(source: T, childPosition: Int): View {
|
|
14
14
|
return source!!.getChildAt(childPosition)
|
|
@@ -11,7 +11,7 @@ import com.mapbox.rctmgl.utils.ConvertUtils
|
|
|
11
11
|
import com.mapbox.rctmgl.utils.ExpressionParser
|
|
12
12
|
import javax.annotation.Nonnull
|
|
13
13
|
|
|
14
|
-
class RCTMGLVectorSourceManager(reactApplicationContext: ReactApplicationContext
|
|
14
|
+
class RCTMGLVectorSourceManager(reactApplicationContext: ReactApplicationContext) :
|
|
15
15
|
RCTMGLTileSourceManager<RCTMGLVectorSource?>(reactApplicationContext) {
|
|
16
16
|
@Nonnull
|
|
17
17
|
override fun getName(): String {
|
package/package.json
CHANGED
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.java
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
package com.mapbox.rctmgl.components;
|
|
2
|
-
|
|
3
|
-
import android.view.ViewGroup;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
-
import com.facebook.react.common.MapBuilder;
|
|
7
|
-
import com.facebook.react.uimanager.ThemedReactContext;
|
|
8
|
-
import com.facebook.react.uimanager.UIManagerModule;
|
|
9
|
-
import com.facebook.react.uimanager.ViewGroupManager;
|
|
10
|
-
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
11
|
-
|
|
12
|
-
import com.mapbox.rctmgl.events.IEvent;
|
|
13
|
-
import com.mapbox.rctmgl.components.AbstractEvent;
|
|
14
|
-
|
|
15
|
-
import java.util.HashMap;
|
|
16
|
-
import java.util.Map;
|
|
17
|
-
|
|
18
|
-
import javax.annotation.Nullable;
|
|
19
|
-
import javax.annotation.Nonnull;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Created by nickitaliano on 8/23/17.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
abstract public class AbstractEventEmitter<T extends ViewGroup> extends ViewGroupManager<T> {
|
|
26
|
-
private static final double BRIDGE_TIMEOUT_MS = 10;
|
|
27
|
-
private Map<String, Long> mRateLimitedEvents;
|
|
28
|
-
private EventDispatcher mEventDispatcher;
|
|
29
|
-
private ReactApplicationContext mRCTAppContext;
|
|
30
|
-
|
|
31
|
-
public AbstractEventEmitter(ReactApplicationContext reactApplicationContext) {
|
|
32
|
-
mRateLimitedEvents = new HashMap<>();
|
|
33
|
-
mRCTAppContext = reactApplicationContext;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public void handleEvent(IEvent event) {
|
|
37
|
-
String eventCacheKey = getEventCacheKey(event);
|
|
38
|
-
|
|
39
|
-
// fail safe to protect bridge from being spammed
|
|
40
|
-
if (shouldDropEvent(eventCacheKey, event)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
mRateLimitedEvents.put(eventCacheKey, System.currentTimeMillis());
|
|
45
|
-
mEventDispatcher.dispatchEvent(new AbstractEvent(event.getID(), event.getKey(), event.canCoalesce(), event.toJSON()));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Override
|
|
49
|
-
protected void addEventEmitters(ThemedReactContext context, @Nonnull T view) {
|
|
50
|
-
mEventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Nullable
|
|
54
|
-
@Override
|
|
55
|
-
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
|
|
56
|
-
Map<String, String> events = customEvents();
|
|
57
|
-
|
|
58
|
-
if (events == null) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
Map<String, Object> exportedEvents = new HashMap<>();
|
|
63
|
-
|
|
64
|
-
for (Map.Entry<String, String> event : events.entrySet()) {
|
|
65
|
-
exportedEvents.put(event.getKey(), MapBuilder.of("registrationName", event.getValue()));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return exportedEvents;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@Nullable
|
|
72
|
-
public abstract Map<String, String> customEvents();
|
|
73
|
-
|
|
74
|
-
private boolean shouldDropEvent(String cacheKey, IEvent event) {
|
|
75
|
-
Long lastEventTimestamp = mRateLimitedEvents.get(cacheKey);
|
|
76
|
-
return lastEventTimestamp != null && (event.getTimestamp() - lastEventTimestamp) <= BRIDGE_TIMEOUT_MS;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private String getEventCacheKey(IEvent event) {
|
|
80
|
-
return String.format("%s-%s", event.getKey(), event.getType());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
package com.mapbox.rctmgl.components.mapview;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
-
//import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
|
5
|
-
import com.facebook.react.uimanager.ThemedReactContext;
|
|
6
|
-
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Created by hernanmateo on 12/11/18.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
public class RCTMGLAndroidTextureMapViewManager extends RCTMGLMapViewManager {
|
|
13
|
-
public static final String LOG_TAG = "RCTMGLAndroidTextureMapViewManager";
|
|
14
|
-
public static final String REACT_CLASS = "RCTMGLAndroidTextureMapView";
|
|
15
|
-
|
|
16
|
-
public RCTMGLAndroidTextureMapViewManager(ReactApplicationContext context) {
|
|
17
|
-
super(context);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Override
|
|
21
|
-
public String getName() {
|
|
22
|
-
return REACT_CLASS;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Override
|
|
26
|
-
protected RCTMGLAndroidTextureMapView createViewInstance(ThemedReactContext themedReactContext) {
|
|
27
|
-
//MapboxMapOptions options = new MapboxMapOptions();
|
|
28
|
-
//options.textureMode(true);
|
|
29
|
-
return new RCTMGLAndroidTextureMapView(themedReactContext, this/*, options*/);
|
|
30
|
-
}
|
|
31
|
-
}
|