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

Commit 28b03e3

Browse files
[tvOS] Expose UIFocusEnvironment Protocol methods to ASDisplayNode
1 parent cc4f604 commit 28b03e3

4 files changed

Lines changed: 114 additions & 0 deletions

File tree

AsyncDisplayKit/ASDisplayNode.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ NS_ASSUME_NONNULL_END
660660
- (BOOL)isFirstResponder;
661661
- (BOOL)canPerformAction:(nonnull SEL)action withSender:(nonnull id)sender;
662662

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+
663673
// Accessibility support
664674
@property (atomic, assign) BOOL isAccessibilityElement;
665675
@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/Details/_ASDisplayView.mm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,36 @@ - (id)forwardingTargetForSelector:(SEL)aSelector
331331
return _node;
332332
}
333333

334+
#if TARGET_OS_TV
335+
#pragma mark - tvOS
336+
- (BOOL)canBecomeFocused
337+
{
338+
return [_node canBecomeFocused];
339+
}
340+
341+
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
342+
{
343+
return [_node didUpdateFocusInContext:context withAnimationCoordinator:coordinator];
344+
}
345+
346+
- (void)setNeedsFocusUpdate
347+
{
348+
return [_node setNeedsFocusUpdate];
349+
}
350+
351+
- (void)updateFocusIfNeeded
352+
{
353+
return [_node updateFocusIfNeeded];
354+
}
355+
356+
- (BOOL)shouldUpdateFocusInContext:(UIFocusUpdateContext *)context
357+
{
358+
return [_node shouldUpdateFocusInContext:context];
359+
}
360+
361+
- (UIView *)preferredFocusedView
362+
{
363+
return [_node preferredFocusedView];
364+
}
365+
#endif
334366
@end

AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,46 @@ - (BOOL)canResignFirstResponder
8181
return YES;
8282
}
8383

84+
#if TARGET_OS_TV
85+
// Focus Engine
86+
- (BOOL)canBecomeFocused
87+
{
88+
return YES;
89+
}
90+
91+
- (void)setNeedsFocusUpdate
92+
{
93+
ASDisplayNodeAssertMainThread();
94+
[_view setNeedsFocusUpdate];
95+
}
96+
97+
- (void)updateFocusIfNeeded
98+
{
99+
ASDisplayNodeAssertMainThread();
100+
[_view updateFocusIfNeeded];
101+
}
102+
103+
- (BOOL)shouldUpdateFocusInContext:(UIFocusUpdateContext *)context
104+
{
105+
return YES;
106+
}
107+
108+
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
109+
{
110+
111+
}
112+
113+
- (UIView *)preferredFocusedView
114+
{
115+
if (self.nodeLoaded) {
116+
return _view;
117+
}
118+
else {
119+
return nil;
120+
}
121+
}
122+
#endif
123+
84124
- (BOOL)isFirstResponder
85125
{
86126
ASDisplayNodeAssertMainThread();

0 commit comments

Comments
 (0)