Skip to content

Commit

Permalink
Fix error in clusterMaxZoomLevel on new arch (#3541)
Browse files Browse the repository at this point in the history
* Fix error in clusterMaxZoomLevel on new arch

* Use macro to convert props in RNMBXShapeSourceComponentView

* Format
  • Loading branch information
janicduplessis authored Jun 29, 2024
1 parent 55216db commit dbe96aa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 55 deletions.
8 changes: 7 additions & 1 deletion ios/RNMBX/RNMBXFabricPropConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
*
* 1. Requirest the following prelude
* 1. Requires the following prelude
* const auto &oldViewProps = static_cast<const RNMBXNativeUserLocationProps &>(*oldProps);
* const auto &newViewProps = static_cast<const RNMBXNativeUserLocationProps &>(*props);
*
Expand All @@ -12,6 +12,7 @@
NSNumber* RNMBXPropConvert_Optional_BOOL_NSNumber(const folly::dynamic &dyn, NSString* propertyName);
BOOL RNMBXPropConvert_Optional_BOOL(const folly::dynamic &dyn, NSString* propertyName);
NSString* RNMBXPropConvert_Optional_NSString(const folly::dynamic &dyn, NSString* propertyName);
NSNumber* RNMBXPropConvert_Optional_NSNumber(const folly::dynamic &dyn, NSString* propertyName);
id RNMBXPropConvert_Optional_ExpressionDouble(const folly::dynamic &dyn, NSString* propertyName);
BOOL RNMBXPropConvert_BOOL(const folly::dynamic &dyn, NSString* propertyName);
NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn, NSString* propertyName);
Expand All @@ -33,6 +34,11 @@ NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn,
_view.name = RNMBXPropConvert_Optional_NSString(newViewProps.name, @#name); \
}

