Skip to content

Commit

Permalink
[Ink] Remove encoding/decoding behavior for custom properties (#4555)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Jul 25, 2018
1 parent 98b046d commit fc1e82c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 122 deletions.
61 changes: 3 additions & 58 deletions components/Ink/src/MDCInkView.m
Expand Up @@ -20,15 +20,6 @@
#import "private/MDCInkLayer.h"
#import "private/MDCLegacyInkLayer.h"

static NSString *const MDCInkViewAnimationDelegateKey = @"MDCInkViewAnimationDelegateKey";
static NSString *const MDCInkViewInkStyleKey = @"MDCInkViewInkStyleKey";
static NSString *const MDCInkViewUsesLegacyInkRippleKey = @"MDCInkViewUsesLegacyInkRippleKey";
static NSString *const MDCInkViewMaskLayerKey = @"MDCInkViewMaskLayerKey";
static NSString *const MDCInkViewUsesCustomInkCenterKey = @"MDCInkViewUsesCustomInkCenterKey";
static NSString *const MDCInkViewCustomInkCenterKey = @"MDCInkViewCustomInkCenterKey";
static NSString *const MDCInkViewInkColorKey = @"MDCInkViewInkColorKey";
static NSString *const MDCInkViewMaxRippleRadiusKey = @"MDCInkViewMaxRippleRadiusKey";

@interface MDCInkPendingAnimation : NSObject <CAAction>

@property(nonatomic, weak) CALayer *animationSourceLayer;
Expand Down Expand Up @@ -69,59 +60,13 @@ - (instancetype)initWithFrame:(CGRect)frame {
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
if ([aDecoder containsValueForKey:MDCInkViewAnimationDelegateKey]) {
_animationDelegate = [aDecoder decodeObjectForKey:MDCInkViewAnimationDelegateKey];
}
if ([aDecoder containsValueForKey:MDCInkViewMaskLayerKey]) {
_maskLayer = [aDecoder decodeObjectForKey:MDCInkViewMaskLayerKey];
_maskLayer.delegate = self;
} else {
_maskLayer = [CAShapeLayer layer];
_maskLayer.delegate = self;
}
if ([aDecoder containsValueForKey:MDCInkViewUsesLegacyInkRippleKey]) {
_usesLegacyInkRipple = [aDecoder decodeBoolForKey:MDCInkViewUsesLegacyInkRippleKey];
} else {
_usesLegacyInkRipple = YES;
}
if ([aDecoder containsValueForKey:MDCInkViewInkStyleKey]) {
self.inkStyle = [aDecoder decodeIntegerForKey:MDCInkViewInkStyleKey];
}

// The following are derived properties, but `layer` may not have been encoded
if ([aDecoder containsValueForKey:MDCInkViewUsesCustomInkCenterKey]) {
self.usesCustomInkCenter = [aDecoder decodeBoolForKey:MDCInkViewUsesCustomInkCenterKey];
}
if ([aDecoder containsValueForKey:MDCInkViewCustomInkCenterKey]) {
self.customInkCenter = [aDecoder decodeCGPointForKey:MDCInkViewCustomInkCenterKey];
}
if ([aDecoder containsValueForKey:MDCInkViewMaxRippleRadiusKey]) {
self.maxRippleRadius = (CGFloat)[aDecoder decodeDoubleForKey:MDCInkViewMaxRippleRadiusKey];
}
if ([aDecoder containsValueForKey:MDCInkViewInkColorKey]) {
self.inkColor = [aDecoder decodeObjectOfClass:[UIColor class] forKey:MDCInkViewInkColorKey];
}
_maskLayer = [CAShapeLayer layer];
_maskLayer.delegate = self;
_usesLegacyInkRipple = YES;
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];

if (self.animationDelegate && [self.animationDelegate conformsToProtocol:@protocol(NSCoding)]) {
[aCoder encodeObject:self.animationDelegate forKey:MDCInkViewAnimationDelegateKey];
}
[aCoder encodeInteger:self.inkStyle forKey:MDCInkViewInkStyleKey];
[aCoder encodeBool:self.usesLegacyInkRipple forKey:MDCInkViewUsesLegacyInkRippleKey];
[aCoder encodeObject:self.maskLayer forKey:MDCInkViewMaskLayerKey];

// The following are derived properties, but `layer` may not get encoded by the superclass
[aCoder encodeBool:self.usesCustomInkCenter forKey:MDCInkViewUsesCustomInkCenterKey];
[aCoder encodeCGPoint:self.customInkCenter forKey:MDCInkViewCustomInkCenterKey];
[aCoder encodeDouble:self.maxRippleRadius forKey:MDCInkViewMaxRippleRadiusKey];
[aCoder encodeObject:self.inkColor forKey:MDCInkViewInkColorKey];
}

