Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit ccbf38c

Browse files
committed
Merge pull request #1096 from facebook/pr/1059
[tvOS] Initial changes to support building AsyncDisplayKit for tvOS.
2 parents ca27702 + fe572c2 commit ccbf38c

15 files changed

Lines changed: 167 additions & 23 deletions

AsyncDisplayKit.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ Pod::Spec.new do |spec|
4747
}
4848

4949
spec.ios.deployment_target = '7.0'
50+
spec.tvos.deployment_target = '9.0'
5051
end

AsyncDisplayKit/ASDisplayNode.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ NS_ASSUME_NONNULL_END
641641
@property (atomic, assign) UIViewContentMode contentMode; // default=UIViewContentModeScaleToFill
642642

643643
@property (atomic, assign, getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default=YES (NO for layer-backed nodes)
644+
#if TARGET_OS_IOS
644645
@property (atomic, assign, getter=isExclusiveTouch) BOOL exclusiveTouch; // default=NO
646+
#endif
645647
@property (atomic, assign, nullable) CGColorRef shadowColor; // default=opaque rgb black
646648
@property (atomic, assign) CGFloat shadowOpacity; // default=0.0
647649
@property (atomic, assign) CGSize shadowOffset; // default=(0, -3)
@@ -658,6 +660,16 @@ NS_ASSUME_NONNULL_END
658660
- (BOOL)isFirstResponder;
659661
- (BOOL)canPerformAction:(nonnull SEL)action withSender:(nonnull id)sender;
660662

663+
#if TARGET_OS_TV
664+
//Focus Engine
665+
- (void)setNeedsFocusUpdate;
666+
- (BOOL)canBecomeFocused;
667+
- (void)updateFocusIfNeeded;
668+
- (void)didUpdateFocusInContext:(nonnull UIFocusUpdateContext *)context withAnimationCoordinator:(nonnull UIFocusAnimationCoordinator *)coordinator;
669+
- (BOOL)shouldUpdateFocusInContext:(nonnull UIFocusUpdateContext *)context;
670+
- (nullable UIView *)preferredFocusedView;
671+
#endif
672+
661673
// Accessibility support
662674
@property (atomic, assign) BOOL isAccessibilityElement;
663675
@property (nullable, atomic, copy) NSString *accessibilityLabel;

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,38 @@ - (void)_enqueueAsyncSizingWithSentinel:(ASSentinel *)sentinel completion:(void(
23122312
return self;
23132313
}
23142314

2315+
#if TARGET_OS_TV
2316+
#pragma mark - UIFocusEnvironment Protocol (tvOS)
2317+
2318+
- (void)setNeedsFocusUpdate
2319+
{
2320+
2321+
}
2322+
2323+
- (void)updateFocusIfNeeded
2324+
{
2325+
2326+
}
2327+
2328+
- (BOOL)shouldUpdateFocusInContext:(UIFocusUpdateContext *)context
2329+
{
2330+
return YES;
2331+
}
2332+
2333+
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
2334+
{
2335+
2336+
}
2337+
2338+
- (UIView *)preferredFocusedView
2339+
{
2340+
if (self.nodeLoaded) {
2341+
return self.view;
2342+
} else {
2343+
return nil;
2344+
}
2345+
}
2346+
#endif
23152347
@end
23162348

23172349
@implementation ASDisplayNode (Debugging)

AsyncDisplayKit/ASEditableTextNode.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ - (void)didLoad
163163
_textKitComponents.textView = self.textView;
164164
//_textKitComponents.textView = NO; // Unfortunately there's a bug here with iOS 7 DP5 that causes the text-view to only be one line high when scrollEnabled is NO. rdar://14729288
165165
_textKitComponents.textView.delegate = self;
166+
#if TARGET_OS_IOS
166167
_textKitComponents.textView.editable = YES;
168+
#endif
167169
_textKitComponents.textView.typingAttributes = _typingAttributes;
168170
_textKitComponents.textView.returnKeyType = _returnKeyType;
169171
_textKitComponents.textView.accessibilityHint = _placeholderTextKitComponents.textStorage.string;

AsyncDisplayKit/ASMapNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#import <AsyncDisplayKit/ASImageNode.h>
10+
#if TARGET_OS_IOS
1011
#import <MapKit/MapKit.h>
1112

1213
NS_ASSUME_NONNULL_BEGIN
@@ -48,3 +49,5 @@ NS_ASSUME_NONNULL_BEGIN
4849
@end
4950

5051
NS_ASSUME_NONNULL_END
52+
53+
#endif

AsyncDisplayKit/ASMapNode.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9+
#if TARGET_OS_IOS
910
#import "ASMapNode.h"
1011
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
1112
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
@@ -246,4 +247,5 @@ - (void)layout
246247
}
247248
}
248249
}
249-
@end
250+
@end
251+
#endif

