Summary: This is a prototype for view preview within Flipper for iOS (Android next). If enabled, a preview of the selected element is rendered in the attribute inspector. Changelog: Add view preview/snapshot for the Layout plugin on iOS. Reviewed By: antonk52 Differential Revision: D34990372 fbshipit-source-id: 1984514fbf59041ad236008a8db10569c5fc5f94
77 lines
2.2 KiB
Objective-C
77 lines
2.2 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#if FB_SONARKIT_ENABLED
|
|
|
|
#import "SKApplicationDescriptor.h"
|
|
|
|
#import <FlipperKitLayoutHelpers/SKHiddenWindow.h>
|
|
#import <objc/runtime.h>
|
|
|
|
@implementation SKApplicationDescriptor
|
|
|
|
- (NSString*)identifierForNode:(UIApplication*)node {
|
|
return [NSString stringWithFormat:@"%p", node];
|
|
}
|
|
|
|
- (NSUInteger)childCountForNode:(UIApplication*)node {
|
|
return [[self visibleChildrenForNode:node] count];
|
|
}
|
|
|
|
- (id)childForNode:(UIApplication*)node atIndex:(NSUInteger)index {
|
|
return [self visibleChildrenForNode:node][index];
|
|
}
|
|
|
|
- (void)setHighlighted:(BOOL)highlighted forNode:(UIApplication*)node {
|
|
SKNodeDescriptor* windowDescriptor =
|
|
[self descriptorForClass:[UIWindow class]];
|
|
[windowDescriptor setHighlighted:highlighted forNode:[node keyWindow]];
|
|
}
|
|
|
|
- (UIImage*)getSnapshot:(BOOL)includeChildren forNode:(UIApplication*)node {
|
|
SKNodeDescriptor* descriptor = [self descriptorForClass:[UIView class]];
|
|
return [descriptor getSnapshot:includeChildren forNode:[node keyWindow]];
|
|
}
|
|
|
|
- (void)hitTest:(SKTouch*)touch forNode:(UIApplication*)node {
|
|
bool finish = true;
|
|
for (NSInteger index = [self childCountForNode:node] - 1; index >= 0;
|
|
index--) {
|
|
UIWindow* child = [self childForNode:node atIndex:index];
|
|
if (child.isHidden || child.alpha <= 0) {
|
|
continue;
|
|
}
|
|
|
|
if ([touch containedIn:child.frame]) {
|
|
[touch continueWithChildIndex:index withOffset:child.frame.origin];
|
|
finish = false;
|
|
}
|
|
}
|
|
if (finish) {
|
|
[touch finish];
|
|
}
|
|
}
|
|
|
|
- (NSArray<UIWindow*>*)visibleChildrenForNode:(UIApplication*)node {
|
|
NSMutableArray<UIWindow*>* children = [NSMutableArray new];
|
|
for (UIWindow* window in node.windows) {
|
|
if ([window isKindOfClass:[SKHiddenWindow class]] ||
|
|
[window
|
|
isKindOfClass:objc_lookUpClass("FBAccessibilityOverlayWindow")] ||
|
|
[window isKindOfClass:objc_lookUpClass("UITextEffectsWindow")] ||
|
|
[window isKindOfClass:objc_lookUpClass("FBStatusBarTrackingWindow")]) {
|
|
continue;
|
|
}
|
|
[children addObject:window];
|
|
}
|
|
return children;
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|