add macOS deps to shared libraries

Summary: Add macOS dependencies and alternative classes to the libraries that FlipperKitLayoutPlugin needs to function.

Reviewed By: priteshrnandgaonkar

Differential Revision: D27328277

fbshipit-source-id: f22d1e9f6a5415cee0bae8eaada653be5f5467b3
This commit is contained in:
Kyle Cui
2021-03-29 16:11:32 -07:00
committed by Facebook GitHub Bot
parent ec603255fe
commit 7c44d4d4f0
24 changed files with 444 additions and 5 deletions

View File

@@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#endif
@protocol FKTextSearchable<NSObject>

View File

@@ -5,14 +5,32 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#endif
@interface SKHighlightOverlay : NSObject
+ (instancetype)sharedInstance;
+ (UIColor*)overlayColor;
#if TARGET_OS_IPHONE
+ (UIColor*)overlayColor;
- (void)mountInView:(UIView*)view withFrame:(CGRect)frame;
#elif TARGET_OS_OSX
+ (NSColor*)overlayColor;
- (void)mountInView:(NSView*)view withFrame:(CGRect)frame;
#endif
- (void)unmount;
@end

View File

@@ -31,6 +31,8 @@
return self;
}
#if TARGET_OS_IPHONE
- (void)mountInView:(UIView*)view withFrame:(CGRect)frame {
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
@@ -40,10 +42,25 @@
[CATransaction commit];
}
#elif TARGET_OS_OSX
- (void)mountInView:(NSView*)view withFrame:(CGRect)frame {
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
_overlayLayer.frame = frame;
[view.layer addSublayer:_overlayLayer];
[CATransaction commit];
}
#endif
- (void)unmount {
[_overlayLayer removeFromSuperlayer];
}
#if TARGET_OS_IPHONE
+ (UIColor*)overlayColor {
return [UIColor colorWithRed:136.0 / 255.0
green:117.0 / 255.0
@@ -51,6 +68,17 @@
alpha:0.6];
}
#elif TARGET_OS_OSX
+ (NSColor*)overlayColor {
return [NSColor colorWithRed:136.0 / 255.0
green:117.0 / 255.0
blue:197.0 / 255.0
alpha:0.6];
}
#endif
@end
#endif

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <FlipperKit/SKMacros.h>
FB_LINK_REQUIRE_CATEGORY(NSCollectionView_SKInvalidation)
@interface NSCollectionView (SKInvalidation)
+ (void)enableInvalidations;
@end
#endif

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_OSX
#if FB_SONARKIT_ENABLED
#import "NSCollectionView+SKInvalidation.h"
#import "SKInvalidation.h"
#import "SKSwizzle.h"
FB_LINKABLE(NSCollectionView_SKInvalidation)
@implementation NSCollectionView (SKInvalidation)
+ (void)enableInvalidations {
}
@end
#endif // FB_SONARKIT_ENABLED
#endif

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <FlipperKit/SKMacros.h>
#import "SKObject.h"
FB_LINK_REQUIRE_CATEGORY(NSColor_SonarValueCoder)
@interface NSColor (SonarValueCoder)<SKSonarValueCoder>
@end
#endif

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_OSX
#if FB_SONARKIT_ENABLED
#import "NSColor+SKSonarValueCoder.h"
FB_LINKABLE(NSColor_SonarValueCoder)
@implementation NSColor (SonarValueCoder)
+ (instancetype)fromSonarValue:(NSNumber*)sonarValue {
NSUInteger intColor = [sonarValue integerValue];
CGFloat r, g, b, a;
b = CGFloat(intColor & 0xFF) / 255;
g = CGFloat((intColor >> 8) & 0xFF) / 255;
r = CGFloat((intColor >> 16) & 0xFF) / 255;
a = CGFloat((intColor >> 24) & 0xFF) / 255;
return [NSColor colorWithRed:r green:g blue:b alpha:a];
}
- (NSDictionary<NSString*, id<NSObject>>*)sonarValue {
CGColorSpaceRef colorSpace = CGColorGetColorSpace([self CGColor]);
CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(colorSpace);
NSUInteger red, green, blue, alpha;
switch (colorSpaceModel) {
case kCGColorSpaceModelUnknown:
case kCGColorSpaceModelRGB: {
CGFloat r, g, b, a;
[self getRed:&r green:&g blue:&b alpha:&a];
red = (NSUInteger)(r * 255) & 0xFF;
green = (NSUInteger)(g * 255) & 0xFF;
blue = (NSUInteger)(b * 255) & 0xFF;
alpha = (NSUInteger)(a * 255) & 0xFF;
} break;
case kCGColorSpaceModelMonochrome: {
CGFloat a, w;
[self getWhite:&w alpha:&a];
red = green = blue = (NSUInteger)(w * 255) & 0xFF;
alpha = (NSUInteger)(a * 255) & 0xFF;
} break;
default:
red = green = blue = alpha = 0;
}
NSUInteger intColor = (alpha << 24) | (red << 16) | (green << 8) | blue;
return
@{@"__type__" : @"color", @"__mutable__" : @NO, @"value" : @(intColor)};
}
@end
#endif // FB_SONARKIT_ENABLED
#endif

