diff --git a/ios/RNMBX/RNMBXFabricPropConvert.h b/ios/RNMBX/RNMBXFabricPropConvert.h index 84c9fb40e..f5d70323a 100644 --- a/ios/RNMBX/RNMBXFabricPropConvert.h +++ b/ios/RNMBX/RNMBXFabricPropConvert.h @@ -2,7 +2,7 @@ /** * - * 1. Requirest the following prelude + * 1. Requires the following prelude * const auto &oldViewProps = static_cast(*oldProps); * const auto &newViewProps = static_cast(*props); * @@ -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); @@ -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); \ diff --git a/ios/RNMBX/RNMBXFabricPropConvert.mm b/ios/RNMBX/RNMBXFabricPropConvert.mm index e5a67e99a..84eb8bd1f 100644 --- a/ios/RNMBX/RNMBXFabricPropConvert.mm +++ b/ios/RNMBX/RNMBXFabricPropConvert.mm @@ -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: @@ -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) { diff --git a/ios/RNMBX/RNMBXShapeSourceComponentView.mm b/ios/RNMBX/RNMBXShapeSourceComponentView.mm index 84cef466a..907fd1808 100644 --- a/ios/RNMBX/RNMBXShapeSourceComponentView.mm +++ b/ios/RNMBX/RNMBXShapeSourceComponentView.mm @@ -2,6 +2,7 @@ #import "RNMBXShapeSourceComponentView.h" #import "RNMBXFabricHelpers.h" +#import "RNMBXFabricPropConvert.h" #import #import @@ -85,59 +86,23 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps { - const auto &newProps = static_cast(*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(*_props); + const auto &newViewProps = static_cast(*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]; }