AsyncDisplayKit/ASMultiplexImageNode.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9+
#if TARGET_OS_IOS
10+
911
#import <AsyncDisplayKit/ASImageNode.h>
1012
#import <AsyncDisplayKit/ASImageProtocols.h>
11-
1213
#import <Photos/Photos.h>
1314

1415
NS_ASSUME_NONNULL_BEGIN
@@ -116,13 +117,14 @@ typedef NS_ENUM(NSUInteger, ASMultiplexImageNodeErrorCode) {
116117
*/
117118
@property (nullable, nonatomic, readonly) ASImageIdentifier displayedImageIdentifier;
118119

120+
#if TARGET_OS_IOS
119121
/**
120122
* @abstract The image manager that this image node should use when requesting images from the Photos framework. If this is `nil` (the default), then `PHImageManager.defaultManager` is used.
121123
122124
* @see `+[NSURL URLWithAssetLocalIdentifier:targetSize:contentMode:options:]` below.
123125
*/
124126
@property (nonatomic, strong) PHImageManager *imageManager;
125-
127+
#endif
126128
@end
127129

128130

@@ -229,6 +231,7 @@ didFinishDownloadingImageWithIdentifier:(ASImageIdentifier)imageIdentifier
229231
*/
230232
- (nullable NSURL *)multiplexImageNode:(ASMultiplexImageNode *)imageNode URLForImageIdentifier:(ASImageIdentifier)imageIdentifier;
231233

234+
#if TARGET_OS_IOS
232235
/**
233236
* @abstract A PHAsset for the specific asset local identifier
234237
* @param imageNode The sender.
@@ -240,11 +243,11 @@ didFinishDownloadingImageWithIdentifier:(ASImageIdentifier)imageIdentifier
240243
* @return A PHAsset corresponding to `assetLocalIdentifier`, or nil if none is available.
241244
*/
242245
- (nullable PHAsset *)multiplexImageNode:(ASMultiplexImageNode *)imageNode assetForLocalIdentifier:(NSString *)assetLocalIdentifier;
243-
246+
#endif
244247
@end
245248

246249
#pragma mark -
247-
250+
#if TARGET_OS_IOS
248251
@interface NSURL (ASPhotosFrameworkURLs)
249252

250253
/**
@@ -261,5 +264,8 @@ didFinishDownloadingImageWithIdentifier:(ASImageIdentifier)imageIdentifier
261264
options:(PHImageRequestOptions *)options;
262265

263266
@end
267+
#endif
268+
269+
NS_ASSUME_NONNULL_END
264270

265-
NS_ASSUME_NONNULL_END
271+
#endif

AsyncDisplayKit/ASMultiplexImageNode.mm

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9-
#import "ASMultiplexImageNode.h"
9+
#if TARGET_OS_IOS
1010

11+
#import "ASMultiplexImageNode.h"
1112
#import <AssetsLibrary/AssetsLibrary.h>
1213

1314
#import <Photos/Photos.h>
14-
1515
#import <libkern/OSAtomic.h>
1616

1717
#import "ASAvailability.h"
@@ -112,6 +112,7 @@ - (void)_loadNextImage;
112112
*/
113113
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock;
114114

115+
#if TARGET_OS_IOS
115116
/**
116117
@abstract Loads the image corresponding to the given assetURL from the device's Assets Library.
117118
@param imageIdentifier The identifier for the image to be loaded. May not be nil.
@@ -131,7 +132,7 @@ - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL com
131132
@param error An error describing why the load failed, if it failed; nil otherwise.
132133
*/
133134
- (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock;
134-
135+
#endif
135136
/**
136137
@abstract Downloads the image corresponding to the given imageIdentifier from the given URL.
137138
@param imageIdentifier The identifier for the image to be downloaded. May not be nil.
@@ -262,7 +263,9 @@ - (void)setDataSource:(id <ASMultiplexImageNodeDataSource>)dataSource
262263
_dataSource = dataSource;
263264
_dataSourceFlags.image = [_dataSource respondsToSelector:@selector(multiplexImageNode:imageForImageIdentifier:)];
264265
_dataSourceFlags.URL = [_dataSource respondsToSelector:@selector(multiplexImageNode:URLForImageIdentifier:)];
266+
#if TARGET_OS_IOS
265267
_dataSourceFlags.asset = [_dataSource respondsToSelector:@selector(multiplexImageNode:assetForLocalIdentifier:)];
268+
#endif
266269
}
267270

268271
#pragma mark -
@@ -455,6 +458,7 @@ - (void)_loadNextImage
455458
return;
456459
}
457460

461+
#if TARGET_OS_IOS
458462
// If it's an assets-library URL, we need to fetch it from the assets library.
459463
if ([[nextImageURL scheme] isEqualToString:kAssetsLibraryURLScheme]) {
460464
// Load the asset.
@@ -470,6 +474,7 @@ - (void)_loadNextImage
470474
finishedLoadingBlock(image, nextImageIdentifier, error);
471475
}];
472476
}
477+
#endif
473478
else // Otherwise, it's a web URL that we can download.
474479
{
475480
// First, check the cache.
@@ -499,7 +504,7 @@ - (void)_loadNextImage
499504
}];
500505
}
501506
}
502-
507+
#if TARGET_OS_IOS
503508
- (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock
504509
{
505510
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
@@ -609,7 +614,7 @@ - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identif
609614
_phImageRequestOperation = newImageRequestOp;
610615
[phImageRequestQueue addOperation:newImageRequestOp];
611616
}
612-
617+
#endif
613618
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock
614619
{
615620
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
@@ -708,7 +713,7 @@ - (BOOL)_shouldClearFetchedImageData {
708713
}
709714

710715
@end
711-
716+
#if TARGET_OS_IOS
712717
@implementation NSURL (ASPhotosFrameworkURLs)
713718

714719
+ (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHImageRequestOptions *)options
@@ -720,4 +725,7 @@ + (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSi
720725
return request.url;
721726
}
722727

723-
@end
728+
@end
729+
#endif
730+
731+
#endif

AsyncDisplayKit/ASPagerNode.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ - (void)didLoad
4848
[super didLoad];
4949

5050
ASCollectionView *cv = self.view;
51-
51+
#if TARGET_OS_IOS
5252
cv.pagingEnabled = YES;
53+
cv.scrollsToTop = NO;
54+
#endif
5355
cv.allowsSelection = NO;
5456
cv.showsVerticalScrollIndicator = NO;
5557
cv.showsHorizontalScrollIndicator = NO;
56-
cv.scrollsToTop = NO;
5758

5859
// Zeroing contentInset is important, as UIKit will set the top inset for the navigation bar even though
5960
// our view is only horizontally scrollable. This causes UICollectionViewFlowLayout to log a warning.

AsyncDisplayKit/ASTableViewProtocols.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ NS_ASSUME_NONNULL_BEGIN
7373

7474
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
7575
- (nullable NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath;
76+
#if TARGET_OS_IOS
7677
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath;
77-
78+
#endif
7879
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;
7980

8081
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;

0 commit comments

Comments
 (0)