Run CLANGFORMAT on plugins
Summary: This diff runs CLANGFORMAT lint on plugins. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT. Ran `arc lint -a --paths-cmd "find ./iOS/Plugins -type f" --verbose` Reviewed By: passy Differential Revision: D19942173 fbshipit-source-id: 8b975b0a344df073b02d69cd1f9ee5629af2799d
This commit is contained in:
committed by
Facebook Github Bot
parent
a19a430eee
commit
e8b20d5b15
@@ -14,17 +14,27 @@
|
||||
|
||||
#import "CKComponent+Sonar.h"
|
||||
|
||||
static NSDictionary<NSString *, NSObject *> *CKCenterLayoutComponentCenteringOptionsParser(CKCenterLayoutComponentCenteringOptions centeringOptions) {
|
||||
NSMutableDictionary<NSString *, NSObject *> *centeringDict = [NSMutableDictionary new];
|
||||
centeringDict[@"centeringX"] = SKMutableObject(@((BOOL)(centeringOptions & CKCenterLayoutComponentCenteringX)));
|
||||
centeringDict[@"centeringY"] = SKMutableObject(@((BOOL)(centeringOptions & CKCenterLayoutComponentCenteringY)));
|
||||
static NSDictionary<NSString*, NSObject*>*
|
||||
CKCenterLayoutComponentCenteringOptionsParser(
|
||||
CKCenterLayoutComponentCenteringOptions centeringOptions) {
|
||||
NSMutableDictionary<NSString*, NSObject*>* centeringDict =
|
||||
[NSMutableDictionary new];
|
||||
centeringDict[@"centeringX"] = SKMutableObject(
|
||||
@((BOOL)(centeringOptions & CKCenterLayoutComponentCenteringX)));
|
||||
centeringDict[@"centeringY"] = SKMutableObject(
|
||||
@((BOOL)(centeringOptions & CKCenterLayoutComponentCenteringY)));
|
||||
return centeringDict;
|
||||
}
|
||||
|
||||
static NSDictionary<NSString *, NSObject *> *CKCenterLayoutComponentSizingOptionsParser(CKCenterLayoutComponentSizingOptions sizingOptions) {
|
||||
NSMutableDictionary<NSString *, NSObject *> *centeringDict = [NSMutableDictionary new];
|
||||
centeringDict[@"sizingMinimumX"] = SKMutableObject(@((BOOL)(sizingOptions & CKCenterLayoutComponentSizingOptionMinimumX)));
|
||||
centeringDict[@"sizingMinimumY"] = SKMutableObject(@((BOOL)(sizingOptions & CKCenterLayoutComponentSizingOptionMinimumY)));
|
||||
static NSDictionary<NSString*, NSObject*>*
|
||||
CKCenterLayoutComponentSizingOptionsParser(
|
||||
CKCenterLayoutComponentSizingOptions sizingOptions) {
|
||||
NSMutableDictionary<NSString*, NSObject*>* centeringDict =
|
||||
[NSMutableDictionary new];
|
||||
centeringDict[@"sizingMinimumX"] = SKMutableObject(
|
||||
@((BOOL)(sizingOptions & CKCenterLayoutComponentSizingOptionMinimumX)));
|
||||
centeringDict[@"sizingMinimumY"] = SKMutableObject(
|
||||
@((BOOL)(sizingOptions & CKCenterLayoutComponentSizingOptionMinimumY)));
|
||||
return centeringDict;
|
||||
}
|
||||
|
||||
@@ -40,12 +50,20 @@ struct CKCenterLayoutComponentOptionsStruct {
|
||||
FB_LINKABLE(CKCenterLayoutComponent_Sonar)
|
||||
@implementation CKCenterLayoutComponent (Sonar)
|
||||
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_additionalDataOverride
|
||||
{
|
||||
return @[[SKNamed newWithName:@"CKCenterLayoutComponent" withValue:@{
|
||||
@"centeringOptions": SKMutableObject(CKCenterLayoutComponentCenteringOptionsParser((CKCenterLayoutComponentCenteringOptions)[[self valueForKey:@"_centeringOptions"] longValue])),
|
||||
@"sizingOptions": SKMutableObject(CKCenterLayoutComponentSizingOptionsParser((CKCenterLayoutComponentSizingOptions)[[self valueForKey:@"_sizingOptions"] longValue]))
|
||||
}]];
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)
|
||||
sonar_additionalDataOverride {
|
||||
return @[ [SKNamed
|
||||
newWithName:@"CKCenterLayoutComponent"
|
||||
withValue:@{
|
||||
@"centeringOptions" :
|
||||
SKMutableObject(CKCenterLayoutComponentCenteringOptionsParser(
|
||||
(CKCenterLayoutComponentCenteringOptions)[
|
||||
[self valueForKey:@"_centeringOptions"] longValue])),
|
||||
@"sizingOptions" :
|
||||
SKMutableObject(CKCenterLayoutComponentSizingOptionsParser(
|
||||
(CKCenterLayoutComponentSizingOptions)[
|
||||
[self valueForKey:@"_sizingOptions"] longValue]))
|
||||
}] ];
|
||||
}
|
||||
|
||||
- (void)setMutableData:(id)data {
|
||||
@@ -55,15 +73,19 @@ FB_LINKABLE(CKCenterLayoutComponent_Sonar)
|
||||
[self setValue:@(value.sizingOptions) forKey:@"_sizingOptions"];
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeDataChanged> *)sonar_getDataMutationsChanged {
|
||||
- (NSDictionary<NSString*, SKNodeDataChanged>*)sonar_getDataMutationsChanged {
|
||||
__block CKCenterLayoutComponentOptionsStruct options;
|
||||
options.centeringOptions = (CKCenterLayoutComponentCenteringOptions)[[self valueForKey:@"_centeringOptions"] longValue];
|
||||
options.sizingOptions = (CKCenterLayoutComponentSizingOptions)[[self valueForKey:@"_sizingOptions"] longValue];
|
||||
options.centeringOptions = (CKCenterLayoutComponentCenteringOptions)[
|
||||
[self valueForKey:@"_centeringOptions"] longValue];
|
||||
options.sizingOptions = (CKCenterLayoutComponentSizingOptions)[
|
||||
[self valueForKey:@"_sizingOptions"] longValue];
|
||||
return @{
|
||||
@"CKCenterLayoutComponent.centeringOptions.centeringX": ^(NSNumber *value) {
|
||||
options.centeringOptions ^= CKCenterLayoutComponentCenteringX;
|
||||
return [NSValue value:&options withObjCType:@encode(CKCenterLayoutComponentOptionsStruct)];
|
||||
},
|
||||
@"CKCenterLayoutComponent.centeringOptions.centeringX" : ^(NSNumber* value){
|
||||
options.centeringOptions ^= CKCenterLayoutComponentCenteringX;
|
||||
return [NSValue value:&options
|
||||
withObjCType:@encode(CKCenterLayoutComponentOptionsStruct)];
|
||||
}
|
||||
,
|
||||
@"CKCenterLayoutComponent.centeringOptions.centeringY": ^(NSNumber *value) {
|
||||
options.centeringOptions ^= CKCenterLayoutComponentCenteringY;
|
||||
return [NSValue value:&options withObjCType:@encode(CKCenterLayoutComponentOptionsStruct)];
|
||||
@@ -76,7 +98,8 @@ FB_LINKABLE(CKCenterLayoutComponent_Sonar)
|
||||
options.sizingOptions ^= CKCenterLayoutComponentSizingOptionMinimumY;
|
||||
return [NSValue value:&options withObjCType:@encode(CKCenterLayoutComponentOptionsStruct)];
|
||||
},
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,13 +14,13 @@ typedef id (^SKNodeDataChanged)(id value);
|
||||
|
||||
FB_LINK_REQUIRE_CATEGORY(CKComponent_Sonar)
|
||||
@interface CKComponent (Sonar)
|
||||
@property (assign, nonatomic) NSUInteger flipper_canBeReusedCounter;
|
||||
@property(assign, nonatomic) NSUInteger flipper_canBeReusedCounter;
|
||||
|
||||
- (void)setMutableData:(id)data;
|
||||
- (NSDictionary<NSString *, SKNodeDataChanged> *)sonar_getDataMutationsChanged;
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_getData;
|
||||
- (NSDictionary<NSString *, SKNodeUpdateData> *)sonar_getDataMutations;
|
||||
- (NSString *)sonar_getName;
|
||||
- (NSString *)sonar_getDecoration;
|
||||
- (NSDictionary<NSString*, SKNodeDataChanged>*)sonar_getDataMutationsChanged;
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)sonar_getData;
|
||||
- (NSDictionary<NSString*, SKNodeUpdateData>*)sonar_getDataMutations;
|
||||
- (NSString*)sonar_getName;
|
||||
- (NSString*)sonar_getDecoration;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,54 +11,66 @@
|
||||
|
||||
#import <ComponentKit/CKComponentAccessibility.h>
|
||||
#import <ComponentKit/CKComponentController.h>
|
||||
#import <ComponentKit/CKComponentDebugController.h>
|
||||
#import <ComponentKit/CKComponentInternal.h>
|
||||
#import <ComponentKit/CKComponentSubclass.h>
|
||||
#import <ComponentKit/CKComponentViewConfiguration.h>
|
||||
#import <ComponentKit/CKComponentDebugController.h>
|
||||
#import <ComponentKit/CKMutex.h>
|
||||
#import <FlipperKitLayoutPlugin/SKNamed.h>
|
||||
#import <FlipperKitLayoutPlugin/SKObject.h>
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/message.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#import "CKCenterLayoutComponent+Sonar.h"
|
||||
#import "CKRatioLayoutComponent+Sonar.h"
|
||||
#import "CKFlexboxComponent+Sonar.h"
|
||||
#import "CKInsetComponent+Sonar.h"
|
||||
#import "CKRatioLayoutComponent+Sonar.h"
|
||||
#import "CKStatelessComponent+Sonar.h"
|
||||
#import "FKDataStorageForLiveEditing.h"
|
||||
#import "Utils.h"
|
||||
|
||||
/** This protocol isn't actually adopted anywhere, it just lets us use the SEL below */
|
||||
/** This protocol isn't actually adopted anywhere, it just lets us use the SEL
|
||||
* below */
|
||||
@protocol SonarKitLayoutComponentKitOverrideInformalProtocol
|
||||
- (NSString *)sonar_componentNameOverride;
|
||||
- (NSString *)sonar_componentDecorationOverride;
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_additionalDataOverride;
|
||||
- (NSString*)sonar_componentNameOverride;
|
||||
- (NSString*)sonar_componentDecorationOverride;
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)
|
||||
sonar_additionalDataOverride;
|
||||
@end
|
||||
|
||||
static BOOL AccessibilityContextIsDefault(CKComponentAccessibilityContext accessibilityContext) {
|
||||
static BOOL AccessibilityContextIsDefault(
|
||||
CKComponentAccessibilityContext accessibilityContext) {
|
||||
return accessibilityContext == CKComponentAccessibilityContext();
|
||||
}
|
||||
|
||||
static NSDictionary<NSString *, NSObject *> *AccessibilityContextDict(CKComponentAccessibilityContext accessibilityContext) {
|
||||
NSMutableDictionary<NSString *, NSObject *> *accessibilityDict = [NSMutableDictionary new];
|
||||
static NSDictionary<NSString*, NSObject*>* AccessibilityContextDict(
|
||||
CKComponentAccessibilityContext accessibilityContext) {
|
||||
NSMutableDictionary<NSString*, NSObject*>* accessibilityDict =
|
||||
[NSMutableDictionary new];
|
||||
if (accessibilityContext.isAccessibilityElement != nil) {
|
||||
accessibilityDict[@"isAccessibilityElement"] = SKObject(@([accessibilityContext.isAccessibilityElement boolValue]));
|
||||
accessibilityDict[@"isAccessibilityElement"] =
|
||||
SKObject(@([accessibilityContext.isAccessibilityElement boolValue]));
|
||||
}
|
||||
if (accessibilityContext.accessibilityLabel.hasText()) {
|
||||
accessibilityDict[@"accessibilityLabel"] = SKObject(accessibilityContext.accessibilityLabel.value());
|
||||
accessibilityDict[@"accessibilityLabel"] =
|
||||
SKObject(accessibilityContext.accessibilityLabel.value());
|
||||
}
|
||||
if (accessibilityContext.accessibilityHint.hasText()) {
|
||||
accessibilityDict[@"accessibilityHint"] = SKObject(accessibilityContext.accessibilityHint.value());
|
||||
accessibilityDict[@"accessibilityHint"] =
|
||||
SKObject(accessibilityContext.accessibilityHint.value());
|
||||
}
|
||||
if (accessibilityContext.accessibilityValue.hasText()) {
|
||||
accessibilityDict[@"accessibilityValue"] = SKObject(accessibilityContext.accessibilityValue.value());
|
||||
accessibilityDict[@"accessibilityValue"] =
|
||||
SKObject(accessibilityContext.accessibilityValue.value());
|
||||
}
|
||||
if (accessibilityContext.accessibilityTraits != nil) {
|
||||
accessibilityDict[@"accessibilityTraits"] = SKObject(@([accessibilityContext.accessibilityTraits integerValue]));
|
||||
accessibilityDict[@"accessibilityTraits"] =
|
||||
SKObject(@([accessibilityContext.accessibilityTraits integerValue]));
|
||||
}
|
||||
if (accessibilityContext.accessibilityComponentAction) {
|
||||
accessibilityDict[@"accessibilityComponentAction.identifier"] = SKObject(@(accessibilityContext.accessibilityComponentAction.identifier().c_str()));
|
||||
accessibilityDict[@"accessibilityComponentAction.identifier"] = SKObject(
|
||||
@(accessibilityContext.accessibilityComponentAction.identifier()
|
||||
.c_str()));
|
||||
}
|
||||
return accessibilityDict;
|
||||
}
|
||||
@@ -66,98 +78,104 @@ static NSDictionary<NSString *, NSObject *> *AccessibilityContextDict(CKComponen
|
||||
FB_LINKABLE(CKComponent_Sonar)
|
||||
@implementation CKComponent (Sonar)
|
||||
|
||||
static FKDataStorageForLiveEditing *_dataStorage;
|
||||
static NSMutableSet<NSString *> *_swizzledClasses;
|
||||
static FKDataStorageForLiveEditing* _dataStorage;
|
||||
static NSMutableSet<NSString*>* _swizzledClasses;
|
||||
static CK::StaticMutex _mutex = CK_MUTEX_INITIALIZER;
|
||||
|
||||
+ (void)swizzleOriginalSEL:(SEL)originalSEL to:(SEL)replacementSEL
|
||||
{
|
||||
+ (void)swizzleOriginalSEL:(SEL)originalSEL to:(SEL)replacementSEL {
|
||||
Class targetClass = self;
|
||||
Method original = class_getInstanceMethod(targetClass, originalSEL);
|
||||
Method replacement = class_getInstanceMethod(targetClass, replacementSEL);
|
||||
BOOL didAddMethod =
|
||||
class_addMethod(targetClass,
|
||||
originalSEL,
|
||||
method_getImplementation(replacement),
|
||||
method_getTypeEncoding(replacement));
|
||||
BOOL didAddMethod = class_addMethod(
|
||||
targetClass,
|
||||
originalSEL,
|
||||
method_getImplementation(replacement),
|
||||
method_getTypeEncoding(replacement));
|
||||
if (didAddMethod) {
|
||||
class_replaceMethod(targetClass,
|
||||
replacementSEL,
|
||||
method_getImplementation(original),
|
||||
method_getTypeEncoding(original));
|
||||
class_replaceMethod(
|
||||
targetClass,
|
||||
replacementSEL,
|
||||
method_getImplementation(original),
|
||||
method_getTypeEncoding(original));
|
||||
} else {
|
||||
method_exchangeImplementations(original, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)sonar_getName
|
||||
{
|
||||
- (NSString*)sonar_getName {
|
||||
if ([self respondsToSelector:@selector(sonar_componentNameOverride)]) {
|
||||
return [(id)self sonar_componentNameOverride];
|
||||
}
|
||||
auto const canBeReusedCounter = self.flipper_canBeReusedCounter;
|
||||
if (canBeReusedCounter > 0) {
|
||||
return [NSString stringWithFormat:@"%@ (Can be reused x%lu)", NSStringFromClass([self class]), (unsigned long)canBeReusedCounter];
|
||||
return [NSString stringWithFormat:@"%@ (Can be reused x%lu)",
|
||||
NSStringFromClass([self class]),
|
||||
(unsigned long)canBeReusedCounter];
|
||||
}
|
||||
return NSStringFromClass([self class]);
|
||||
}
|
||||
|
||||
- (NSString *)sonar_getDecoration
|
||||
{
|
||||
- (NSString*)sonar_getDecoration {
|
||||
if ([self respondsToSelector:@selector(sonar_componentDecorationOverride)]) {
|
||||
return [(id)self sonar_componentDecorationOverride];
|
||||
}
|
||||
return @"componentkit";
|
||||
}
|
||||
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_getData
|
||||
{
|
||||
static NSDictionary<NSNumber *, NSString *> *UIControlEventsEnumMap = @{
|
||||
@(UIControlEventTouchDown): @"UIControlEventTouchDown",
|
||||
@(UIControlEventTouchDownRepeat): @"UIControlEventTouchDownRepeat",
|
||||
@(UIControlEventTouchDragInside): @"UIControlEventTouchDragInside",
|
||||
@(UIControlEventTouchDragOutside): @"UIControlEventTouchDragOutside",
|
||||
@(UIControlEventTouchDragEnter): @"UIControlEventTouchDragEnter",
|
||||
@(UIControlEventTouchDragExit): @"UIControlEventTouchDragExit",
|
||||
@(UIControlEventTouchUpInside): @"UIControlEventTouchUpInside",
|
||||
@(UIControlEventTouchUpOutside): @"UIControlEventTouchUpOutside",
|
||||
@(UIControlEventTouchCancel): @"UIControlEventTouchTouchCancel",
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)sonar_getData {
|
||||
static NSDictionary<NSNumber*, NSString*>* UIControlEventsEnumMap = @{
|
||||
@(UIControlEventTouchDown) : @"UIControlEventTouchDown",
|
||||
@(UIControlEventTouchDownRepeat) : @"UIControlEventTouchDownRepeat",
|
||||
@(UIControlEventTouchDragInside) : @"UIControlEventTouchDragInside",
|
||||
@(UIControlEventTouchDragOutside) : @"UIControlEventTouchDragOutside",
|
||||
@(UIControlEventTouchDragEnter) : @"UIControlEventTouchDragEnter",
|
||||
@(UIControlEventTouchDragExit) : @"UIControlEventTouchDragExit",
|
||||
@(UIControlEventTouchUpInside) : @"UIControlEventTouchUpInside",
|
||||
@(UIControlEventTouchUpOutside) : @"UIControlEventTouchUpOutside",
|
||||
@(UIControlEventTouchCancel) : @"UIControlEventTouchTouchCancel",
|
||||
|
||||
@(UIControlEventValueChanged): @"UIControlEventValueChanged",
|
||||
@(UIControlEventPrimaryActionTriggered): @"UIControlEventPrimaryActionTriggered",
|
||||
@(UIControlEventValueChanged) : @"UIControlEventValueChanged",
|
||||
@(UIControlEventPrimaryActionTriggered) :
|
||||
@"UIControlEventPrimaryActionTriggered",
|
||||
|
||||
@(UIControlEventEditingDidBegin): @"UIControlEventEditingDidBegin",
|
||||
@(UIControlEventEditingChanged): @"UIControlEventEditingChanged",
|
||||
@(UIControlEventEditingDidEnd): @"UIControlEventEditingDidEnd",
|
||||
@(UIControlEventEditingDidEndOnExit): @"UIControlEventEditingDidEndOnExit",
|
||||
};
|
||||
@(UIControlEventEditingDidBegin) : @"UIControlEventEditingDidBegin",
|
||||
@(UIControlEventEditingChanged) : @"UIControlEventEditingChanged",
|
||||
@(UIControlEventEditingDidEnd) : @"UIControlEventEditingDidEnd",
|
||||
@(UIControlEventEditingDidEndOnExit) : @"UIControlEventEditingDidEndOnExit",
|
||||
};
|
||||
|
||||
NSMutableArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>* data =
|
||||
[NSMutableArray new];
|
||||
|
||||
NSMutableArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *data = [NSMutableArray new];
|
||||
|
||||
[data addObject: [SKNamed newWithName: @"CKComponent"
|
||||
withValue: @{
|
||||
@"frame": SKObject(self.viewContext.frame),
|
||||
@"controller": SKObject(NSStringFromClass([self.controller class])),
|
||||
@"size": SKObject(ckcomponentSize([self size])),
|
||||
}]];
|
||||
[data addObject:[SKNamed newWithName:@"CKComponent"
|
||||
withValue:@{
|
||||
@"frame" : SKObject(self.viewContext.frame),
|
||||
@"controller" : SKObject(
|
||||
NSStringFromClass([self.controller class])),
|
||||
@"size" : SKObject(ckcomponentSize([self size])),
|
||||
}]];
|
||||
|
||||
auto const canBeReusedCounter = self.flipper_canBeReusedCounter;
|
||||
if (canBeReusedCounter > 0) {
|
||||
[data addObject: [SKNamed newWithName: @"Convert to CKRenderComponent"
|
||||
withValue: @{
|
||||
@"This component can be reused" :
|
||||
SKObject([NSString stringWithFormat:@"%lu times", (unsigned long)canBeReusedCounter])
|
||||
}]];
|
||||
[data addObject:[SKNamed
|
||||
newWithName:@"Convert to CKRenderComponent"
|
||||
withValue:@{
|
||||
@"This component can be reused" : SKObject([NSString
|
||||
stringWithFormat:@"%lu times",
|
||||
(unsigned long)
|
||||
canBeReusedCounter])
|
||||
}]];
|
||||
}
|
||||
|
||||
if (self.viewContext.view) {
|
||||
auto _actions = _CKComponentDebugControlActionsForComponent(self);
|
||||
if (_actions.size() > 0) {
|
||||
NSMutableDictionary<NSString *, NSObject *> *actions = [NSMutableDictionary new];
|
||||
NSMutableDictionary<NSString*, NSObject*>* actions =
|
||||
[NSMutableDictionary new];
|
||||
|
||||
for (NSNumber *controlEvent : [UIControlEventsEnumMap allKeys]) {
|
||||
NSMutableArray<NSDictionary<NSString *, NSObject *> *> *responders = [NSMutableArray new];
|
||||
for (NSNumber* controlEvent : [UIControlEventsEnumMap allKeys]) {
|
||||
NSMutableArray<NSDictionary<NSString*, NSObject*>*>* responders =
|
||||
[NSMutableArray new];
|
||||
|
||||
for (const auto action : _actions) {
|
||||
if ((action.first & [controlEvent integerValue]) == 0) {
|
||||
@@ -167,20 +185,25 @@ static CK::StaticMutex _mutex = CK_MUTEX_INITIALIZER;
|
||||
for (auto responder : action.second) {
|
||||
auto debugTarget = _CKTypedComponentDebugInitialTarget(responder);
|
||||
if (debugTarget.isBlockBaseAction()) {
|
||||
[responders addObject: @{
|
||||
@"identifier": SKObject(@(responder.identifier().c_str())),
|
||||
@"selector": SKObject(NSStringFromSelector(responder.selector())),
|
||||
}];
|
||||
[responders addObject:@{
|
||||
@"identifier" : SKObject(@(responder.identifier().c_str())),
|
||||
@"selector" :
|
||||
SKObject(NSStringFromSelector(responder.selector())),
|
||||
}];
|
||||
|
||||
} else {
|
||||
id initialTarget = debugTarget.get(self);
|
||||
const CKActionInfo actionInfo = CKActionFind(responder.selector(), initialTarget);
|
||||
[responders addObject: @{
|
||||
@"initialTarget": SKObject(NSStringFromClass([initialTarget class])),
|
||||
@"identifier": SKObject(@(responder.identifier().c_str())),
|
||||
@"handler": SKObject(NSStringFromClass([actionInfo.responder class])),
|
||||
@"selector": SKObject(NSStringFromSelector(responder.selector())),
|
||||
}];
|
||||
const CKActionInfo actionInfo =
|
||||
CKActionFind(responder.selector(), initialTarget);
|
||||
[responders addObject:@{
|
||||
@"initialTarget" :
|
||||
SKObject(NSStringFromClass([initialTarget class])),
|
||||
@"identifier" : SKObject(@(responder.identifier().c_str())),
|
||||
@"handler" :
|
||||
SKObject(NSStringFromClass([actionInfo.responder class])),
|
||||
@"selector" :
|
||||
SKObject(NSStringFromSelector(responder.selector())),
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,19 +213,23 @@ static CK::StaticMutex _mutex = CK_MUTEX_INITIALIZER;
|
||||
}
|
||||
}
|
||||
|
||||
[data addObject: [SKNamed newWithName: @"Actions" withValue: actions]];
|
||||
[data addObject:[SKNamed newWithName:@"Actions" withValue:actions]];
|
||||
}
|
||||
}
|
||||
|
||||
// Only add accessibility panel if accessibilityContext is not default
|
||||
CKComponentAccessibilityContext accessibilityContext = [self viewConfiguration].accessibilityContext();
|
||||
CKComponentAccessibilityContext accessibilityContext =
|
||||
[self viewConfiguration].accessibilityContext();
|
||||
if (!AccessibilityContextIsDefault(accessibilityContext)) {
|
||||
[data addObject:
|
||||
[SKNamed newWithName: @"Accessibility"
|
||||
withValue: @{
|
||||
@"accessibilityContext": AccessibilityContextDict(accessibilityContext),
|
||||
@"accessibilityEnabled": SKMutableObject(@(CK::Component::Accessibility::IsAccessibilityEnabled())),
|
||||
}]];
|
||||
[data addObject:[SKNamed
|
||||
newWithName:@"Accessibility"
|
||||
withValue:@{
|
||||
@"accessibilityContext" :
|
||||
AccessibilityContextDict(accessibilityContext),
|
||||
@"accessibilityEnabled" : SKMutableObject(
|
||||
@(CK::Component::Accessibility::
|
||||
IsAccessibilityEnabled())),
|
||||
}]];
|
||||
}
|
||||
if ([self respondsToSelector:@selector(sonar_additionalDataOverride)]) {
|
||||
[data addObjectsFromArray:[(id)self sonar_additionalDataOverride]];
|
||||
@@ -212,10 +239,9 @@ static CK::StaticMutex _mutex = CK_MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
- (void)setMutableData:(id)value {
|
||||
|
||||
}
|
||||
|
||||
- (void) setMutableDataFromStorage {
|
||||
- (void)setMutableDataFromStorage {
|
||||
const auto globalID = self.treeNode.nodeIdentifier;
|
||||
id data = [_dataStorage dataForTreeNodeIdentifier:globalID];
|
||||
if (data) {
|
||||
@@ -223,32 +249,36 @@ static CK::StaticMutex _mutex = CK_MUTEX_INITIALIZER;
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSString *)swizzledMethodNameForRender {
|
||||
return [NSString stringWithFormat:@"sonar_render_%@", NSStringFromClass(self)];
|
||||
+ (NSString*)swizzledMethodNameForRender {
|
||||
return
|
||||
[NSString stringWithFormat:@"sonar_render_%@", NSStringFromClass(self)];
|
||||
}
|
||||
|
||||
+ (SEL)registerNewImplementation:(SEL)selector {
|
||||
SEL resultSelector = sel_registerName([[self swizzledMethodNameForRender] UTF8String]);
|
||||
SEL resultSelector =
|
||||
sel_registerName([[self swizzledMethodNameForRender] UTF8String]);
|
||||
Method method = class_getInstanceMethod(self, selector);
|
||||
class_addMethod(self,
|
||||
resultSelector,
|
||||
method_getImplementation(method),
|
||||
method_getTypeEncoding(method)
|
||||
);
|
||||
class_addMethod(
|
||||
self,
|
||||
resultSelector,
|
||||
method_getImplementation(method),
|
||||
method_getTypeEncoding(method));
|
||||
return resultSelector;
|
||||
}
|
||||
|
||||
- (CKComponent *)sonar_render:(id)state {
|
||||
- (CKComponent*)sonar_render:(id)state {
|
||||
[self setMutableDataFromStorage];
|
||||
SEL resultSelector = NSSelectorFromString([[self class] swizzledMethodNameForRender]);
|
||||
return ((CKComponent *(*)(CKComponent *, SEL, id))objc_msgSend)(self, resultSelector, state);
|
||||
SEL resultSelector =
|
||||
NSSelectorFromString([[self class] swizzledMethodNameForRender]);
|
||||
return ((CKComponent * (*)(CKComponent*, SEL, id)) objc_msgSend)(
|
||||
self, resultSelector, state);
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeDataChanged> *)sonar_getDataMutationsChanged {
|
||||
- (NSDictionary<NSString*, SKNodeDataChanged>*)sonar_getDataMutationsChanged {
|
||||
return @{};
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeUpdateData> *)sonar_getDataMutations {
|
||||
- (NSDictionary<NSString*, SKNodeUpdateData>*)sonar_getDataMutations {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_dataStorage = [[FKDataStorageForLiveEditing alloc] init];
|
||||
@@ -259,46 +289,55 @@ static CK::StaticMutex _mutex = CK_MUTEX_INITIALIZER;
|
||||
if (![_swizzledClasses containsObject:NSStringFromClass([self class])]) {
|
||||
[_swizzledClasses addObject:NSStringFromClass([self class])];
|
||||
if ([self respondsToSelector:@selector(render:)]) {
|
||||
SEL replacement = [[self class] registerNewImplementation:@selector(sonar_render:)];
|
||||
SEL replacement =
|
||||
[[self class] registerNewImplementation:@selector(sonar_render:)];
|
||||
[[self class] swizzleOriginalSEL:@selector(render:) to:replacement];
|
||||
} else {
|
||||
CKAssert(NO, @"Only CKRenderLayoutComponent and CKRenderLayoutWithChildrenComponent children are now able to be live editable");
|
||||
CKAssert(
|
||||
NO,
|
||||
@"Only CKRenderLayoutComponent and CKRenderLayoutWithChildrenComponent children are now able to be live editable");
|
||||
}
|
||||
}
|
||||
}
|
||||
NSDictionary<NSString *, SKNodeDataChanged> *dataChanged = [self sonar_getDataMutationsChanged];
|
||||
NSMutableDictionary *dataMutation = [[NSMutableDictionary alloc] init];
|
||||
NSDictionary<NSString*, SKNodeDataChanged>* dataChanged =
|
||||
[self sonar_getDataMutationsChanged];
|
||||
NSMutableDictionary* dataMutation = [[NSMutableDictionary alloc] init];
|
||||
[dataMutation addEntriesFromDictionary:@{
|
||||
@"Accessibility.accessibilityEnabled": ^(NSNumber *value) {
|
||||
CK::Component::Accessibility::SetForceAccessibilityEnabled([value boolValue]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
const auto globalID = self.treeNode.nodeIdentifier;
|
||||
for (NSString *key in dataChanged) {
|
||||
const auto block = dataChanged[key];
|
||||
[dataMutation setObject:^(id value) {
|
||||
id data = block(value);
|
||||
[_dataStorage setData:data forTreeNodeIdentifier:globalID];
|
||||
[CKComponentDebugController reflowComponentsWithTreeNodeIdentifier:globalID];
|
||||
}
|
||||
forKey:key];
|
||||
}
|
||||
return dataMutation;
|
||||
}
|
||||
const auto globalID = self.treeNode.nodeIdentifier;
|
||||
for (NSString* key in dataChanged) {
|
||||
const auto block = dataChanged[key];
|
||||
[dataMutation
|
||||
setObject:^(id value) {
|
||||
id data = block(value);
|
||||
[_dataStorage setData:data forTreeNodeIdentifier:globalID];
|
||||
[CKComponentDebugController
|
||||
reflowComponentsWithTreeNodeIdentifier:globalID];
|
||||
}
|
||||
forKey:key];
|
||||
}
|
||||
return dataMutation;
|
||||
}
|
||||
|
||||
static char const kCanBeReusedKey = ' ';
|
||||
static char const kCanBeReusedKey = ' ';
|
||||
|
||||
- (void)setFlipper_canBeReusedCounter:(NSUInteger)canBeReusedCounter
|
||||
{
|
||||
objc_setAssociatedObject(self, &kCanBeReusedKey, @(canBeReusedCounter), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
- (void)setFlipper_canBeReusedCounter:(NSUInteger)canBeReusedCounter {
|
||||
objc_setAssociatedObject(
|
||||
self,
|
||||
&kCanBeReusedKey,
|
||||
@(canBeReusedCounter),
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (NSUInteger)flipper_canBeReusedCounter
|
||||
{
|
||||
return [objc_getAssociatedObject(self, &kCanBeReusedKey) unsignedIntegerValue];
|
||||
}
|
||||
- (NSUInteger)flipper_canBeReusedCounter {
|
||||
return [objc_getAssociatedObject(self, &kCanBeReusedKey)
|
||||
unsignedIntegerValue];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,69 +18,72 @@
|
||||
FB_LINKABLE(CKFlexboxComponent_Sonar)
|
||||
@implementation CKFlexboxComponent (Sonar)
|
||||
|
||||
static NSDictionary<NSNumber *, NSString *> *CKFlexboxDirectionEnumMap;
|
||||
static NSDictionary<NSNumber*, NSString*>* CKFlexboxDirectionEnumMap;
|
||||
|
||||
static NSDictionary<NSNumber *, NSString *> *CKFlexboxJustifyContentEnumMap;
|
||||
static NSDictionary<NSNumber*, NSString*>* CKFlexboxJustifyContentEnumMap;
|
||||
|
||||
static NSDictionary<NSNumber *, NSString *> *CKFlexboxAlignItemsEnumMap;
|
||||
static NSDictionary<NSNumber*, NSString*>* CKFlexboxAlignItemsEnumMap;
|
||||
|
||||
static NSDictionary<NSNumber *, NSString *> *CKFlexboxAlignContentEnumMap;
|
||||
static NSDictionary<NSNumber*, NSString*>* CKFlexboxAlignContentEnumMap;
|
||||
|
||||
static NSDictionary<NSNumber *, NSString *> *CKFlexboxWrapEnumMap;
|
||||
static NSDictionary<NSNumber*, NSString*>* CKFlexboxWrapEnumMap;
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
+ (void)initialize {
|
||||
CKFlexboxDirectionEnumMap = @{
|
||||
@(CKFlexboxDirectionColumn): @"column",
|
||||
@(CKFlexboxDirectionRow): @"row",
|
||||
@(CKFlexboxDirectionColumnReverse): @"column-reverse",
|
||||
@(CKFlexboxDirectionRowReverse): @"row-reverse",
|
||||
};
|
||||
@(CKFlexboxDirectionColumn) : @"column",
|
||||
@(CKFlexboxDirectionRow) : @"row",
|
||||
@(CKFlexboxDirectionColumnReverse) : @"column-reverse",
|
||||
@(CKFlexboxDirectionRowReverse) : @"row-reverse",
|
||||
};
|
||||
CKFlexboxJustifyContentEnumMap = @{
|
||||
@(CKFlexboxJustifyContentStart): @"start",
|
||||
@(CKFlexboxJustifyContentCenter): @"center",
|
||||
@(CKFlexboxJustifyContentEnd): @"end",
|
||||
@(CKFlexboxJustifyContentSpaceBetween): @"space-between",
|
||||
@(CKFlexboxJustifyContentSpaceAround): @"space-around",
|
||||
};
|
||||
@(CKFlexboxJustifyContentStart) : @"start",
|
||||
@(CKFlexboxJustifyContentCenter) : @"center",
|
||||
@(CKFlexboxJustifyContentEnd) : @"end",
|
||||
@(CKFlexboxJustifyContentSpaceBetween) : @"space-between",
|
||||
@(CKFlexboxJustifyContentSpaceAround) : @"space-around",
|
||||
};
|
||||
CKFlexboxAlignItemsEnumMap = @{
|
||||
@(CKFlexboxAlignItemsStart): @"start",
|
||||
@(CKFlexboxAlignItemsEnd): @"end",
|
||||
@(CKFlexboxAlignItemsCenter): @"center",
|
||||
@(CKFlexboxAlignItemsBaseline): @"baseline",
|
||||
@(CKFlexboxAlignItemsStretch): @"stretch",
|
||||
};
|
||||
@(CKFlexboxAlignItemsStart) : @"start",
|
||||
@(CKFlexboxAlignItemsEnd) : @"end",
|
||||
@(CKFlexboxAlignItemsCenter) : @"center",
|
||||
@(CKFlexboxAlignItemsBaseline) : @"baseline",
|
||||
@(CKFlexboxAlignItemsStretch) : @"stretch",
|
||||
};
|
||||
CKFlexboxAlignContentEnumMap = @{
|
||||
@(CKFlexboxAlignContentStart): @"start",
|
||||
@(CKFlexboxAlignContentEnd): @"end",
|
||||
@(CKFlexboxAlignContentCenter): @"center",
|
||||
@(CKFlexboxAlignContentSpaceBetween): @"space-between",
|
||||
@(CKFlexboxAlignContentSpaceAround): @"space-around",
|
||||
@(CKFlexboxAlignContentStretch): @"stretch",
|
||||
};
|
||||
@(CKFlexboxAlignContentStart) : @"start",
|
||||
@(CKFlexboxAlignContentEnd) : @"end",
|
||||
@(CKFlexboxAlignContentCenter) : @"center",
|
||||
@(CKFlexboxAlignContentSpaceBetween) : @"space-between",
|
||||
@(CKFlexboxAlignContentSpaceAround) : @"space-around",
|
||||
@(CKFlexboxAlignContentStretch) : @"stretch",
|
||||
};
|
||||
CKFlexboxWrapEnumMap = @{
|
||||
@(CKFlexboxWrapWrap): @"wrap",
|
||||
@(CKFlexboxWrapNoWrap): @"no-wrap",
|
||||
@(CKFlexboxWrapWrapReverse): @"wrap-reverse",
|
||||
};
|
||||
@(CKFlexboxWrapWrap) : @"wrap",
|
||||
@(CKFlexboxWrapNoWrap) : @"no-wrap",
|
||||
@(CKFlexboxWrapWrapReverse) : @"wrap-reverse",
|
||||
};
|
||||
}
|
||||
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_additionalDataOverride
|
||||
{
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)
|
||||
sonar_additionalDataOverride {
|
||||
CKFlexboxComponentStyle style;
|
||||
[[self valueForKey: @"_style"] getValue: &style];
|
||||
[[self valueForKey:@"_style"] getValue:&style];
|
||||
|
||||
return @[[SKNamed
|
||||
newWithName:@"CKFlexboxComponent"
|
||||
withValue:@{
|
||||
@"spacing": SKMutableObject(@(style.spacing)),
|
||||
@"direction": SKMutableObject(CKFlexboxDirectionEnumMap[@(style.direction)]),
|
||||
@"justifyContent": SKMutableObject(CKFlexboxJustifyContentEnumMap[@(style.justifyContent)]),
|
||||
@"alignItems": SKMutableObject(CKFlexboxAlignItemsEnumMap[@(style.alignItems)]),
|
||||
@"alignContent": SKMutableObject(CKFlexboxAlignContentEnumMap[@(style.alignContent)]),
|
||||
@"wrap": SKMutableObject(CKFlexboxWrapEnumMap[@(style.wrap)]),
|
||||
@"padding": SKMutableObject(flexboxRect(style.padding)),
|
||||
}]];
|
||||
return @[ [SKNamed
|
||||
newWithName:@"CKFlexboxComponent"
|
||||
withValue:@{
|
||||
@"spacing" : SKMutableObject(@(style.spacing)),
|
||||
@"direction" :
|
||||
SKMutableObject(CKFlexboxDirectionEnumMap[@(style.direction)]),
|
||||
@"justifyContent" : SKMutableObject(
|
||||
CKFlexboxJustifyContentEnumMap[@(style.justifyContent)]),
|
||||
@"alignItems" :
|
||||
SKMutableObject(CKFlexboxAlignItemsEnumMap[@(style.alignItems)]),
|
||||
@"alignContent" : SKMutableObject(
|
||||
CKFlexboxAlignContentEnumMap[@(style.alignContent)]),
|
||||
@"wrap" : SKMutableObject(CKFlexboxWrapEnumMap[@(style.wrap)]),
|
||||
@"padding" : SKMutableObject(flexboxRect(style.padding)),
|
||||
}] ];
|
||||
}
|
||||
|
||||
- (void)setMutableData:(id)data {
|
||||
@@ -89,14 +92,14 @@ static NSDictionary<NSNumber *, NSString *> *CKFlexboxWrapEnumMap;
|
||||
[self setValue:data forKey:@"_style"];
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeDataChanged> *)sonar_getDataMutationsChanged {
|
||||
- (NSDictionary<NSString*, SKNodeDataChanged>*)sonar_getDataMutationsChanged {
|
||||
__block CKFlexboxComponentStyle style;
|
||||
[[self valueForKey:@"_style"] getValue: &style];
|
||||
return @{
|
||||
@"CKFlexboxComponent.spacing": ^(NSNumber *value) {
|
||||
style.spacing = value.floatValue;
|
||||
return [NSValue value:&style withObjCType:@encode(CKFlexboxComponentStyle)];
|
||||
},
|
||||
[[self valueForKey:@"_style"] getValue:&style];
|
||||
return @{@"CKFlexboxComponent.spacing" : ^(NSNumber* value){
|
||||
style.spacing = value.floatValue;
|
||||
return [NSValue value:&style withObjCType:@encode(CKFlexboxComponentStyle)];
|
||||
}
|
||||
,
|
||||
@"CKFlexboxComponent.direction": ^(NSString *value) {
|
||||
for (NSNumber *key in CKFlexboxDirectionEnumMap) {
|
||||
if ([CKFlexboxDirectionEnumMap[key] isEqualToString:value]) {
|
||||
@@ -158,7 +161,8 @@ static NSDictionary<NSNumber *, NSString *> *CKFlexboxWrapEnumMap;
|
||||
style.padding.start = relativeStructDimension(value);
|
||||
return [NSValue value:&style withObjCType:@encode(CKFlexboxComponentStyle)];
|
||||
},
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,22 +17,27 @@
|
||||
FB_LINKABLE(CKInsetComponent_Sonar)
|
||||
@implementation CKInsetComponent (Sonar)
|
||||
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_additionalDataOverride
|
||||
{
|
||||
return @[[SKNamed newWithName:@"CKInsetComponent" withValue:@{@"insets": SKMutableObject([[self valueForKey:@"_insets"] UIEdgeInsetsValue])}]];
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)
|
||||
sonar_additionalDataOverride {
|
||||
return @[ [SKNamed newWithName:@"CKInsetComponent"
|
||||
withValue:@{
|
||||
@"insets" : SKMutableObject(
|
||||
[[self valueForKey:@"_insets"] UIEdgeInsetsValue])
|
||||
}] ];
|
||||
}
|
||||
|
||||
- (void)setMutableData:(id)data {
|
||||
[self setValue:data forKey:@"_insets"];
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeDataChanged> *)sonar_getDataMutationsChanged {
|
||||
__block UIEdgeInsets insets = [[self valueForKey:@"_insets"] UIEdgeInsetsValue];
|
||||
return @{
|
||||
@"CKInsetComponent.insets.bottom": ^(NSNumber *value) {
|
||||
insets.bottom = value.floatValue;
|
||||
return [NSValue valueWithUIEdgeInsets:insets];
|
||||
},
|
||||
- (NSDictionary<NSString*, SKNodeDataChanged>*)sonar_getDataMutationsChanged {
|
||||
__block UIEdgeInsets insets =
|
||||
[[self valueForKey:@"_insets"] UIEdgeInsetsValue];
|
||||
return @{@"CKInsetComponent.insets.bottom" : ^(NSNumber* value){
|
||||
insets.bottom = value.floatValue;
|
||||
return [NSValue valueWithUIEdgeInsets:insets];
|
||||
}
|
||||
,
|
||||
@"CKInsetComponent.insets.left": ^(NSNumber *value) {
|
||||
insets.left = value.floatValue;
|
||||
return [NSValue valueWithUIEdgeInsets:insets];
|
||||
@@ -45,7 +50,8 @@ FB_LINKABLE(CKInsetComponent_Sonar)
|
||||
insets.top = value.floatValue;
|
||||
return [NSValue valueWithUIEdgeInsets:insets];
|
||||
},
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,4 +12,3 @@ FB_LINK_REQUIRE_CATEGORY(CKRatioLayoutComponent_Sonar)
|
||||
@interface CKRatioLayoutComponent (Sonar)
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -17,23 +17,28 @@
|
||||
FB_LINKABLE(CKRatioLayoutComponent_Sonar)
|
||||
@implementation CKRatioLayoutComponent (Sonar)
|
||||
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)sonar_additionalDataOverride
|
||||
{
|
||||
return @[[SKNamed newWithName:@"CKRatioLayoutComponent" withValue:@{@"ratio": SKMutableObject((NSNumber *)[self valueForKey:@"_ratio"])}]];
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)
|
||||
sonar_additionalDataOverride {
|
||||
return @[ [SKNamed
|
||||
newWithName:@"CKRatioLayoutComponent"
|
||||
withValue:@{
|
||||
@"ratio" : SKMutableObject((NSNumber*)[self valueForKey:@"_ratio"])
|
||||
}] ];
|
||||
}
|
||||
|
||||
- (void)setMutableData:(id)data {
|
||||
[self setValue:data forKey:@"_ratio"];
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeDataChanged> *)sonar_getDataMutationsChanged {
|
||||
return @{
|
||||
@"CKRatioLayoutComponent.ratio": ^(NSNumber *value) {
|
||||
CGFloat ratio = [(NSNumber *)[self valueForKey:@"_ratio"] floatValue];
|
||||
ratio = value.floatValue;
|
||||
return [NSNumber numberWithFloat:ratio];
|
||||
},
|
||||
};
|
||||
- (NSDictionary<NSString*, SKNodeDataChanged>*)sonar_getDataMutationsChanged {
|
||||
return @{@"CKRatioLayoutComponent.ratio" : ^(NSNumber* value){
|
||||
CGFloat ratio = [(NSNumber*)[self valueForKey:@"_ratio"] floatValue];
|
||||
ratio = value.floatValue;
|
||||
return [NSNumber numberWithFloat:ratio];
|
||||
}
|
||||
,
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
FB_LINK_REQUIRE_CATEGORY(CKStatelessComponent_Sonar)
|
||||
@interface CKStatelessComponent (Sonar)
|
||||
|
||||
- (NSString *)sonar_componentNameOverride;
|
||||
- (NSString*)sonar_componentNameOverride;
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
FB_LINKABLE(CKStatelessComponent_Sonar)
|
||||
@implementation CKStatelessComponent (Sonar)
|
||||
|
||||
- (NSString *)sonar_componentNameOverride
|
||||
{
|
||||
- (NSString*)sonar_componentNameOverride {
|
||||
return [self description];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
|
||||
#import <ComponentKit/CKTreeNodeTypes.h>
|
||||
|
||||
/** DataStorage uses to map global IDs of nodes to data which we want to store
|
||||
/** DataStorage uses to map global IDs of nodes to data which we want to store
|
||||
to prodice live editing*/
|
||||
@interface FKDataStorageForLiveEditing : NSObject
|
||||
|
||||
- (id)dataForTreeNodeIdentifier:(CKTreeNodeIdentifier)treeNodeIdentifier;
|
||||
- (void)setData:(id)value forTreeNodeIdentifier:(CKTreeNodeIdentifier)treeNodeIdentifier;
|
||||
- (void)setData:(id)value
|
||||
forTreeNodeIdentifier:(CKTreeNodeIdentifier)treeNodeIdentifier;
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
std::mutex _mutex;
|
||||
}
|
||||
|
||||
- (void)setData:(id)value forTreeNodeIdentifier:(CKTreeNodeIdentifier)treeNodeIdentifier {
|
||||
- (void)setData:(id)value
|
||||
forTreeNodeIdentifier:(CKTreeNodeIdentifier)treeNodeIdentifier {
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_data[treeNodeIdentifier] = value;
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SKSubDescriptor.h"
|
||||
#import <FlipperKitLayoutPlugin/SKDescriptorMapper.h>
|
||||
#import "SKSubDescriptor.h"
|
||||
|
||||
@interface FlipperKitLayoutComponentKitSupport : NSObject
|
||||
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper *)mapper;
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper*)mapper;
|
||||
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper *)mapper
|
||||
subDescriptors:(NSArray<SKSubDescriptor *>*)subDescriptors;
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper*)mapper
|
||||
subDescriptors:(NSArray<SKSubDescriptor*>*)subDescriptors;
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,42 +9,48 @@
|
||||
|
||||
#import "FlipperKitLayoutComponentKitSupport.h"
|
||||
|
||||
#import <ComponentKit/CKComponentRootView.h>
|
||||
#import <ComponentKit/CKComponentHostingView.h>
|
||||
#import <ComponentKit/CKComponentRootView.h>
|
||||
|
||||
#import <FlipperKitLayoutPlugin/SKDescriptorMapper.h>
|
||||
|
||||
#import "SKComponentHostingViewDescriptor.h"
|
||||
#import "SKComponentRootViewDescriptor.h"
|
||||
#import "SKComponentLayoutDescriptor.h"
|
||||
#import "SKComponentLayoutWrapper.h"
|
||||
#import "SKComponentRootViewDescriptor.h"
|
||||
#import "SKSubDescriptor.h"
|
||||
|
||||
@implementation FlipperKitLayoutComponentKitSupport
|
||||
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper *)mapper
|
||||
subDescriptors:(NSArray<SKSubDescriptor *>*)subDescriptors{
|
||||
[mapper registerDescriptor: [[SKComponentHostingViewDescriptor alloc] initWithDescriptorMapper: mapper]
|
||||
forClass: [CKComponentHostingView class]];
|
||||
[mapper registerDescriptor: [[SKComponentRootViewDescriptor alloc] initWithDescriptorMapper: mapper]
|
||||
forClass: [CKComponentRootView class]];
|
||||
SKComponentLayoutDescriptor *layoutDescriptor = [[SKComponentLayoutDescriptor alloc] initWithDescriptorMapper:mapper];
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper*)mapper
|
||||
subDescriptors:(NSArray<SKSubDescriptor*>*)subDescriptors {
|
||||
[mapper registerDescriptor:[[SKComponentHostingViewDescriptor alloc]
|
||||
initWithDescriptorMapper:mapper]
|
||||
forClass:[CKComponentHostingView class]];
|
||||
[mapper registerDescriptor:[[SKComponentRootViewDescriptor alloc]
|
||||
initWithDescriptorMapper:mapper]
|
||||
forClass:[CKComponentRootView class]];
|
||||
SKComponentLayoutDescriptor* layoutDescriptor =
|
||||
[[SKComponentLayoutDescriptor alloc] initWithDescriptorMapper:mapper];
|
||||
[layoutDescriptor addSubDescriptors:subDescriptors];
|
||||
[mapper registerDescriptor: layoutDescriptor
|
||||
forClass: [SKComponentLayoutWrapper class]];
|
||||
[mapper registerDescriptor:layoutDescriptor
|
||||
forClass:[SKComponentLayoutWrapper class]];
|
||||
}
|
||||
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper *)mapper {
|
||||
// What we really want here is "forProtocol:@protocol(CKInspectableView)" but no such luck.
|
||||
[mapper registerDescriptor: [[SKComponentHostingViewDescriptor alloc] initWithDescriptorMapper: mapper]
|
||||
forClass: [CKComponentHostingView class]];
|
||||
[mapper registerDescriptor: [[SKComponentRootViewDescriptor alloc] initWithDescriptorMapper: mapper]
|
||||
forClass: [CKComponentRootView class]];
|
||||
[mapper registerDescriptor: [[SKComponentLayoutDescriptor alloc] initWithDescriptorMapper: mapper]
|
||||
forClass: [SKComponentLayoutWrapper class]];
|
||||
+ (void)setUpWithDescriptorMapper:(SKDescriptorMapper*)mapper {
|
||||
// What we really want here is "forProtocol:@protocol(CKInspectableView)" but
|
||||
// no such luck.
|
||||
[mapper registerDescriptor:[[SKComponentHostingViewDescriptor alloc]
|
||||
initWithDescriptorMapper:mapper]
|
||||
forClass:[CKComponentHostingView class]];
|
||||
[mapper registerDescriptor:[[SKComponentRootViewDescriptor alloc]
|
||||
initWithDescriptorMapper:mapper]
|
||||
forClass:[CKComponentRootView class]];
|
||||
[mapper registerDescriptor:[[SKComponentLayoutDescriptor alloc]
|
||||
initWithDescriptorMapper:mapper]
|
||||
forClass:[SKComponentLayoutWrapper class]];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
@class CKComponentHostingView;
|
||||
|
||||
@interface SKComponentHostingViewDescriptor : SKNodeDescriptor<CKComponentHostingView *>
|
||||
@interface SKComponentHostingViewDescriptor
|
||||
: SKNodeDescriptor<CKComponentHostingView*>
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#import <ComponentKit/CKComponentHostingView.h>
|
||||
#import <ComponentKit/CKComponentHostingViewInternal.h>
|
||||
#import <ComponentKit/CKComponentLayout.h>
|
||||
#import <ComponentKit/CKComponentHostingViewInternal.h>
|
||||
|
||||
#import <FlipperKitLayoutPlugin/SKDescriptorMapper.h>
|
||||
|
||||
@@ -21,25 +20,25 @@
|
||||
|
||||
@implementation SKComponentHostingViewDescriptor
|
||||
|
||||
- (NSString *)identifierForNode:(CKComponentHostingView *)node {
|
||||
return [NSString stringWithFormat: @"%p", node];
|
||||
- (NSString*)identifierForNode:(CKComponentHostingView*)node {
|
||||
return [NSString stringWithFormat:@"%p", node];
|
||||
}
|
||||
|
||||
- (NSUInteger)childCountForNode:(CKComponentHostingView *)node {
|
||||
- (NSUInteger)childCountForNode:(CKComponentHostingView*)node {
|
||||
return node.mountedLayout.component ? 1 : 0;
|
||||
}
|
||||
|
||||
- (id)childForNode:(CKComponentHostingView *)node atIndex:(NSUInteger)index {
|
||||
- (id)childForNode:(CKComponentHostingView*)node atIndex:(NSUInteger)index {
|
||||
return [SKComponentLayoutWrapper newFromRoot:node];
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted forNode:(CKComponentHostingView *)node {
|
||||
SKNodeDescriptor *viewDescriptor = [self descriptorForClass: [UIView class]];
|
||||
[viewDescriptor setHighlighted: highlighted forNode: node];
|
||||
- (void)setHighlighted:(BOOL)highlighted forNode:(CKComponentHostingView*)node {
|
||||
SKNodeDescriptor* viewDescriptor = [self descriptorForClass:[UIView class]];
|
||||
[viewDescriptor setHighlighted:highlighted forNode:node];
|
||||
}
|
||||
|
||||
- (void)hitTest:(SKTouch *)touch forNode:(CKComponentHostingView *)node {
|
||||
[touch continueWithChildIndex: 0 withOffset: (CGPoint){ 0, 0 }];
|
||||
- (void)hitTest:(SKTouch*)touch forNode:(CKComponentHostingView*)node {
|
||||
[touch continueWithChildIndex:0 withOffset:(CGPoint){0, 0}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
@class SKComponentLayoutWrapper;
|
||||
|
||||
@interface SKComponentLayoutDescriptor: SKNodeDescriptor<SKComponentLayoutWrapper *>
|
||||
@interface SKComponentLayoutDescriptor
|
||||
: SKNodeDescriptor<SKComponentLayoutWrapper*>
|
||||
|
||||
- (void)addSubDescriptors:(NSArray<SKSubDescriptor *>*)subDescriptors;
|
||||
- (void)addSubDescriptors:(NSArray<SKSubDescriptor*>*)subDescriptors;
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,30 +10,29 @@
|
||||
#import "SKComponentLayoutDescriptor.h"
|
||||
|
||||
#import <ComponentKit/CKComponent.h>
|
||||
#import <ComponentKit/CKComponentInternal.h>
|
||||
#import <ComponentKit/CKComponentAccessibility.h>
|
||||
#import <ComponentKit/CKComponentActionInternal.h>
|
||||
#import <ComponentKit/CKComponentDebugController.h>
|
||||
#import <ComponentKit/CKComponentInternal.h>
|
||||
#import <ComponentKit/CKComponentLayout.h>
|
||||
#import <ComponentKit/CKComponentRootView.h>
|
||||
#import <ComponentKit/CKComponentViewConfiguration.h>
|
||||
#import <ComponentKit/CKComponentAccessibility.h>
|
||||
#import <ComponentKit/CKComponentDebugController.h>
|
||||
#import <ComponentKit/CKInsetComponent.h>
|
||||
#import <ComponentKit/CKFlexboxComponent.h>
|
||||
#import <ComponentKit/CKInsetComponent.h>
|
||||
|
||||
#import <FlipperKitHighlightOverlay/SKHighlightOverlay.h>
|
||||
#import <FlipperKitLayoutPlugin/SKObject.h>
|
||||
#import <FlipperKitLayoutTextSearchable/FKTextSearchable.h>
|
||||
|
||||
#import "SKSubDescriptor.h"
|
||||
#import "SKComponentLayoutWrapper.h"
|
||||
#import "CKComponent+Sonar.h"
|
||||
#import "SKComponentLayoutWrapper.h"
|
||||
#import "SKSubDescriptor.h"
|
||||
#import "Utils.h"
|
||||
|
||||
@implementation SKComponentLayoutDescriptor
|
||||
{
|
||||
NSDictionary<NSNumber *, NSString *> *CKFlexboxAlignSelfEnumMap;
|
||||
NSDictionary<NSNumber *, NSString *> *CKFlexboxPositionTypeEnumMap;
|
||||
NSArray<SKSubDescriptor *>*_registeredSubdescriptors;
|
||||
@implementation SKComponentLayoutDescriptor {
|
||||
NSDictionary<NSNumber*, NSString*>* CKFlexboxAlignSelfEnumMap;
|
||||
NSDictionary<NSNumber*, NSString*>* CKFlexboxPositionTypeEnumMap;
|
||||
NSArray<SKSubDescriptor*>* _registeredSubdescriptors;
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
@@ -51,38 +50,37 @@
|
||||
|
||||
- (void)initEnumMaps {
|
||||
CKFlexboxAlignSelfEnumMap = @{
|
||||
@(CKFlexboxAlignSelfAuto): @"auto",
|
||||
@(CKFlexboxAlignSelfStart): @"start",
|
||||
@(CKFlexboxAlignSelfEnd): @"end",
|
||||
@(CKFlexboxAlignSelfCenter): @"center",
|
||||
@(CKFlexboxAlignSelfBaseline): @"baseline",
|
||||
@(CKFlexboxAlignSelfStretch): @"stretch",
|
||||
};
|
||||
@(CKFlexboxAlignSelfAuto) : @"auto",
|
||||
@(CKFlexboxAlignSelfStart) : @"start",
|
||||
@(CKFlexboxAlignSelfEnd) : @"end",
|
||||
@(CKFlexboxAlignSelfCenter) : @"center",
|
||||
@(CKFlexboxAlignSelfBaseline) : @"baseline",
|
||||
@(CKFlexboxAlignSelfStretch) : @"stretch",
|
||||
};
|
||||
|
||||
CKFlexboxPositionTypeEnumMap = @{
|
||||
@(CKFlexboxPositionTypeRelative): @"relative",
|
||||
@(CKFlexboxPositionTypeAbsolute): @"absolute",
|
||||
};
|
||||
@(CKFlexboxPositionTypeRelative) : @"relative",
|
||||
@(CKFlexboxPositionTypeAbsolute) : @"absolute",
|
||||
};
|
||||
}
|
||||
|
||||
- (NSString *)identifierForNode:(SKComponentLayoutWrapper *)node {
|
||||
- (NSString*)identifierForNode:(SKComponentLayoutWrapper*)node {
|
||||
return node.identifier;
|
||||
}
|
||||
|
||||
- (NSString *)identifierForInvalidation:(SKComponentLayoutWrapper *)node
|
||||
{
|
||||
- (NSString*)identifierForInvalidation:(SKComponentLayoutWrapper*)node {
|
||||
return [NSString stringWithFormat:@"%p", node.rootNode];
|
||||
}
|
||||
|
||||
- (NSString *)nameForNode:(SKComponentLayoutWrapper *)node {
|
||||
- (NSString*)nameForNode:(SKComponentLayoutWrapper*)node {
|
||||
return [node.component sonar_getName];
|
||||
}
|
||||
|
||||
- (NSString *)decorationForNode:(SKComponentLayoutWrapper *)node {
|
||||
- (NSString*)decorationForNode:(SKComponentLayoutWrapper*)node {
|
||||
return [node.component sonar_getDecoration];
|
||||
}
|
||||
|
||||
- (NSUInteger)childCountForNode:(SKComponentLayoutWrapper *)node {
|
||||
- (NSUInteger)childCountForNode:(SKComponentLayoutWrapper*)node {
|
||||
NSUInteger count = node.children.size();
|
||||
if (count == 0) {
|
||||
count = node.component.viewContext.view ? 1 : 0;
|
||||
@@ -90,93 +88,107 @@
|
||||
return count;
|
||||
}
|
||||
|
||||
- (id)childForNode:(SKComponentLayoutWrapper *)node atIndex:(NSUInteger)index {
|
||||
if (node.children.size() == 0) {
|
||||
if (node.rootNode == node.component.viewContext.view) {
|
||||
return nil;
|
||||
}
|
||||
return node.component.viewContext.view;
|
||||
- (id)childForNode:(SKComponentLayoutWrapper*)node atIndex:(NSUInteger)index {
|
||||
if (node.children.size() == 0) {
|
||||
if (node.rootNode == node.component.viewContext.view) {
|
||||
return nil;
|
||||
}
|
||||
return node.children[index];
|
||||
return node.component.viewContext.view;
|
||||
}
|
||||
return node.children[index];
|
||||
}
|
||||
|
||||
- (NSArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *)dataForNode:(SKComponentLayoutWrapper *)node {
|
||||
NSMutableArray<SKNamed<NSDictionary<NSString *, NSObject *> *> *> *data = [NSMutableArray new];
|
||||
- (NSArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>*)dataForNode:
|
||||
(SKComponentLayoutWrapper*)node {
|
||||
NSMutableArray<SKNamed<NSDictionary<NSString*, NSObject*>*>*>* data =
|
||||
[NSMutableArray new];
|
||||
|
||||
if (node.isFlexboxChild) {
|
||||
[data addObject: [SKNamed newWithName:@"Layout" withValue:[self propsForFlexboxChild:node.flexboxChild]]];
|
||||
[data
|
||||
addObject:[SKNamed
|
||||
newWithName:@"Layout"
|
||||
withValue:[self
|
||||
propsForFlexboxChild:node.flexboxChild]]];
|
||||
}
|
||||
NSMutableDictionary<NSString *, NSObject *> *extraData = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary<NSString*, NSObject*>* extraData =
|
||||
[[NSMutableDictionary alloc] init];
|
||||
|
||||
for (SKSubDescriptor *s in _registeredSubdescriptors) {
|
||||
for (SKSubDescriptor* s in _registeredSubdescriptors) {
|
||||
[extraData setObject:[s getDataForNode:node] forKey:[s getName]];
|
||||
}
|
||||
if (extraData.count > 0) {
|
||||
[data addObject: [SKNamed newWithName:@"Extra Sections" withValue:extraData]];
|
||||
[data addObject:[SKNamed newWithName:@"Extra Sections"
|
||||
withValue:extraData]];
|
||||
}
|
||||
|
||||
[data addObjectsFromArray:[node.component sonar_getData]];
|
||||
return data;
|
||||
}
|
||||
|
||||
- (void)addSubDescriptors:(nonnull NSArray<SKSubDescriptor *>*)subDescriptors{
|
||||
- (void)addSubDescriptors:(nonnull NSArray<SKSubDescriptor*>*)subDescriptors {
|
||||
_registeredSubdescriptors = subDescriptors;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSObject *> *)propsForFlexboxChild:(CKFlexboxComponentChild)child {
|
||||
- (NSDictionary<NSString*, NSObject*>*)propsForFlexboxChild:
|
||||
(CKFlexboxComponentChild)child {
|
||||
return @{
|
||||
@"spacingBefore": SKObject(@(child.spacingBefore)),
|
||||
@"spacingAfter": SKObject(@(child.spacingAfter)),
|
||||
@"flexGrow": SKObject(@(child.flexGrow)),
|
||||
@"flexShrink": SKObject(@(child.flexShrink)),
|
||||
@"zIndex": SKObject(@(child.zIndex)),
|
||||
@"sizeConstraints": SKObject(ckcomponentSize(child.sizeConstraints)),
|
||||
@"useTextRounding": SKObject(@(child.useTextRounding)),
|
||||
@"margin": flexboxRect(child.margin),
|
||||
@"flexBasis": relativeDimension(child.flexBasis),
|
||||
@"padding": flexboxRect(child.padding),
|
||||
@"alignSelf": CKFlexboxAlignSelfEnumMap[@(child.alignSelf)],
|
||||
@"position": @{
|
||||
@"type": CKFlexboxPositionTypeEnumMap[@(child.position.type)],
|
||||
@"start": relativeDimension(child.position.start),
|
||||
@"top": relativeDimension(child.position.top),
|
||||
@"end": relativeDimension(child.position.end),
|
||||
@"bottom": relativeDimension(child.position.bottom),
|
||||
@"left": relativeDimension(child.position.left),
|
||||
@"right": relativeDimension(child.position.right),
|
||||
},
|
||||
@"aspectRatio": @(child.aspectRatio.aspectRatio()),
|
||||
};
|
||||
@"spacingBefore" : SKObject(@(child.spacingBefore)),
|
||||
@"spacingAfter" : SKObject(@(child.spacingAfter)),
|
||||
@"flexGrow" : SKObject(@(child.flexGrow)),
|
||||
@"flexShrink" : SKObject(@(child.flexShrink)),
|
||||
@"zIndex" : SKObject(@(child.zIndex)),
|
||||
@"sizeConstraints" : SKObject(ckcomponentSize(child.sizeConstraints)),
|
||||
@"useTextRounding" : SKObject(@(child.useTextRounding)),
|
||||
@"margin" : flexboxRect(child.margin),
|
||||
@"flexBasis" : relativeDimension(child.flexBasis),
|
||||
@"padding" : flexboxRect(child.padding),
|
||||
@"alignSelf" : CKFlexboxAlignSelfEnumMap[@(child.alignSelf)],
|
||||
@"position" : @{
|
||||
@"type" : CKFlexboxPositionTypeEnumMap[@(child.position.type)],
|
||||
@"start" : relativeDimension(child.position.start),
|
||||
@"top" : relativeDimension(child.position.top),
|
||||
@"end" : relativeDimension(child.position.end),
|
||||
@"bottom" : relativeDimension(child.position.bottom),
|
||||
@"left" : relativeDimension(child.position.left),
|
||||
@"right" : relativeDimension(child.position.right),
|
||||
},
|
||||
@"aspectRatio" : @(child.aspectRatio.aspectRatio()),
|
||||
};
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, SKNodeUpdateData> *)dataMutationsForNode:(SKComponentLayoutWrapper *)node {
|
||||
- (NSDictionary<NSString*, SKNodeUpdateData>*)dataMutationsForNode:
|
||||
(SKComponentLayoutWrapper*)node {
|
||||
return [node.component sonar_getDataMutations];
|
||||
}
|
||||
|
||||
- (NSArray<SKNamed<NSString *> *> *)attributesForNode:(SKComponentLayoutWrapper *)node {
|
||||
NSMutableArray<SKNamed<NSString *> *> *attributes = [NSMutableArray array];
|
||||
[attributes addObject:[SKNamed newWithName:@"responder"
|
||||
withValue:SKObject(NSStringFromClass([node.component.nextResponder class]))]];
|
||||
- (NSArray<SKNamed<NSString*>*>*)attributesForNode:
|
||||
(SKComponentLayoutWrapper*)node {
|
||||
NSMutableArray<SKNamed<NSString*>*>* attributes = [NSMutableArray array];
|
||||
[attributes
|
||||
addObject:[SKNamed
|
||||
newWithName:@"responder"
|
||||
withValue:SKObject(NSStringFromClass(
|
||||
[node.component.nextResponder class]))]];
|
||||
return attributes;
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted forNode:(SKComponentLayoutWrapper *)node {
|
||||
SKHighlightOverlay *overlay = [SKHighlightOverlay sharedInstance];
|
||||
- (void)setHighlighted:(BOOL)highlighted
|
||||
forNode:(SKComponentLayoutWrapper*)node {
|
||||
SKHighlightOverlay* overlay = [SKHighlightOverlay sharedInstance];
|
||||
if (highlighted) {
|
||||
CKComponentViewContext viewContext = node.component.viewContext;
|
||||
[overlay mountInView: viewContext.view
|
||||
withFrame: viewContext.frame];
|
||||
[overlay mountInView:viewContext.view withFrame:viewContext.frame];
|
||||
} else {
|
||||
[overlay unmount];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hitTest:(SKTouch *)touch forNode:(SKComponentLayoutWrapper *)node {
|
||||
- (void)hitTest:(SKTouch*)touch forNode:(SKComponentLayoutWrapper*)node {
|
||||
if (node.children.size() == 0) {
|
||||
UIView *componentView = node.component.viewContext.view;
|
||||
UIView* componentView = node.component.viewContext.view;
|
||||
if (componentView != nil) {
|
||||
if ([touch containedIn: componentView.bounds]) {
|
||||
[touch continueWithChildIndex: 0 withOffset: componentView.bounds.origin];
|
||||
if ([touch containedIn:componentView.bounds]) {
|
||||
[touch continueWithChildIndex:0 withOffset:componentView.bounds.origin];
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -186,13 +198,10 @@
|
||||
for (index = node.children.size() - 1; index >= 0; index--) {
|
||||
const auto child = node.children[index];
|
||||
|
||||
CGRect frame = {
|
||||
.origin = child.position,
|
||||
.size = child.size
|
||||
};
|
||||
CGRect frame = {.origin = child.position, .size = child.size};
|
||||
|
||||
if ([touch containedIn: frame]) {
|
||||
[touch continueWithChildIndex: index withOffset: child.position];
|
||||
if ([touch containedIn:frame]) {
|
||||
[touch continueWithChildIndex:index withOffset:child.position];
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -200,22 +209,26 @@
|
||||
[touch finish];
|
||||
}
|
||||
|
||||
- (BOOL)matchesQuery:(NSString *)query forNode:(id)node {
|
||||
if ([super matchesQuery:query forNode:node]) {
|
||||
return YES;
|
||||
- (BOOL)matchesQuery:(NSString*)query forNode:(id)node {
|
||||
if ([super matchesQuery:query forNode:node]) {
|
||||
return YES;
|
||||
}
|
||||
if ([node isKindOfClass:[SKComponentLayoutWrapper class]]) {
|
||||
const auto layoutWrapper = (SKComponentLayoutWrapper*)node;
|
||||
if ([layoutWrapper.component
|
||||
conformsToProtocol:@protocol(FKTextSearchable)]) {
|
||||
NSString* text =
|
||||
((id<FKTextSearchable>)layoutWrapper.component).searchableText;
|
||||
return [self string:text contains:query];
|
||||
}
|
||||
if ([node isKindOfClass:[SKComponentLayoutWrapper class]]) {
|
||||
const auto layoutWrapper = (SKComponentLayoutWrapper *)node;
|
||||
if ([layoutWrapper.component conformsToProtocol:@protocol(FKTextSearchable)]) {
|
||||
NSString *text = ((id<FKTextSearchable>)layoutWrapper.component).searchableText;
|
||||
return [self string:text contains:query];
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)string:(NSString *)string contains:(NSString *)substring {
|
||||
return string != nil && substring != nil && [string rangeOfString: substring options: NSCaseInsensitiveSearch].location != NSNotFound;
|
||||
- (BOOL)string:(NSString*)string contains:(NSString*)substring {
|
||||
return string != nil && substring != nil &&
|
||||
[string rangeOfString:substring options:NSCaseInsensitiveSearch]
|
||||
.location != NSNotFound;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,17 +14,18 @@
|
||||
|
||||
@interface SKComponentLayoutWrapper : NSObject
|
||||
|
||||
@property (nonatomic, weak, readonly) CKComponent *component;
|
||||
@property (nonatomic, readonly) NSString *identifier;
|
||||
@property (nonatomic, readonly) CGSize size;
|
||||
@property (nonatomic, readonly) CGPoint position;
|
||||
@property (nonatomic, readonly) std::vector<SKComponentLayoutWrapper *> children;
|
||||
@property (nonatomic, weak, readonly) id<CKInspectableView> rootNode;
|
||||
@property(nonatomic, weak, readonly) CKComponent* component;
|
||||
@property(nonatomic, readonly) NSString* identifier;
|
||||
@property(nonatomic, readonly) CGSize size;
|
||||
@property(nonatomic, readonly) CGPoint position;
|
||||
@property(nonatomic, readonly) std::vector<SKComponentLayoutWrapper*> children;
|
||||
@property(nonatomic, weak, readonly) id<CKInspectableView> rootNode;
|
||||
// Null for layouts which are not direct children of a CKFlexboxComponent
|
||||
@property (nonatomic, readonly) BOOL isFlexboxChild;
|
||||
@property (nonatomic, readonly) CKFlexboxComponentChild flexboxChild;
|
||||
@property(nonatomic, readonly) BOOL isFlexboxChild;
|
||||
@property(nonatomic, readonly) CKFlexboxComponentChild flexboxChild;
|
||||
|
||||
+ (instancetype)newFromRoot:(id<CKInspectableView>)root;
|
||||
+ (instancetype)newFromRoot:(id<CKInspectableView>)root parentKey:(NSString *)parentKey;
|
||||
+ (instancetype)newFromRoot:(id<CKInspectableView>)root
|
||||
parentKey:(NSString*)parentKey;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,23 +11,27 @@
|
||||
|
||||
#import <ComponentKit/CKAnalyticsListenerHelpers.h>
|
||||
#import <ComponentKit/CKComponent.h>
|
||||
#import <ComponentKit/CKComponentInternal.h>
|
||||
#import <ComponentKit/CKComponentRootView.h>
|
||||
#import <ComponentKit/CKComponentAttachController.h>
|
||||
#import <ComponentKit/CKComponentAttachControllerInternal.h>
|
||||
#import <ComponentKit/CKComponentInternal.h>
|
||||
#import <ComponentKit/CKComponentRootView.h>
|
||||
#import <ComponentKit/CKInspectableView.h>
|
||||
|
||||
#import "CKComponent+Sonar.h"
|
||||
|
||||
static char const kLayoutWrapperKey = ' ';
|
||||
|
||||
static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKComponent *child) {
|
||||
static CKFlexboxComponentChild findFlexboxLayoutParams(
|
||||
CKComponent* parent,
|
||||
CKComponent* child) {
|
||||
if ([parent isKindOfClass:[CKFlexboxComponent class]]) {
|
||||
static Ivar ivar = class_getInstanceVariable([CKFlexboxComponent class], "_children");
|
||||
static Ivar ivar =
|
||||
class_getInstanceVariable([CKFlexboxComponent class], "_children");
|
||||
static ptrdiff_t offset = ivar_getOffset(ivar);
|
||||
|
||||
unsigned char *pComponent = (unsigned char*)(__bridge void*)parent;
|
||||
auto children = (std::vector<CKFlexboxComponentChild> *)(pComponent + offset);
|
||||
unsigned char* pComponent = (unsigned char*)(__bridge void*)parent;
|
||||
auto children =
|
||||
(std::vector<CKFlexboxComponentChild>*)(pComponent + offset);
|
||||
|
||||
if (children) {
|
||||
for (auto it = children->begin(); it != children->end(); it++) {
|
||||
@@ -47,47 +51,59 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo
|
||||
return [self newFromRoot:root parentKey:@""];
|
||||
}
|
||||
|
||||
+ (instancetype)newFromRoot:(id<CKInspectableView>)root parentKey:(NSString *)parentKey {
|
||||
+ (instancetype)newFromRoot:(id<CKInspectableView>)root
|
||||
parentKey:(NSString*)parentKey {
|
||||
const CKComponentLayout layout = [root mountedLayout];
|
||||
// Check if there is a cached wrapper.
|
||||
if (layout.component) {
|
||||
SKComponentLayoutWrapper *cachedWrapper = objc_getAssociatedObject(layout.component, &kLayoutWrapperKey);
|
||||
SKComponentLayoutWrapper* cachedWrapper =
|
||||
objc_getAssociatedObject(layout.component, &kLayoutWrapperKey);
|
||||
if (cachedWrapper) {
|
||||
return cachedWrapper;
|
||||
}
|
||||
}
|
||||
// TODO: Add support for `CKMountable` components.
|
||||
CKComponent *component = (CKComponent *)layout.component;
|
||||
CKComponentReuseWrapper *reuseWrapper = CKAnalyticsListenerHelpers::GetReusedNodes(component);
|
||||
CKComponent* component = (CKComponent*)layout.component;
|
||||
CKComponentReuseWrapper* reuseWrapper =
|
||||
CKAnalyticsListenerHelpers::GetReusedNodes(component);
|
||||
// Create a new layout wrapper.
|
||||
SKComponentLayoutWrapper *const wrapper =
|
||||
[[SKComponentLayoutWrapper alloc] initWithLayout:layout
|
||||
position:CGPointMake(0, 0)
|
||||
parentKey:[NSString stringWithFormat: @"%@%d.", parentKey, component.treeNode.nodeIdentifier]
|
||||
reuseWrapper:reuseWrapper
|
||||
rootNode: root];
|
||||
SKComponentLayoutWrapper* const wrapper = [[SKComponentLayoutWrapper alloc]
|
||||
initWithLayout:layout
|
||||
position:CGPointMake(0, 0)
|
||||
parentKey:[NSString
|
||||
stringWithFormat:@"%@%d.",
|
||||
parentKey,
|
||||
component.treeNode.nodeIdentifier]
|
||||
reuseWrapper:reuseWrapper
|
||||
rootNode:root];
|
||||
// Cache the result.
|
||||
if (component) {
|
||||
objc_setAssociatedObject(component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
objc_setAssociatedObject(
|
||||
component,
|
||||
&kLayoutWrapperKey,
|
||||
wrapper,
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLayout:(const CKComponentLayout &)layout
|
||||
- (instancetype)initWithLayout:(const CKComponentLayout&)layout
|
||||
position:(CGPoint)position
|
||||
parentKey:(NSString *)parentKey
|
||||
reuseWrapper:(CKComponentReuseWrapper *)reuseWrapper
|
||||
rootNode:(id<CKInspectableView>)node
|
||||
{
|
||||
parentKey:(NSString*)parentKey
|
||||
reuseWrapper:(CKComponentReuseWrapper*)reuseWrapper
|
||||
rootNode:(id<CKInspectableView>)node {
|
||||
if (self = [super init]) {
|
||||
_rootNode = node;
|
||||
_component = (CKComponent *)layout.component;
|
||||
_component = (CKComponent*)layout.component;
|
||||
_size = layout.size;
|
||||
_position = position;
|
||||
_identifier = [parentKey stringByAppendingString:layout.component ? NSStringFromClass([layout.component class]) : @"(null)"];
|
||||
_identifier = [parentKey stringByAppendingString:layout.component
|
||||
? NSStringFromClass([layout.component class])
|
||||
: @"(null)"];
|
||||
|
||||
if (_component && reuseWrapper) {
|
||||
auto const canBeReusedCounter = [reuseWrapper canBeReusedCounter:_component.treeNode.nodeIdentifier];
|
||||
auto const canBeReusedCounter =
|
||||
[reuseWrapper canBeReusedCounter:_component.treeNode.nodeIdentifier];
|
||||
if (canBeReusedCounter > 0) {
|
||||
_component.flipper_canBeReusedCounter = canBeReusedCounter;
|
||||
}
|
||||
@@ -95,18 +111,22 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo
|
||||
|
||||
if (layout.children != nullptr) {
|
||||
int index = 0;
|
||||
for (const auto &child : *layout.children) {
|
||||
for (const auto& child : *layout.children) {
|
||||
if (child.layout.component == nil) {
|
||||
continue; // nil children are allowed, ignore them
|
||||
}
|
||||
SKComponentLayoutWrapper *childWrapper = [[SKComponentLayoutWrapper alloc] initWithLayout:child.layout
|
||||
position:child.position
|
||||
parentKey:[_identifier stringByAppendingFormat:@"[%d].", index++]
|
||||
reuseWrapper:reuseWrapper
|
||||
rootNode:node
|
||||
];
|
||||
childWrapper->_isFlexboxChild = [_component isKindOfClass:[CKFlexboxComponent class]];
|
||||
childWrapper->_flexboxChild = findFlexboxLayoutParams(_component, (CKComponent *)child.layout.component);
|
||||
SKComponentLayoutWrapper* childWrapper =
|
||||
[[SKComponentLayoutWrapper alloc]
|
||||
initWithLayout:child.layout
|
||||
position:child.position
|
||||
parentKey:[_identifier
|
||||
stringByAppendingFormat:@"[%d].", index++]
|
||||
reuseWrapper:reuseWrapper
|
||||
rootNode:node];
|
||||
childWrapper->_isFlexboxChild =
|
||||
[_component isKindOfClass:[CKFlexboxComponent class]];
|
||||
childWrapper->_flexboxChild = findFlexboxLayoutParams(
|
||||
_component, (CKComponent*)child.layout.component);
|
||||
_children.push_back(childWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
@class CKComponentRootView;
|
||||
|
||||
@interface SKComponentRootViewDescriptor : SKNodeDescriptor<CKComponentRootView *>
|
||||
@interface SKComponentRootViewDescriptor
|
||||
: SKNodeDescriptor<CKComponentRootView*>
|
||||
|
||||
@end
|
||||
|
||||
@@ -22,28 +22,30 @@
|
||||
|
||||
@implementation SKComponentRootViewDescriptor
|
||||
|
||||
- (NSString *)identifierForNode:(CKComponentRootView *)node {
|
||||
return [NSString stringWithFormat: @"%p", node];
|
||||
- (NSString*)identifierForNode:(CKComponentRootView*)node {
|
||||
return [NSString stringWithFormat:@"%p", node];
|
||||
}
|
||||
|
||||
- (NSUInteger)childCountForNode:(CKComponentRootView *)node {
|
||||
- (NSUInteger)childCountForNode:(CKComponentRootView*)node {
|
||||
const auto state = CKGetAttachStateForView(node);
|
||||
return state == nil ? 0 : 1;
|
||||
}
|
||||
|
||||
- (id)childForNode:(CKComponentRootView *)node atIndex:(NSUInteger)index {
|
||||
- (id)childForNode:(CKComponentRootView*)node atIndex:(NSUInteger)index {
|
||||
auto const attachState = CKGetAttachStateForView(node);
|
||||
return [SKComponentLayoutWrapper newFromRoot:node
|
||||
parentKey:[NSString stringWithFormat:@"%d.", attachState.scopeIdentifier]];
|
||||
return [SKComponentLayoutWrapper
|
||||
newFromRoot:node
|
||||
parentKey:[NSString
|
||||
stringWithFormat:@"%d.", attachState.scopeIdentifier]];
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted forNode:(CKComponentRootView *)node {
|
||||
SKNodeDescriptor *viewDescriptor = [self descriptorForClass: [UIView class]];
|
||||
[viewDescriptor setHighlighted: highlighted forNode: node];
|
||||
- (void)setHighlighted:(BOOL)highlighted forNode:(CKComponentRootView*)node {
|
||||
SKNodeDescriptor* viewDescriptor = [self descriptorForClass:[UIView class]];
|
||||
[viewDescriptor setHighlighted:highlighted forNode:node];
|
||||
}
|
||||
|
||||
- (void)hitTest:(SKTouch *)touch forNode:(CKComponentRootView *)node {
|
||||
[touch continueWithChildIndex: 0 withOffset: (CGPoint){ 0, 0 }];
|
||||
- (void)hitTest:(SKTouch*)touch forNode:(CKComponentRootView*)node {
|
||||
[touch continueWithChildIndex:0 withOffset:(CGPoint){0, 0}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,19 +11,19 @@
|
||||
|
||||
/**
|
||||
A SKSubDescriptor is an object which knows how to expose an Object of type T
|
||||
to the SKLayoutDescriptor. This class is for frameworks wanting to pass data along
|
||||
through the Layout Descriptor.
|
||||
to the SKLayoutDescriptor. This class is for frameworks wanting to pass data
|
||||
along through the Layout Descriptor.
|
||||
*/
|
||||
@interface SKSubDescriptor : NSObject
|
||||
|
||||
/**
|
||||
This is the SubDescriptor name.
|
||||
*/
|
||||
- (NSString *) getName;
|
||||
- (NSString*)getName;
|
||||
|
||||
/**
|
||||
This is the data the SubDescriptor wants to pass up to the SKLayoutDescriptor.
|
||||
*/
|
||||
- (NSString *)getDataForNode:(SKComponentLayoutWrapper *)node;
|
||||
- (NSString*)getDataForNode:(SKComponentLayoutWrapper*)node;
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,15 +10,15 @@
|
||||
#import "SKSubDescriptor.h"
|
||||
#import "SKComponentLayoutWrapper.h"
|
||||
|
||||
@implementation SKSubDescriptor
|
||||
{
|
||||
@implementation SKSubDescriptor {
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSObject *> *)getDataForNode:(SKComponentLayoutWrapper *)node {
|
||||
- (NSDictionary<NSString*, NSObject*>*)getDataForNode:
|
||||
(SKComponentLayoutWrapper*)node {
|
||||
return @{};
|
||||
}
|
||||
|
||||
- (NSString *)getName {
|
||||
- (NSString*)getName {
|
||||
return @"";
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#import <ComponentKit/CKComponent.h>
|
||||
#import <ComponentKit/CKFlexboxComponent.h>
|
||||
|
||||
NSString *relativeDimension(CKRelativeDimension dimension);
|
||||
NSDictionary<NSString *, NSString *> *flexboxRect(CKFlexboxSpacing spacing);
|
||||
CKRelativeDimension relativeStructDimension(NSString *dimension);
|
||||
NSDictionary<NSString *, NSString *> *ckcomponentSize(CKComponentSize size);
|
||||
NSString* relativeDimension(CKRelativeDimension dimension);
|
||||
NSDictionary<NSString*, NSString*>* flexboxRect(CKFlexboxSpacing spacing);
|
||||
CKRelativeDimension relativeStructDimension(NSString* dimension);
|
||||
NSDictionary<NSString*, NSString*>* ckcomponentSize(CKComponentSize size);
|
||||
|
||||
@@ -9,44 +9,46 @@
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
NSString *relativeDimension(CKRelativeDimension dimension) {
|
||||
switch(dimension.type()) {
|
||||
NSString* relativeDimension(CKRelativeDimension dimension) {
|
||||
switch (dimension.type()) {
|
||||
case CKRelativeDimension::Type::PERCENT:
|
||||
return [NSString stringWithFormat: @"%@%%", @(dimension.value())];
|
||||
return [NSString stringWithFormat:@"%@%%", @(dimension.value())];
|
||||
case CKRelativeDimension::Type::POINTS:
|
||||
return [NSString stringWithFormat: @"%@pt", @(dimension.value())];
|
||||
return [NSString stringWithFormat:@"%@pt", @(dimension.value())];
|
||||
default:
|
||||
return @"auto";
|
||||
}
|
||||
}
|
||||
|
||||
CKRelativeDimension relativeStructDimension(NSString *dimension) {
|
||||
CKRelativeDimension relativeStructDimension(NSString* dimension) {
|
||||
if ([dimension hasSuffix:@"%"]) {
|
||||
return CKRelativeDimension::Percent([[dimension substringToIndex:([dimension length] - 1)] integerValue]);
|
||||
return CKRelativeDimension::Percent(
|
||||
[[dimension substringToIndex:([dimension length] - 1)] integerValue]);
|
||||
}
|
||||
if ([dimension hasSuffix:@"pt"]) {
|
||||
return CKRelativeDimension::Points([[dimension substringToIndex:([dimension length] - 2)] integerValue]);
|
||||
return CKRelativeDimension::Points(
|
||||
[[dimension substringToIndex:([dimension length] - 2)] integerValue]);
|
||||
}
|
||||
return CKRelativeDimension::Auto();
|
||||
}
|
||||
|
||||
NSDictionary<NSString *, NSString *> *flexboxRect(CKFlexboxSpacing spacing) {
|
||||
NSDictionary<NSString*, NSString*>* flexboxRect(CKFlexboxSpacing spacing) {
|
||||
return @{
|
||||
@"top": relativeDimension(spacing.top.dimension()),
|
||||
@"bottom": relativeDimension(spacing.bottom.dimension()),
|
||||
@"start": relativeDimension(spacing.start.dimension()),
|
||||
@"end": relativeDimension(spacing.end.dimension())
|
||||
@"top" : relativeDimension(spacing.top.dimension()),
|
||||
@"bottom" : relativeDimension(spacing.bottom.dimension()),
|
||||
@"start" : relativeDimension(spacing.start.dimension()),
|
||||
@"end" : relativeDimension(spacing.end.dimension())
|
||||
};
|
||||
}
|
||||
|
||||
NSDictionary<NSString *, NSString *> *ckcomponentSize(CKComponentSize size) {
|
||||
NSDictionary<NSString*, NSString*>* ckcomponentSize(CKComponentSize size) {
|
||||
return @{
|
||||
@"width": relativeDimension(size.width),
|
||||
@"height": relativeDimension(size.height),
|
||||
@"minWidth": relativeDimension(size.minWidth),
|
||||
@"minHeight": relativeDimension(size.minHeight),
|
||||
@"maxWidth": relativeDimension(size.maxWidth),
|
||||
@"maxHeight": relativeDimension(size.maxHeight),
|
||||
@"width" : relativeDimension(size.width),
|
||||
@"height" : relativeDimension(size.height),
|
||||
@"minWidth" : relativeDimension(size.minWidth),
|
||||
@"minHeight" : relativeDimension(size.minHeight),
|
||||
@"maxWidth" : relativeDimension(size.maxWidth),
|
||||
@"maxHeight" : relativeDimension(size.maxHeight),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user