View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_OSX
#import <FlipperKit/SKMacros.h>
FB_LINK_REQUIRE_CATEGORY(NSView_SKInvalidation)
@interface NSView (SKInvalidation)
+ (void)enableInvalidation;
@end
#endif

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_OSX
#if FB_SONARKIT_ENABLED
#import <AppKit/AppKit.h>
#import <objc/runtime.h>
#import "NSView+SKInvalidation.h"
#import "SKInvalidation.h"
#import "SKSwizzle.h"
FB_LINKABLE(NSView_SKInvalidation)
@implementation NSView (SKInvalidation)
+ (void)enableInvalidation {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
swizzleMethods(
[self class], @selector(setHidden:), @selector(swizzle_setHidden:));
swizzleMethods(
[self class], @selector(addSubview:), @selector(swizzle_addSubview:));
swizzleMethods(
[self class],
@selector(removeFromSuperview),
@selector(swizzle_removeFromSuperview));
});
}
- (void)swizzle_setHidden:(BOOL)hidden {
[self swizzle_setHidden:hidden];
id<SKInvalidationDelegate> delegate =
[SKInvalidation sharedInstance].delegate;
if (delegate != nil) {
[delegate invalidateNode:self.superview];
}
}
- (void)swizzle_addSubview:(NSView*)view {
[self swizzle_addSubview:view];
[[SKInvalidation sharedInstance].delegate invalidateNode:self];
}
- (void)swizzle_removeFromSuperview {
NSView* oldSuperview = self.superview;
// Be careful that we always call the swizzled implementation
// before any early returns or mischief below!
[self swizzle_removeFromSuperview];
if (oldSuperview) {
[[SKInvalidation sharedInstance].delegate invalidateNode:oldSuperview];
}
}
@end
#endif // FB_SONARKIT_ENABLED
#endif

View File

@@ -7,12 +7,22 @@
#if FB_SONARKIT_ENABLED
#import <UIKit/UIKit.h>
#import "SKInvalidation.h"
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#import "UICollectionView+SKInvalidation.h"
#import "UIView+SKInvalidation.h"
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import "NSCollectionView+SKInvalidation.h"
#import "NSView+SKInvalidation.h"
#endif
@implementation SKInvalidation
+ (instancetype)sharedInstance {
@@ -29,6 +39,7 @@
+ (void)enableInvalidations {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
#if TARGET_OS_IPHONE
[UIView enableInvalidation];
[UICollectionView enableInvalidations];
@@ -43,6 +54,13 @@
selector:@selector(windowDidBecomeHidden:)
name:UIWindowDidBecomeHiddenNotification
object:nil];
#elif TARGET_OS_OSX
[NSView enableInvalidation];
[NSCollectionView enableInvalidations];
#endif
});
}

View File

@@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#endif
#import <FlipperKitLayoutHelpers/FlipperKitLayoutDescriptorMapperProtocol.h>
#import "SKNamed.h"

View File

