Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public class RNMBXMapViewFactory {
}

fun get(impl: String): Factory? {
val (impl, options) = impl.split(":",limit=2);
val (impl, options) = impl.split(":",limit=2) + null;
return factories.get(impl);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rnmapbox.rnmbx.utils.extensions

import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.google.gson.JsonArray
Expand Down Expand Up @@ -83,6 +84,19 @@ fun ReadableMap.getAndLogIfNotString(key: String, tag: String = "RNMBXReadableMa
}
}

fun ReadableMap.getAndLogIfNotArray(key: String, tag: String = "RNMBXReadableMap"): ReadableArray? {
return if (hasKey(key)) {
if (getType(key) == ReadableType.Array) {
getArray(key)
} else {
Logger.e("RNMBXReadableMap", "$key is exected to be a Map but was: ${getType(key)}")
null
}
} else {
null
}
}

fun ReadableMap.getAndLogIfNotMap(key: String, tag: String = "RNMBXReadableMap"): ReadableMap? {
return if (hasKey(key)) {
if (getType(key) == ReadableType.Map) {
Expand Down
12 changes: 6 additions & 6 deletions ios/RNMBX/RNMBXLogging.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Foundation
import MapboxMaps

enum RNMBXError: Error, LocalizedError {
public enum RNMBXError: Error, LocalizedError {
case parseError(String)
case failed(String)
case paramError(String)

var errorDescription: String? {
public var errorDescription: String? {
return String(describing: self)
}
}

class Logger {
enum LogLevel : String, Comparable {
static func < (lhs: Logger.LogLevel, rhs: Logger.LogLevel) -> Bool {
public class Logger {
public enum LogLevel : String, Comparable {
public static func < (lhs: Logger.LogLevel, rhs: Logger.LogLevel) -> Bool {
return lhs.intValue < rhs.intValue
}

Expand Down Expand Up @@ -56,7 +56,7 @@ class Logger {
}
}

static func log(level: LogLevel, message: String) {
public static func log(level: LogLevel, message: String) {
sharedInstance.log(level: level, message: message)
}

Expand Down
6 changes: 5 additions & 1 deletion ios/RNMBX/RNMBXMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Turf
import MapKit

public typealias RNMBXMapViewFactoryFunc = (String, UIView) -> MapView?;
public typealias RNMBXMapViewFactoryFunc = (String, UIView) -> (MapView?)

/**
* Experimental MapView factory for advanced usecases
Expand Down Expand Up @@ -191,6 +191,7 @@ open class RNMBXMapView: UIView {

_mapView.gestures.delegate = self
setupEvents()
afterMapViewAdded()
}

func createAndAddMapViewImpl(_ impl: String, _ view: RNMBXMapView) -> MapView? {
Expand Down Expand Up @@ -841,6 +842,9 @@ open class RNMBXMapView: UIView {
}
}
}

// MARK: - hooks for subclasses
open func afterMapViewAdded() {}
}

// MARK: - event handlers
Expand Down
2 changes: 2 additions & 0 deletions ios/RNMBX/RNMBXMapViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ @interface RCT_EXTERN_REMAP_MODULE(RNMBXMapView, RNMBXMapViewManager, RCTViewMan
RCT_REMAP_VIEW_PROPERTY(onLongPress, reactOnLongPress, RCTBubblingEventBlock)
RCT_REMAP_VIEW_PROPERTY(onMapChange, reactOnMapChange, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(mapViewImpl, NSString)

@end
4 changes: 2 additions & 2 deletions ios/RNMBX/RNMBXMapViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension QueriedSourceFeature {
#endif

@objc(RNMBXMapViewManager)
public class RNMBXMapViewManager: RCTViewManager {
open class RNMBXMapViewManager: RCTViewManager {
@objc
override public static func requiresMainQueueSetup() -> Bool {
return true
Expand All @@ -17,7 +17,7 @@ public class RNMBXMapViewManager: RCTViewManager {
return UIScreen.main.bounds
}

override public func view() -> UIView! {
override open func view() -> UIView! {
let result = RNMBXMapView(frame: self.defaultFrame(), eventDispatcher: self.bridge.eventDispatcher())
return result
}
Expand Down
15 changes: 10 additions & 5 deletions ios/RNMBX/RNMBXModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import MapboxMobileEvents
let DEFAULT_SOURCE_ID = "composite";

@objc(RNMBXModule)
public
class RNMBXModule : NSObject {
#if RNMBX_11
static var accessToken : String? {

public static var accessToken : String? {
didSet {
#if RNMBX_11
if let token = accessToken {
MapboxOptions.accessToken = token
}
#else
if let token = accessToken {
ResourceOptionsManager.default.resourceOptions.accessToken = token
}
#endif
}
}
#else
static var accessToken : String?
#endif


@objc
func constantsToExport() -> [AnyHashable: Any]! {
Expand Down
19 changes: 14 additions & 5 deletions src/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ type Props = ViewProps & {
* @private Experimental support for custom MapView instances
*/
mapViewImpl?: string;

/**
* @private Experimental support for custom MapView instances
*/
_nativeImpl?: NativeMapViewActual;
};

type CallbablePropKeys =
Expand Down Expand Up @@ -1155,11 +1160,15 @@ class MapView extends NativeBridgeComponent(

let mapView = null;
if (this.state.isReady) {
mapView = (
<RNMBXMapView {...props} {...callbacks}>
{this.props.children}
</RNMBXMapView>
);
if (props._nativeImpl) {
mapView = <props._nativeImpl {...props} {...callbacks} />;
} else {
mapView = (
<RNMBXMapView {...props} {...callbacks}>
{this.props.children}
</RNMBXMapView>
);
}
}

return (
Expand Down