Add metadata.customAttributes field

Summary:
`customAttributes` will be used by the UI Debugger to pass styleID for Bloks model attributes.
(replicating corresponding [Android implementation](https://www.internalfb.com/code/fbsource/[33c33fa7f582]/xplat/sonar/android/src/facebook/java/com/facebook/flipper/uidebugger/bloks/descriptors/BloksDebugComponentDescriptor.kt?lines=138-139%2C170-171))

Reviewed By: antonk52

Differential Revision: D47494013

fbshipit-source-id: 257387d4af94235b23d636047326532d7071e8dd
This commit is contained in:
Ivan Misuno
2023-07-21 14:32:22 -07:00
committed by Facebook GitHub Bot
parent b22ac16c3c
commit 1753581028
5 changed files with 74 additions and 57 deletions

View File

@@ -26,7 +26,15 @@ FOUNDATION_EXPORT NSString* const UIDEBUGGER_METADATA_TYPE_DOCUMENTATION;
- (UIDMetadataId)registerMetadataWithType:(NSString*)type - (UIDMetadataId)registerMetadataWithType:(NSString*)type
name:(NSString*)name name:(NSString*)name
isMutable:(bool)isMutable 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<NSString*, id>*)
customAttributes;
- (NSDictionary<UIDMetadataId, UIDMetadata*>*)extractPendingMetadata; - (NSDictionary<UIDMetadataId, UIDMetadata*>*)extractPendingMetadata;

View File

@@ -65,12 +65,34 @@ typedef NSMutableDictionary<NSString*, UIDMetadata*>* UIDNamedMetadata;
name:(NSString*)name name:(NSString*)name
isMutable:(bool)isMutable isMutable:(bool)isMutable
definedBy:(UIDMetadataId)parent { 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<NSString*, id>*)
customAttributes {
if (!parent) {
parent = _rootId;
}
UIDMetadataId identifier = @(++_generator); UIDMetadataId identifier = @(++_generator);
UIDMetadata* metadata = [[UIDMetadata alloc] initWithIdentifier:identifier UIDMetadata* metadata =
type:type [[UIDMetadata alloc] initWithIdentifier:identifier
name:name type:type
isMutable:isMutable name:name
parent:parent]; isMutable:isMutable
parent:parent
possibleValues:nil
tags:nil
customAttributes:customAttributes];
[_lock lock]; [_lock lock];
if (![_register objectForKey:parent]) { if (![_register objectForKey:parent]) {

View File

@@ -23,32 +23,33 @@ typedef NSNumber* UIDMetadataId;
*/ */
@interface UIDMetadata : NSObject @interface UIDMetadata : NSObject
#pragma mark - Included in the wire protocol
@property(nonatomic, readonly) UIDMetadataId identifier; @property(nonatomic, readonly) UIDMetadataId identifier;
@property(nonatomic, strong, readonly) NSString* type; @property(nonatomic, strong, readonly) NSString* type;
@property(nonatomic, readonly) UIDMetadataId parent;
@property(nonatomic, strong, readonly) NSString* name; @property(nonatomic, strong, readonly) NSString* name;
@property(nonatomic, readonly) bool isMutable; @property(nonatomic, readonly) bool isMutable;
@property(nonatomic, strong, readonly) @property(nonatomic, readonly, nullable)
NSDictionary<NSString*, id>* customAttributes;
#pragma mark - Not included in the wire protocol
@property(nonatomic, readonly) UIDMetadataId parent;
@property(nonatomic, strong, readonly, nullable)
NSSet<UIDInspectableValue*>* possibleValues; NSSet<UIDInspectableValue*>* possibleValues;
@property(nonatomic, strong, readonly) NSSet<NSString*>* tags; @property(nonatomic, strong, readonly, nullable) NSSet<NSString*>* tags;
- (instancetype)initWithIdentifier:(UIDMetadataId)identifier #pragma mark -
type:(NSString*)type
name:(NSString*)name;
- (instancetype)initWithIdentifier:(UIDMetadataId)identifier - (instancetype)
type:(NSString*)type initWithIdentifier:(UIDMetadataId)identifier
name:(NSString*)name type:(NSString*)type
isMutable:(bool)isMutable name:(NSString*)name
parent:(UIDMetadataId)parent; isMutable:(bool)isMutable
parent:(UIDMetadataId)parent
- (instancetype)initWithIdentifier:(UIDMetadataId)identifier possibleValues:(nullable NSSet<UIDInspectableValue*>*)possibleValues
type:(NSString*)type tags:(nullable NSSet<NSString*>*)tags
name:(NSString*)name customAttributes:(nullable NSDictionary<NSString*, id>*)customAttributes;
isMutable:(bool)isMutable
parent:(UIDMetadataId)parent
possibleValues:(NSSet<UIDInspectableValue*>*)possibleValues
tags:(NSSet<NSString*>*)tags;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -12,48 +12,25 @@
@implementation UIDMetadata @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 - (instancetype)initWithIdentifier:(UIDMetadataId)identifier
type:(NSString*)type type:(NSString*)type
name:(NSString*)name name:(NSString*)name
isMutable:(bool)isMutable isMutable:(bool)isMutable
parent:(UIDMetadataId)parent parent:(UIDMetadataId)parent
possibleValues:(NSSet<UIDInspectableValue*>*)possibleValues possibleValues:(NSSet<UIDInspectableValue*>*)possibleValues
tags:(NSSet<NSString*>*)tags { tags:(NSSet<NSString*>*)tags
customAttributes:
(nullable NSDictionary<NSString*, id>*)customAttributes {
self = [super init]; self = [super init];
if (self) { if (self) {
_identifier = identifier; _identifier = identifier;
_type = type; _type = type;
_name = name; _name = name;
_isMutable = isMutable; _isMutable = isMutable;
_parent = parent; _parent = parent ?: @0;
_possibleValues = possibleValues; _possibleValues = possibleValues ?: [NSSet set];
_tags = tags; _tags = tags ?: [NSSet set];
_customAttributes = customAttributes;
} }
return self; return self;
} }

View File

@@ -7,6 +7,7 @@
#if FB_SONARKIT_ENABLED #if FB_SONARKIT_ENABLED
#import "NSDictionary+Foundation.h"
#import "NSSet+Foundation.h" #import "NSSet+Foundation.h"
#import "UIDMetadata+Foundation.h" #import "UIDMetadata+Foundation.h"
@@ -14,12 +15,20 @@ FB_LINKABLE(UIDMetadata_Foundation)
@implementation UIDMetadata (Foundation) @implementation UIDMetadata (Foundation)
- (id)toFoundation { - (id)toFoundation {
return @{ NSMutableDictionary* result = [NSMutableDictionary dictionary];
[result addEntriesFromDictionary:@{
@"id" : self.identifier, @"id" : self.identifier,
@"type" : self.type, @"type" : self.type,
@"name" : self.name, @"name" : self.name,
@"mutable" : [NSNumber numberWithBool:self.isMutable], @"mutable" : [NSNumber numberWithBool:self.isMutable],
}; }];
if (self.customAttributes != nil) {
result[@"customAttributes"] = [self.customAttributes toFoundation];
}
return [result copy];
} }
@end @end