Skip to content

Commit

Permalink
Added ifdefs for tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
m4p committed Jun 29, 2021
1 parent 33aa95d commit 5930550
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ build/
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/carthage,cocoapods,fastlane,macos,swiftpackagemanager,xcode
.swiftpm
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "LookinServer",
platforms: [
.iOS(.v9),
.iOS(.v9),.tvOS(.v14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
5 changes: 5 additions & 0 deletions Src/Server/Inspect/LKS_LocalInspectViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,12 @@ - (UIView *)_targetViewAtPoint:(CGPoint)point {
static dispatch_once_t onceToken;
static NSArray<Class> *classes = nil;
dispatch_once(&onceToken,^{
#if TARGET_OS_TV
NSMutableArray<Class> *array = @[[UILabel class], [UIProgressView class], [UIActivityIndicatorView class], [UITextView class], [UITextField class], [UIVisualEffectView class]].mutableCopy;
#else
NSMutableArray<Class> *array = @[[UILabel class], [UIProgressView class], [UIActivityIndicatorView class], [UITextView class], [UITextField class], [UISlider class], [UISwitch class], [UIVisualEffectView class]].mutableCopy;
#endif

NSArray<NSString *> *custom = [LookinHierarchyInfo collapsedClassList];
if (custom.count) {
NSArray<Class> *customClasses = [custom lookin_map:^id(NSUInteger idx, NSString *value) {
Expand Down
9 changes: 9 additions & 0 deletions Src/Server/Others/LKS_EventHandlerMaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,22 @@ + (NSString *)_inheritedRecognizerNameForRecognizer:(UIGestureRecognizer *)recog
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// 注意这里 UIScreenEdgePanGestureRecognizer 在 UIPanGestureRecognizer 前面,因为 UIScreenEdgePanGestureRecognizer 继承于 UIPanGestureRecognizer

#if TARGET_OS_TV
baseRecognizers = @[[UILongPressGestureRecognizer class],
[UIPanGestureRecognizer class],
[UISwipeGestureRecognizer class],
[UITapGestureRecognizer class]];
#else
baseRecognizers = @[[UILongPressGestureRecognizer class],
[UIScreenEdgePanGestureRecognizer class],
[UIPanGestureRecognizer class],
[UISwipeGestureRecognizer class],
[UIRotationGestureRecognizer class],
[UIPinchGestureRecognizer class],
[UITapGestureRecognizer class]];
#endif

});

__block NSString *result = @"UIGestureRecognizer";
Expand Down
8 changes: 8 additions & 0 deletions Src/Server/Others/LKS_ExportManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ - (void)layoutSubviews {

@interface LKS_ExportManager ()

#if TARGET_OS_TV
#else
@property(nonatomic, strong) UIDocumentInteractionController *documentController;
#endif


@property(nonatomic, strong) LKS_ExportManagerMaskView *maskView;

Expand Down Expand Up @@ -157,6 +161,8 @@ - (void)exportAndShare {

[self.maskView removeFromSuperview];

#if TARGET_OS_TV
#else
if (!self.documentController) {
self.documentController = [UIDocumentInteractionController new];
}
Expand All @@ -166,6 +172,8 @@ - (void)exportAndShare {
} else {
[self.documentController presentOpenInMenuFromRect:visibleVc.view.bounds inView:visibleVc.view animated:YES];
}
#endif


[[NSNotificationCenter defaultCenter] postNotificationName:@"Lookin_DidFinishExport" object:nil];

Expand Down
3 changes: 3 additions & 0 deletions Src/Server/Perspective/LKS_PerspectiveHierarchyView.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ - (instancetype)initWithDataSource:(LKS_PerspectiveDataSource *)dataSource {

self.tableView = [[UITableView alloc] init];
self.tableView.backgroundColor = [UIColor clearColor];
#if TARGET_OS_TV
#else
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
#endif
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.scrollView addSubview:self.tableView];
Expand Down
15 changes: 14 additions & 1 deletion Src/Server/Perspective/LKS_PerspectiveViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,28 @@ - (void)viewDidLoad {
[self.view addGestureRecognizer:self.tapGestureRecognizer];

self.hierarchyDragGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleHierarchyDragGestureRecognizer:)];
#if TARGET_OS_TV
#else
self.hierarchyDragGestureRecognizer.maximumNumberOfTouches = 1;
#endif
self.hierarchyDragGestureRecognizer.delegate = self;
[self.view addGestureRecognizer:self.hierarchyDragGestureRecognizer];

self.rotationGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRotationGestureRecognizer:)];
#if TARGET_OS_TV
#else
self.rotationGestureRecognizer.maximumNumberOfTouches = 1;
#endif
self.rotationGestureRecognizer.delegate = self;
[self.rotationGestureRecognizer requireGestureRecognizerToFail:self.hierarchyDragGestureRecognizer];
[self.view addGestureRecognizer:self.rotationGestureRecognizer];

self.twoFingersGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTwoFingersGestureRecognizer:)];
#if TARGET_OS_TV
#else
self.twoFingersGestureRecognizer.minimumNumberOfTouches = 2;
self.twoFingersGestureRecognizer.maximumNumberOfTouches = 2;
#endif
[self.view addGestureRecognizer:self.twoFingersGestureRecognizer];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -392,8 +401,12 @@ - (void)_startEnterAnim {
self.closeButton.alpha = 0;
self.dimensionButtonsView.alpha = 0;
self.layoutButtonsView.alpha = 0;

#if TARGET_OS_TV
BOOL isLandScape = YES;
#else
BOOL isLandScape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
#endif

if (isLandScape) {
self.layoutType = LKS_PerspectiveLayoutHorizontal;
self.previewAndHierarchySepPosition = 0;
Expand Down
4 changes: 4 additions & 0 deletions Src/Shared/LookinAppInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ + (NSString *)appName {
}

+ (UIImage *)appIcon {
#if TARGET_OS_TV
return nil;
#else
NSString *imageName = [[[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectForKey:@"CFBundlePrimaryIcon"] objectForKey:@"CFBundleIconFiles"] lastObject];
if (!imageName.length) {
// 正常情况下拿到的 name 可能比如 “AppIcon60x60”。但某些情况可能为 nil,此时直接 return 否则 [UIImage imageNamed:nil] 可能导致 console 报 "CUICatalog: Invalid asset name supplied: '(null)'" 的错误信息
return nil;
}
return [UIImage imageNamed:imageName];
#endif
}

+ (UIImage *)screenshotImage {
Expand Down

0 comments on commit 5930550

Please sign in to comment.