From e2fa2f8192ddce3f6ab6dfe871d5d52756eadbc1 Mon Sep 17 00:00:00 2001 From: Aaron Schubert Date: Thu, 21 Apr 2016 09:23:47 +0100 Subject: [PATCH] [tvOS] Address comments on previous PR. --- AsyncDisplayKit/ASControlNode.mm | 3 ++- AsyncDisplayKit/ASImageNode+tvOS.h | 2 +- AsyncDisplayKit/ASImageNode+tvOS.m | 35 ++++++++++++++++++------------ AsyncDisplayKit/ASImageNode.h | 9 ++++++++ AsyncDisplayKit/ASImageNode.mm | 5 ----- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/AsyncDisplayKit/ASControlNode.mm b/AsyncDisplayKit/ASControlNode.mm index 7d8f54a997..e81a7805df 100644 --- a/AsyncDisplayKit/ASControlNode.mm +++ b/AsyncDisplayKit/ASControlNode.mm @@ -96,7 +96,8 @@ static BOOL _enableHitTestDebug = NO; #if TARGET_OS_TV - (void)didLoad { - //On tvOS all control views, such as buttons, interact with the focus system even if they don't have a target set on them. Here we add our own internal tap gesture to handle this behaviour. + // On tvOS all controls, such as buttons, interact with the focus system even if they don't have a target set on them. + // Here we add our own internal tap gesture to handle this behaviour. self.userInteractionEnabled = YES; UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pressDown)]; tapGestureRec.allowedPressTypes = @[@(UIPressTypeSelect)]; diff --git a/AsyncDisplayKit/ASImageNode+tvOS.h b/AsyncDisplayKit/ASImageNode+tvOS.h index adc4127bd0..9a06a09242 100644 --- a/AsyncDisplayKit/ASImageNode+tvOS.h +++ b/AsyncDisplayKit/ASImageNode+tvOS.h @@ -10,6 +10,6 @@ #import @interface ASImageNode (tvOS) -@property (nonatomic) BOOL isDefaultState; @end #endif + diff --git a/AsyncDisplayKit/ASImageNode+tvOS.m b/AsyncDisplayKit/ASImageNode+tvOS.m index b7055f07fc..29181d0604 100644 --- a/AsyncDisplayKit/ASImageNode+tvOS.m +++ b/AsyncDisplayKit/ASImageNode+tvOS.m @@ -8,13 +8,14 @@ #if TARGET_OS_TV #import "ASImageNode+tvOS.h" +#import @implementation ASImageNode (tvOS) - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; - self.isDefaultState = NO; + self.isDefaultFocusAppearance = NO; UIView *view = [self getView]; CALayer *layer = view.layer; @@ -47,16 +48,27 @@ [CATransaction commit]; } -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ [super touchesMoved:touches withEvent:event]; - if (!self.isDefaultState) { + // TODO: Clean up, and improve visuals. + + if (!self.isDefaultFocusAppearance) { + // This view may correspond to either self.view + // or our superview if we are in a ASCellNode UIView *view = [self getView]; UITouch *touch = [touches anyObject]; // Get the specific point that was touched - // This is quite messy in it's current state so is not ready for production. The reason it is here is for others to contribute and to make it clear what is occuring. - // TODO: Clean up, and improve visuals. + + // This is quite messy in it's current state so is not ready for production. + // The reason it is here is for others to contribute and to make it clear what is occuring. + + // We get the touch location in self.view because + // we are operating in that coordinate system. + // BUT we apply our transforms to *view since we want to apply + // the transforms to the root view (L: 107) CGPoint point = [touch locationInView:self.view]; float pitch = 0; float yaw = 0; @@ -87,8 +99,8 @@ } } - CATransform3D pitchTransform = CATransform3DMakeRotation([self degressToRadians:pitch],1.0,0.0,0.0); - CATransform3D yawTransform = CATransform3DMakeRotation([self degressToRadians:yaw],0.0,1.0,0.0); + CATransform3D pitchTransform = CATransform3DMakeRotation(GLKMathDegreesToRadians(pitch),1.0,0.0,0.0); + CATransform3D yawTransform = CATransform3DMakeRotation(GLKMathDegreesToRadians(yaw),0.0,1.0,0.0); CATransform3D transform = CATransform3DConcat(pitchTransform, yawTransform); CATransform3D scaleAndTransform = CATransform3DConcat(transform, CATransform3DMakeAffineTransform(CGAffineTransformScale(CGAffineTransformIdentity, 1.25, 1.25))); @@ -109,7 +121,7 @@ - (void)finishTouches { - if (!self.isDefaultState) { + if (!self.isDefaultFocusAppearance) { UIView *view = [self getView]; CALayer *layer = view.layer; @@ -157,7 +169,7 @@ layer.shadowPath = nil; [layer removeAnimationForKey:@"shadowOffset"]; [layer removeAnimationForKey:@"shadowOpacity"]; - self.isDefaultState = YES; + self.isDefaultFocusAppearance = YES; } - (UIView *)getView @@ -170,10 +182,5 @@ return view; } -- (float)degressToRadians:(float)value -{ - return value * M_PI / 180; -} - @end #endif diff --git a/AsyncDisplayKit/ASImageNode.h b/AsyncDisplayKit/ASImageNode.h index 8ce01b6397..c71e4bcf5d 100644 --- a/AsyncDisplayKit/ASImageNode.h +++ b/AsyncDisplayKit/ASImageNode.h @@ -110,6 +110,15 @@ typedef UIImage * _Nullable (^asimagenode_modification_block_t)(UIImage *image); */ - (void)setNeedsDisplayWithCompletion:(void (^ _Nullable)(BOOL canceled))displayCompletionBlock; +#if TARGET_OS_TV +/** + * A bool to track if the current appearance of the node + * is the default focus appearance. + * Exposed here so the category methods can set it. + */ +@property (nonatomic, assign) BOOL isDefaultFocusAppearance; +#endif + @end diff --git a/AsyncDisplayKit/ASImageNode.mm b/AsyncDisplayKit/ASImageNode.mm index 97fc563ebb..3e9b9e7757 100644 --- a/AsyncDisplayKit/ASImageNode.mm +++ b/AsyncDisplayKit/ASImageNode.mm @@ -73,11 +73,6 @@ void (^_displayCompletionBlock)(BOOL canceled); ASDN::RecursiveMutex _imageLock; - -#if TARGET_OS_TV - //tvOS - BOOL isDefaultState; -#endif // Cropping. BOOL _cropEnabled; // Defaults to YES.