- (void)commonMDCInkViewInit {
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor clearColor];
Expand Down
64 changes: 0 additions & 64 deletions components/Ink/tests/unit/MDCInkViewTests.m
Expand Up @@ -65,70 +65,6 @@ - (void)testInit {
XCTAssertEqualWithAccuracy(inkView.maxRippleRadius, 0.0, 0.0001);
}

- (void)testEncodingWithoutLegacyInk {
// Given
FakeMDCInkViewAnimationDelegate *delegate = [[FakeMDCInkViewAnimationDelegate alloc] init];
MDCInkView *inkView = [[MDCInkView alloc] init];
delegate.inkView = inkView;
inkView.usesLegacyInkRipple = NO;
inkView.usesCustomInkCenter = YES;
inkView.customInkCenter = CGPointMake(5,8);
inkView.animationDelegate = delegate;
inkView.inkColor = UIColor.purpleColor;
inkView.inkStyle = MDCInkStyleUnbounded;
inkView.maxRippleRadius = (CGFloat)9.1;

// When
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:delegate];
FakeMDCInkViewAnimationDelegate *unarchivedDelegate =
[NSKeyedUnarchiver unarchiveObjectWithData:archive];
MDCInkView *unarchivedInkView = unarchivedDelegate.inkView;

// Then
XCTAssertEqual(unarchivedInkView.usesLegacyInkRipple, inkView.usesLegacyInkRipple);
XCTAssertEqual(unarchivedInkView.usesCustomInkCenter, inkView.usesCustomInkCenter);
XCTAssertTrue(CGPointEqualToPoint(unarchivedInkView.customInkCenter, inkView.customInkCenter),
@"%@ is not equal to %@",
NSStringFromCGPoint(unarchivedInkView.customInkCenter),
NSStringFromCGPoint(inkView.customInkCenter));
XCTAssertEqual(unarchivedInkView.animationDelegate, unarchivedDelegate);
XCTAssertEqualObjects(unarchivedInkView.inkColor, inkView.inkColor);
XCTAssertEqual(unarchivedInkView.inkStyle, inkView.inkStyle);
XCTAssertEqualWithAccuracy(unarchivedInkView.maxRippleRadius, inkView.maxRippleRadius, 0.0001);
}

- (void)testEncodingWithLegacyInk {
// Given
FakeMDCInkViewAnimationDelegate *delegate = [[FakeMDCInkViewAnimationDelegate alloc] init];
MDCInkView *inkView = [[MDCInkView alloc] init];
delegate.inkView = inkView;
inkView.usesLegacyInkRipple = YES;
inkView.usesCustomInkCenter = YES;
inkView.customInkCenter = CGPointMake(5,8);
inkView.animationDelegate = delegate;
inkView.inkColor = UIColor.purpleColor;
inkView.inkStyle = MDCInkStyleUnbounded;
inkView.maxRippleRadius = (CGFloat)9.1;

// When
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:delegate];
FakeMDCInkViewAnimationDelegate *unarchivedDelegate =
[NSKeyedUnarchiver unarchiveObjectWithData:archive];
MDCInkView *unarchivedInkView = unarchivedDelegate.inkView;

// Then
XCTAssertEqual(unarchivedInkView.usesLegacyInkRipple, inkView.usesLegacyInkRipple);
XCTAssertEqual(unarchivedInkView.usesCustomInkCenter, inkView.usesCustomInkCenter);
XCTAssertTrue(CGPointEqualToPoint(unarchivedInkView.customInkCenter, inkView.customInkCenter),
@"%@ is not equal to %@",
NSStringFromCGPoint(unarchivedInkView.customInkCenter),
NSStringFromCGPoint(inkView.customInkCenter));
XCTAssertEqual(unarchivedInkView.animationDelegate, unarchivedDelegate);
XCTAssertEqualObjects(unarchivedInkView.inkColor, inkView.inkColor);
XCTAssertEqual(unarchivedInkView.inkStyle, inkView.inkStyle);
XCTAssertEqualWithAccuracy(unarchivedInkView.maxRippleRadius, inkView.maxRippleRadius, 0.0001);
}

- (void)testNewInkUsesMaxRippleRadiusWhenUnbounded {
// Given
MDCInkView *inkViewStyleThenRadius = [[MDCInkView alloc] init];
Expand Down

0 comments on commit fc1e82c

Please sign in to comment.