#define RNMBX_OPTIONAL_PROP_NSNumber(name) \
if ((!oldProps.get() || oldViewProps.name != newViewProps.name) && !newViewProps.name.isNull()) { \
_view.name = RNMBXPropConvert_Optional_NSNumber(newViewProps.name, @#name); \
}

#define RNMBX_OPTIONAL_PROP_ExpressionDouble(name) \
if ((!oldProps.get() || oldViewProps.name != newViewProps.name) && !newViewProps.name.isNull()) { \
_view.name = RNMBXPropConvert_Optional_ExpressionDouble(newViewProps.name, @#name); \
Expand Down
22 changes: 21 additions & 1 deletion ios/RNMBX/RNMBXFabricPropConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ BOOL RNMBXPropConvert_Optional_BOOL(const folly::dynamic &dyn, NSString* propert
}

NSString* RNMBXPropConvert_Optional_NSString(const folly::dynamic &dyn, NSString* propertyName) {
switch (dyn.type()) {
switch (dyn.type()) {
case folly::dynamic::STRING:
return [NSString stringWithCString:dyn.getString().c_str() encoding:NSUTF8StringEncoding];
case folly::dynamic::NULLT:
Expand All @@ -71,6 +71,26 @@ BOOL RNMBXPropConvert_Optional_BOOL(const folly::dynamic &dyn, NSString* propert
}
}

NSNumber* RNMBXPropConvert_Optional_NSNumber(const folly::dynamic &dyn, NSString* propertyName) {
switch (dyn.type()) {
case folly::dynamic::INT64:
return @(dyn.getInt());
case folly::dynamic::DOUBLE:
return @(dyn.getDouble());
case folly::dynamic::NULLT:
return nil;
default:
std::stringstream ss;
ss << dyn;
[RNMBXLogger error:[NSString stringWithFormat:@"Property %@ expected to be a number or nil but was: %s",
propertyName,
ss.str().c_str()
]];
return nil;
}
}



id RNMBXPropConvert_ID(const folly::dynamic &dyn)
{
Expand Down
71 changes: 18 additions & 53 deletions ios/RNMBX/RNMBXShapeSourceComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#import "RNMBXShapeSourceComponentView.h"
#import "RNMBXFabricHelpers.h"
#import "RNMBXFabricPropConvert.h"

#import <React/RCTConversions.h>
#import <React/RCTFabricComponentsPlugins.h>
Expand Down Expand Up @@ -85,59 +86,23 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
{
const auto &newProps = static_cast<const RNMBXShapeSourceProps &>(*props);
id idx = RNMBXConvertFollyDynamicToId(newProps.id);
if (idx != nil) {
_view.id = idx;
}
id existing = RNMBXConvertFollyDynamicToId(newProps.existing);
if (existing != nil) {
_view.existing = existing;
}
id shape = RNMBXConvertFollyDynamicToId(newProps.shape);
if (shape != nil) {
_view.shape = shape;
}
id cluster = RNMBXConvertFollyDynamicToId(newProps.cluster);
if (cluster != nil) {
_view.cluster = cluster;
}
id clusterRadius = RNMBXConvertFollyDynamicToId(newProps.clusterRadius);
if (clusterRadius != nil) {
_view.clusterRadius = clusterRadius;
}
id clusterMaxZoomLevel = RNMBXConvertFollyDynamicToId(newProps.clusterMaxZoomLevel);
if (clusterMaxZoomLevel != nil) {
_view.clusterMaxZoomLevel = clusterMaxZoomLevel;
}
id clusterProperties = RNMBXConvertFollyDynamicToId(newProps.clusterProperties);
if (clusterProperties != nil) {
_view.clusterProperties = clusterProperties;
}
id maxZoomLevel = RNMBXConvertFollyDynamicToId(newProps.maxZoomLevel);
if (maxZoomLevel != nil) {
_view.maxZoomLevel = maxZoomLevel;
}
id buffer = RNMBXConvertFollyDynamicToId(newProps.buffer);
if (buffer != nil) {
_view.buffer = buffer;
}
id tolerance = RNMBXConvertFollyDynamicToId(newProps.tolerance);
if (tolerance != nil) {
_view.tolerance = tolerance;
}
id lineMetrics = RNMBXConvertFollyDynamicToId(newProps.lineMetrics);
if (lineMetrics != nil) {
_view.lineMetrics = lineMetrics;
}
id hasPressListener = RNMBXConvertFollyDynamicToId(newProps.hasPressListener);
if (hasPressListener != nil) {
_view.hasPressListener = hasPressListener;
}
id hitbox = RNMBXConvertFollyDynamicToId(newProps.hitbox);
if (hitbox != nil) {
_view.hitbox = hitbox;
}
const auto &oldViewProps = static_cast<const RNMBXShapeSourceProps &>(*_props);
const auto &newViewProps = static_cast<const RNMBXShapeSourceProps &>(*props);

RNMBX_OPTIONAL_PROP_NSString(id)
RNMBX_OPTIONAL_PROP_BOOL(existing)
RNMBX_OPTIONAL_PROP_NSString(shape)
RNMBX_OPTIONAL_PROP_NSNumber(cluster)
RNMBX_OPTIONAL_PROP_NSNumber(clusterRadius)
RNMBX_OPTIONAL_PROP_NSNumber(clusterMaxZoomLevel)
RNMBX_OPTIONAL_PROP_NSDictionary(clusterProperties)
RNMBX_OPTIONAL_PROP_NSNumber(maxZoomLevel)
RNMBX_OPTIONAL_PROP_NSNumber(buffer)
RNMBX_OPTIONAL_PROP_NSNumber(tolerance)
RNMBX_OPTIONAL_PROP_NSNumber(lineMetrics)
RNMBX_OPTIONAL_PROP_BOOL(hasPressListener)
RNMBX_OPTIONAL_PROP_NSDictionary(hitbox)

[super updateProps:props oldProps:oldProps];
}

Expand Down

0 comments on commit dbe96aa

Please sign in to comment.