diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.h b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.h index ef880b9e55a..9f1315b673d 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.h +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.h @@ -26,7 +26,15 @@ FOUNDATION_EXPORT NSString* const UIDEBUGGER_METADATA_TYPE_DOCUMENTATION; - (UIDMetadataId)registerMetadataWithType:(NSString*)type name:(NSString*)name isMutable:(bool)isMutable - definedBy:(UIDMetadataId)definedById; + definedBy:(UIDMetadataId)parent; + +- (UIDMetadataId)registerMetadataWithType:(NSString*)type + name:(NSString*)name + isMutable:(bool)isMutable + definedBy:(UIDMetadataId)parent + customAttributes: + (nullable NSDictionary*) + customAttributes; - (NSDictionary*)extractPendingMetadata; diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.m index 519cb87e005..0b48f7c1fbf 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIDMetadataRegister.m @@ -65,12 +65,34 @@ - (UIDMetadataId)registerMetadataWithType:(NSString*)type name:(NSString*)name isMutable:(bool)isMutable definedBy:(UIDMetadataId)parent { + return [self registerMetadataWithType:type + name:name + isMutable:isMutable + definedBy:parent + customAttributes:nil]; +} + +- (UIDMetadataId)registerMetadataWithType:(NSString*)type + name:(NSString*)name + isMutable:(bool)isMutable + definedBy:(UIDMetadataId)parent + customAttributes: + (nullable NSDictionary*) + customAttributes { + if (!parent) { + parent = _rootId; + } + UIDMetadataId identifier = @(++_generator); - UIDMetadata* metadata = [[UIDMetadata alloc] initWithIdentifier:identifier - type:type - name:name - isMutable:isMutable - parent:parent]; + UIDMetadata* metadata = + [[UIDMetadata alloc] initWithIdentifier:identifier + type:type + name:name + isMutable:isMutable + parent:parent + possibleValues:nil + tags:nil + customAttributes:customAttributes]; [_lock lock]; if (![_register objectForKey:parent]) { diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.h b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.h index e1c46b220f2..697df7abf99 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.h +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.h @@ -23,32 +23,33 @@ typedef NSNumber* UIDMetadataId; */ @interface UIDMetadata : NSObject +#pragma mark - Included in the wire protocol + @property(nonatomic, readonly) UIDMetadataId identifier; @property(nonatomic, strong, readonly) NSString* type; -@property(nonatomic, readonly) UIDMetadataId parent; @property(nonatomic, strong, readonly) NSString* name; @property(nonatomic, readonly) bool isMutable; -@property(nonatomic, strong, readonly) +@property(nonatomic, readonly, nullable) + NSDictionary* customAttributes; + +#pragma mark - Not included in the wire protocol + +@property(nonatomic, readonly) UIDMetadataId parent; +@property(nonatomic, strong, readonly, nullable) NSSet* possibleValues; -@property(nonatomic, strong, readonly) NSSet* tags; - -- (instancetype)initWithIdentifier:(UIDMetadataId)identifier - type:(NSString*)type - name:(NSString*)name; - -- (instancetype)initWithIdentifier:(UIDMetadataId)identifier - type:(NSString*)type - name:(NSString*)name - isMutable:(bool)isMutable - parent:(UIDMetadataId)parent; - -- (instancetype)initWithIdentifier:(UIDMetadataId)identifier - type:(NSString*)type - name:(NSString*)name - isMutable:(bool)isMutable - parent:(UIDMetadataId)parent - possibleValues:(NSSet*)possibleValues - tags:(NSSet*)tags; +@property(nonatomic, strong, readonly, nullable) NSSet* tags; + +#pragma mark - + +- (instancetype) + initWithIdentifier:(UIDMetadataId)identifier + type:(NSString*)type + name:(NSString*)name + isMutable:(bool)isMutable + parent:(UIDMetadataId)parent + possibleValues:(nullable NSSet*)possibleValues + tags:(nullable NSSet*)tags + customAttributes:(nullable NSDictionary*)customAttributes; @end NS_ASSUME_NONNULL_END diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.m index 81bc2afdb72..ed21cc85f91 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Model/UIDMetadata.m @@ -12,48 +12,25 @@ @implementation UIDMetadata -- (instancetype)initWithIdentifier:(UIDMetadataId)identifier - type:(NSString*)type - name:(NSString*)name { - return [self initWithIdentifier:identifier - type:type - name:name - isMutable:false - parent:@0 - possibleValues:[NSSet set] - tags:[NSSet set]]; -} - -- (instancetype)initWithIdentifier:(UIDMetadataId)identifier - type:(NSString*)type - name:(NSString*)name - isMutable:(bool)isMutable - parent:(UIDMetadataId)parent { - return [self initWithIdentifier:identifier - type:type - name:name - isMutable:isMutable - parent:parent - possibleValues:[NSSet set] - tags:[NSSet set]]; -} - - (instancetype)initWithIdentifier:(UIDMetadataId)identifier type:(NSString*)type name:(NSString*)name isMutable:(bool)isMutable parent:(UIDMetadataId)parent possibleValues:(NSSet*)possibleValues - tags:(NSSet*)tags { + tags:(NSSet*)tags + customAttributes: + (nullable NSDictionary*)customAttributes { self = [super init]; if (self) { _identifier = identifier; _type = type; _name = name; _isMutable = isMutable; - _parent = parent; - _possibleValues = possibleValues; - _tags = tags; + _parent = parent ?: @0; + _possibleValues = possibleValues ?: [NSSet set]; + _tags = tags ?: [NSSet set]; + _customAttributes = customAttributes; } return self; } diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Serializers/UIDMetadata+Foundation.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Serializers/UIDMetadata+Foundation.m index a47cd1fedfe..67527b00122 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Serializers/UIDMetadata+Foundation.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Serializers/UIDMetadata+Foundation.m @@ -7,6 +7,7 @@ #if FB_SONARKIT_ENABLED +#import "NSDictionary+Foundation.h" #import "NSSet+Foundation.h" #import "UIDMetadata+Foundation.h" @@ -14,12 +15,20 @@ @implementation UIDMetadata (Foundation) - (id)toFoundation { - return @{ + NSMutableDictionary* result = [NSMutableDictionary dictionary]; + + [result addEntriesFromDictionary:@{ @"id" : self.identifier, @"type" : self.type, @"name" : self.name, @"mutable" : [NSNumber numberWithBool:self.isMutable], - }; + }]; + + if (self.customAttributes != nil) { + result[@"customAttributes"] = [self.customAttributes toFoundation]; + } + + return [result copy]; } @end