Summary: This is a prototype for view preview within Flipper for iOS (Android next). If enabled, a preview of the selected element is rendered in the attribute inspector. Changelog: Add view preview/snapshot for the Layout plugin on iOS. Reviewed By: antonk52 Differential Revision: D34990372 fbshipit-source-id: 1984514fbf59041ad236008a8db10569c5fc5f94
102 lines
3.5 KiB
Plaintext
102 lines
3.5 KiB
Plaintext
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#if FB_SONARKIT_ENABLED
|
|
|
|
#import "SKButtonDescriptor.h"
|
|
|
|
#import <FlipperKitLayoutHelpers/SKObject.h>
|
|
#import <FlipperKitLayoutHelpers/UIColor+SKSonarValueCoder.h>
|
|
|
|
@implementation SKButtonDescriptor
|
|
|
|
- (NSString*)identifierForNode:(UIButton*)node {
|
|
return [NSString stringWithFormat:@"%p", node];
|
|
}
|
|
|
|
- (NSUInteger)childCountForNode:(UIButton*)node {
|
|
return 0;
|
|
}
|
|
|
|
- (id)childForNode:(UIButton*)node atIndex:(NSUInteger)index {
|
|
return nil;
|
|
}
|
|
|
|
- (NSArray<SKNamed<NSDictionary*>*>*)dataForNode:(UIButton*)node {
|
|
SKNodeDescriptor* viewDescriptor = [self descriptorForClass:[UIView class]];
|
|
auto* viewData = [viewDescriptor dataForNode:node];
|
|
|
|
NSMutableArray* data = [NSMutableArray new];
|
|
[data addObjectsFromArray:viewData];
|
|
[data addObject:[SKNamed
|
|
newWithName:@"UIButton"
|
|
withValue:@{
|
|
@"focused" : @(node.focused),
|
|
@"enabled" : SKMutableObject(@(node.enabled)),
|
|
@"highlighted" : SKMutableObject(@(node.highlighted)),
|
|
@"titleEdgeInsets" : SKObject(node.titleEdgeInsets),
|
|
@"titleLabel" : SKMutableObject(
|
|
node.titleLabel.attributedText.string
|
|
.stringByStandardizingPath),
|
|
@"currentTitleColor" :
|
|
SKMutableObject(node.currentTitleColor),
|
|
}]];
|
|
return data;
|
|
}
|
|
|
|
- (NSDictionary<NSString*, SKNodeUpdateData>*)dataMutationsForNode:
|
|
(UIButton*)node {
|
|
NSDictionary* buttonMutations =
|
|
@{@"UIButton.titleLabel" : ^(NSString* newValue){
|
|
[node setTitle:newValue forState:node.state];
|
|
}
|
|
,
|
|
@"UIButton.currentTitleColor": ^(NSNumber *newValue) {
|
|
[node setTitleColor: [UIColor fromSonarValue: newValue] forState: node.state];
|
|
},
|
|
@"UIButton.highlighted": ^(NSNumber *highlighted) {
|
|
[node setHighlighted: [highlighted boolValue]];
|
|
},
|
|
@"UIButton.enabled": ^(NSNumber *enabled) {
|
|
[node setEnabled: [enabled boolValue]];
|
|
}
|
|
}
|
|
;
|
|
|
|
SKNodeDescriptor* viewDescriptor = [self descriptorForClass:[UIView class]];
|
|
NSDictionary* viewMutations = [viewDescriptor dataMutationsForNode:node];
|
|
|
|
NSMutableDictionary* mutations = [NSMutableDictionary new];
|
|
[mutations addEntriesFromDictionary:buttonMutations];
|
|
[mutations addEntriesFromDictionary:viewMutations];
|
|
|
|
return mutations;
|
|
}
|
|
|
|
- (NSArray<SKNamed<NSString*>*>*)attributesForNode:(UIScrollView*)node {
|
|
SKNodeDescriptor* descriptor = [self descriptorForClass:[UIView class]];
|
|
return [descriptor attributesForNode:node];
|
|
}
|
|
|
|
- (void)setHighlighted:(BOOL)highlighted forNode:(UIButton*)node {
|
|
SKNodeDescriptor* viewDescriptor = [self descriptorForClass:[UIView class]];
|
|
[viewDescriptor setHighlighted:highlighted forNode:node];
|
|
}
|
|
|
|
- (UIImage*)getSnapshot:(BOOL)includeChildren forNode:(UIButton*)node {
|
|
SKNodeDescriptor* descriptor = [self descriptorForClass:[UIView class]];
|
|
return [descriptor getSnapshot:includeChildren forNode:node];
|
|
}
|
|
|
|
- (void)hitTest:(SKTouch*)touch forNode:(UIButton*)node {
|
|
[touch finish];
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|