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

feat: allow merging StyleImport configs #3619

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.rnmapbox.rnmbx.v11compat.style.*

class RNMBXStyleImport(context: Context) : AbstractMapFeature(context) {
var id: String? = null;
var merge: Boolean = false;

var config: HashMap<String, Value> = hashMapOf()
set(value: HashMap<String, Value>) {
Expand All @@ -27,11 +28,16 @@ class RNMBXStyleImport(context: Context) : AbstractMapFeature(context) {
id?.let { id ->
val config = this.config
if (config.isNotEmpty()) {
mapView.mapView.getMapboxMap().getStyle()
?.setStyleImportConfigProperties(id, config)
val mapStyle = mapView.mapView.getMapboxMap().getStyle()
if (merge) {
config.forEach { (key, value) ->
mapStyle?.setStyleImportConfigProperty(id, key, value)
}
} else {
mapStyle?.setStyleImportConfigProperties(id, config)
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ class RNMBXStyleImportManager(context: ReactApplicationContext) :
view.config = value.asMap().toValueHashMap()
}
}

@ReactProp(name = "merge")
override fun setMerge(view: RNMBXStyleImport, value: Boolean) {
view.merge = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "config":
mViewManager.setConfig(view, new DynamicFromObject(value));
break;
case "merge":
mViewManager.setMerge(view, value == null ? false : (boolean) value);
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface RNMBXStyleImportManagerInterface<T extends View> {
void setId(T view, @Nullable String value);
void setExisting(T view, boolean value);
void setConfig(T view, Dynamic value);
void setMerge(T view, boolean value);
}
10 changes: 10 additions & 0 deletions docs/StyleImport.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ See https://github.com/mapbox/mapbox-maps-ios/blob/main/Sources/MapboxMaps/Docum



### merge

```tsx
boolean
```
_required_
whether to merge the style import with the existing style import config or replace it entirely. Defaults to `false`






Expand Down
15 changes: 13 additions & 2 deletions ios/RNMBX/RNMBXStyleImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ open class RNMBXStyleImport : UIView, RNMBXMapComponent {
}
}
}

@objc
var merge: Bool = false;

public func waitForStyleLoad() -> Bool {
true
Expand All @@ -37,8 +40,16 @@ open class RNMBXStyleImport : UIView, RNMBXMapComponent {
func apply(mapView: MapView) {
if let config = config, let id = id {
#if RNMBX_11
logged("RNMBXStyleImport.setStyleImportConfigProperties id=\(id)") {
try mapView.mapboxMap.setStyleImportConfigProperties(for: id, configs: config)
if merge {
for (key, value) in config {
logged("RNMBXStyleImport.setStyleImportConfigProperty for id=\(id), config=\(key), value=\(value)") {
try mapView.mapboxMap.setStyleImportConfigProperty(for: id, config: key, value: value)
}
}
} else {
logged("RNMBXStyleImport.setStyleImportConfigProperties id=\(id)") {
try mapView.mapboxMap.setStyleImportConfigProperties(for: id, configs: config)
}
}
#else
Logger.error("RNMBXStyleImport.setStyleImportConfigProperties is only implemented on v11")
Expand Down
1 change: 1 addition & 0 deletions ios/RNMBX/RNMBXStyleImportManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ @interface RCT_EXTERN_REMAP_MODULE(RNMBXStyleImport, RNMBXStyleImportManager, RC
RCT_EXPORT_VIEW_PROPERTY(id, NSString)
RCT_EXPORT_VIEW_PROPERTY(existing, BOOL)
RCT_EXPORT_VIEW_PROPERTY(config, NSDictionary)
RCT_EXPORT_VIEW_PROPERTY(merge, BOOL)

@end
6 changes: 6 additions & 0 deletions src/components/StyleImport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type Props = {
config: {
[key: string]: string;
};

/**
* Determines whether the style import config should merge with the existing style import config.
* @default false
*/
merge?: boolean;
};

/**
Expand Down
Loading