@@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#endif
@protocol SKSonarValueCoder
@@ -20,7 +27,11 @@ class SKObject {
SKObject(CGRect rect);
SKObject(CGSize size);
SKObject(CGPoint point);
#if TARGET_OS_IPHONE
SKObject(UIEdgeInsets insets);
#elif TARGET_OS_OSX
SKObject(NSEdgeInsets insets);
#endif
SKObject(CGAffineTransform transform);
SKObject(id<SKSonarValueCoder> value);
SKObject(id value);
@@ -38,7 +49,11 @@ class SKMutableObject : public SKObject {
SKMutableObject(CGRect rect) : SKObject(rect) {}
SKMutableObject(CGSize size) : SKObject(size){};
SKMutableObject(CGPoint point) : SKObject(point){};
#if TARGET_OS_IPHONE
SKMutableObject(UIEdgeInsets insets) : SKObject(insets){};
#elif TARGET_OS_OSX
SKMutableObject(NSEdgeInsets insets) : SKObject(insets){};
#endif
SKMutableObject(CGAffineTransform transform) : SKObject(transform){};
SKMutableObject(id<SKSonarValueCoder> value) : SKObject(value){};
SKMutableObject(id value) : SKObject(value){};

View File

@@ -21,6 +21,8 @@ SKObject::SKObject(CGPoint point) {
_actual = @{@"x" : @(point.x), @"y" : @(point.y)};
}
#if TARGET_OS_IPHONE
SKObject::SKObject(UIEdgeInsets insets) {
_actual = @{
@"top" : @(insets.top),
@@ -30,6 +32,19 @@ SKObject::SKObject(UIEdgeInsets insets) {
};
}
#elif TARGET_OS_OSX
SKObject::SKObject(NSEdgeInsets insets) {
_actual = @{
@"top" : @(insets.top),
@"bottom" : @(insets.bottom),
@"left" : @(insets.left),
@"right" : @(insets.right),
};
}
#endif
SKObject::SKObject(CGAffineTransform transform) {
_actual = @{
@"a" : @(transform.a),

View File

@@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#endif
typedef void (^SKTapReceiver)(CGPoint touchPoint);

View File

@@ -7,7 +7,16 @@
#import "SKTapListener.h"
#if TARGET_OS_IPHONE
@interface SKTapListenerImpl
: NSObject<SKTapListener, UIGestureRecognizerDelegate>
#elif TARGET_OS_OSX
@interface SKTapListenerImpl
: NSObject<SKTapListener, NSGestureRecognizerDelegate>
#endif
@end

View File

@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#include <TargetConditionals.h>
#if FB_SONARKIT_ENABLED
#import "SKTapListenerImpl.h"
@@ -15,9 +16,14 @@
@implementation SKTapListenerImpl {
NSMutableArray<SKTapReceiver>* _receiversWaitingForInput;
UITapGestureRecognizer* _gestureRecognizer;
#if TARGET_OS_IPHONE
UITapGestureRecognizer* _gestureRecognizer;
SKHiddenWindow* _overlayWindow;
#elif TARGET_OS_OSX
NSClickGestureRecognizer* _gestureRecognizer;
SKHiddenWindow* _overlayView;
#endif
}
@synthesize isMounted = _isMounted;
@@ -26,6 +32,7 @@
if (self = [super init]) {
_receiversWaitingForInput = [NSMutableArray new];
#if TARGET_OS_IPHONE
_gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:nil];
_gestureRecognizer.delegate = self;
@@ -38,6 +45,21 @@
_overlayWindow.backgroundColor = [SKHighlightOverlay overlayColor];
[_overlayWindow addGestureRecognizer:_gestureRecognizer];
#elif TARGET_OS_OSX
_gestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self
action:nil];
_gestureRecognizer.delegate = self;
_isMounted = NO;
_overlayView = [SKHiddenWindow new];
_overlayView.hidden = YES;
_overlayView.window.level = NSStatusWindowLevel;
_overlayView.window.backgroundColor = [SKHighlightOverlay overlayColor];
[_overlayView addGestureRecognizer:_gestureRecognizer];
#endif
}
return self;
@@ -48,10 +70,20 @@
return;
}
#if TARGET_OS_IPHONE
[_overlayWindow setFrame:frame];
[_overlayWindow makeKeyAndVisible];
_overlayWindow.hidden = NO;
[[UIApplication sharedApplication].delegate.window addSubview:_overlayWindow];
#elif TARGET_OS_OSX
_overlayView.hidden = NO;
[[NSApplication sharedApplication].mainWindow.contentView
addSubview:_overlayView];
_overlayView.frame = frame;
_overlayView.needsDisplay = YES;
#endif
_isMounted = YES;
}
@@ -61,8 +93,15 @@
}
[_receiversWaitingForInput removeAllObjects];
#if TARGET_OS_IPHONE
[_overlayWindow removeFromSuperview];
_overlayWindow.hidden = YES;
#elif TARGET_OS_OSX
[_overlayView removeFromSuperview];
_overlayView.hidden = YES;
#endif
_isMounted = NO;
}
@@ -70,6 +109,7 @@
[_receiversWaitingForInput addObject:receiver];
}
#if TARGET_OS_IPHONE
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
shouldReceiveTouch:(UITouch*)touch {
if ([_receiversWaitingForInput count] == 0) {
@@ -87,6 +127,25 @@
return NO;
}
#elif TARGET_OS_OSX
- (BOOL)gestureRecognizer:(NSGestureRecognizer*)gestureRecognizer
shouldReceiveTouch:(NSTouch*)touch {
if ([_receiversWaitingForInput count] == 0) {
return YES;
}
if (@available(macOS 10.12.2, *)) {
CGPoint touchPoint = [touch locationInView:_overlayView];
for (SKTapReceiver recv in _receiversWaitingForInput) {
recv(touchPoint);
}
}
[_receiversWaitingForInput removeAllObjects];
return NO;
}
#endif
@end
#endif

View File

@@ -5,8 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import <FlipperKitLayoutHelpers/FlipperKitLayoutDescriptorMapperProtocol.h>
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#endif
#import <FlipperKitLayoutHelpers/FlipperKitLayoutDescriptorMapperProtocol.h>
typedef void (^SKTouchFinishDelegate)(id<NSObject> currentNode);
typedef void (^SKProcessFinishDelegate)(NSDictionary* tree);

View File

@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#import <FlipperKit/SKMacros.h>
@@ -15,3 +17,5 @@ FB_LINK_REQUIRE_CATEGORY(UICollectionView_SKInvalidation)
+ (void)enableInvalidations;
@end
#endif

View File

@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_IPHONE
#if FB_SONARKIT_ENABLED
#import "UICollectionView+SKInvalidation.h"
@@ -36,4 +37,5 @@ FB_LINKABLE(UICollectionView_SKInvalidation)
@end
#endif // FB_SONARKIT_ENABLED
#endif

View File

@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#import <FlipperKit/SKMacros.h>
@@ -15,3 +17,5 @@ FB_LINK_REQUIRE_CATEGORY(UIColor_SonarValueCoder)
@interface UIColor (SonarValueCoder)<SKSonarValueCoder>
@end
#endif

View File

@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_IPHONE
#if FB_SONARKIT_ENABLED
#import "UIColor+SKSonarValueCoder.h"
@@ -62,4 +63,5 @@ FB_LINKABLE(UIColor_SonarValueCoder)
@end
#endif // FB_SONARKIT_ENABLED
#endif

View File

@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_IPHONE
#import <FlipperKit/SKMacros.h>
FB_LINK_REQUIRE_CATEGORY(UIView_SKInvalidation)
@@ -13,3 +15,5 @@ FB_LINK_REQUIRE_CATEGORY(UIView_SKInvalidation)
+ (void)enableInvalidation;
@end
#endif

View File

@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#if TARGET_OS_IPHONE
#if FB_SONARKIT_ENABLED
#import <UIKit/UIKit.h>
@@ -115,4 +116,5 @@ FB_LINKABLE(UIView_SKInvalidation)
@end
#endif // FB_SONARKIT_ENABLED
#endif

View File

@@ -5,7 +5,23 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#endif
#if TARGET_OS_IPHONE
@interface SKHiddenWindow : UIWindow
@end
#elif TARGET_OS_OSX
@interface SKHiddenWindow : NSView
@end
#endif