Skip to content

Commit

Permalink
Merge pull request #66 from RomanPodymov/master
Browse files Browse the repository at this point in the history
A small refactoring
  • Loading branch information
antiguab authored Sep 4, 2019
2 parents ea49454 + a419968 commit 4ad1b7d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 41 deletions.
28 changes: 13 additions & 15 deletions Example/BAFluidView/BAViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,8 @@ - (void)viewDidLoad {
self.currentExample = 0;

//For fading in swipe labels and timing it's appearance
self.fadeIn = [CABasicAnimation animationWithKeyPath:@"opacity"];
self.fadeIn.duration = 2.0;
self.fadeIn.fromValue = @0.0f;
self.fadeIn.toValue = @1.0f;
self.fadeIn.removedOnCompletion = NO;
self.fadeIn.fillMode = kCAFillModeForwards;
self.fadeIn.additive = NO;

self.fadeOut = [CABasicAnimation animationWithKeyPath:@"opacity"];
self.fadeOut.duration = 0.5f;
self.fadeOut.fromValue = @1.0f;
self.fadeOut.toValue = @0.0f;
self.fadeOut.removedOnCompletion = NO;
self.fadeOut.fillMode = kCAFillModeForwards;
self.fadeOut.additive = NO;
self.fadeIn = [BAViewController createOpacityAnimationWithDuration:2.0f fromValue:@0.0f toValue:@1.0f];
self.fadeOut = [BAViewController createOpacityAnimationWithDuration:0.5f fromValue:@1.0f toValue:@0.0f];

self.timer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
Expand All @@ -98,6 +85,17 @@ - (void)viewDidLoad {

}

+ (CABasicAnimation*)createOpacityAnimationWithDuration:(NSTimeInterval)aDuration fromValue:(id)aFromValue toValue:(id)aToValue {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = aDuration;
animation.fromValue = aFromValue;
animation.toValue = aToValue;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.additive = NO;
return animation;
}

- (void)viewDidLayoutSubviews {

if (self.firstTimeLoading) {
Expand Down
9 changes: 8 additions & 1 deletion Example/Tests/UIColorSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@

//(UIColor*)colorWithHex:(int)hex;
it(@"should create a UIColor with a given hex", ^{
UIColor* testColor = [UIColor colorWithHex:0x0000000];
UIColor* testColor = [UIColor colorWithHex:0x123456];
expect(testColor).to.beKindOf([UIColor class]);
const CGFloat *testColorComponents = CGColorGetComponents(testColor.CGColor);
CGFloat testRedComponent = (CGFloat)0x12/(CGFloat)0xFF;
expect(testColorComponents[0]).to.equal(testRedComponent);
CGFloat testGreenComponent = (CGFloat)0x34/(CGFloat)0xFF;
expect(testColorComponents[1]).to.equal(testGreenComponent);
CGFloat testBlueComponent = (CGFloat)0x56/(CGFloat)0xFF;
expect(testColorComponents[2]).to.equal(testBlueComponent);
});

});
Expand Down
6 changes: 3 additions & 3 deletions Pod/Classes/BAFluidView.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extern NSString * const kBAFluidViewCMMotionUpdate;
Lets you chose the interval between Max and Min the random function will use
@return a fluid view object with the properties defined
*/
- (id)initWithFrame:(CGRect)aRect maxAmplitude:(int)maxAmplitude minAmplitude:(int)minAmplitude amplitudeIncrement:(int)amplitudeIncrement;
- (instancetype)initWithFrame:(CGRect)aRect maxAmplitude:(int)maxAmplitude minAmplitude:(int)minAmplitude amplitudeIncrement:(int)amplitudeIncrement;

/**
Returns an object that can create the fluid animation with the given wave properties. This init function lets you adjust starting elevation. The other parameters have default values.
Expand All @@ -100,7 +100,7 @@ extern NSString * const kBAFluidViewCMMotionUpdate;
The starting point of the fluid animation
@return a fluid view object with the properties defined
*/
- (id)initWithFrame:(CGRect)aRect startElevation:(NSNumber*)aStartElevation;
- (instancetype)initWithFrame:(CGRect)aRect startElevation:(NSNumber*)aStartElevation;

/**
Returns an object that can create the fluid animation with the given wave properties. This init function lets you adjust all the wave crest and fluid properties.
Expand All @@ -117,7 +117,7 @@ extern NSString * const kBAFluidViewCMMotionUpdate;
The starting point of the fluid animation
@return a fluid view object with the properties defined
*/
- (id)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement startElevation:(NSNumber*)aStartElevation;
- (instancetype)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement startElevation:(NSNumber*)aStartElevation;

/**
This method lets you choose to what level you want the fluidVIew to increase or decrease to (based on starting elevation)
Expand Down
28 changes: 9 additions & 19 deletions Pod/Classes/BAFluidView.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ @implementation BAFluidView

#pragma mark - Lifecycle

- (id)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement
- (instancetype)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement
{
self = [super initWithFrame:aRect];
self = [self initWithFrame:aRect];

if (self)
{
[self initialize];

//setting custom wave properties
self.maxAmplitude = aMaxAmplitude;
self.minAmplitude = aMinAmplitude;
Expand All @@ -89,26 +87,19 @@ - (id)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:
return self;
}

- (id)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement startElevation:(NSNumber*)aStartElevation
- (instancetype)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement startElevation:(NSNumber*)aStartElevation
{
self = [super initWithFrame:aRect];
self = [self initWithFrame:aRect maxAmplitude:aMaxAmplitude minAmplitude:aMinAmplitude amplitudeIncrement:aAmplitudeIncrement];

if (self)
{
[self initialize];

//setting custom wave properties
self.maxAmplitude = aMaxAmplitude;
self.minAmplitude = aMinAmplitude;
self.amplitudeIncrement = aAmplitudeIncrement;
self.amplitudeArray = [self createAmplitudeOptions];
[self updateStartElevation:aStartElevation];;
[self updateStartElevation:aStartElevation];
}
return self;
}


- (id)initWithFrame:(CGRect)aRect
- (instancetype)initWithFrame:(CGRect)aRect
{
self = [super initWithFrame:aRect];

Expand All @@ -120,19 +111,18 @@ - (id)initWithFrame:(CGRect)aRect
return self;
}

- (id)initWithFrame:(CGRect)aRect startElevation:(NSNumber*)aStartElevation
- (instancetype)initWithFrame:(CGRect)aRect startElevation:(NSNumber*)aStartElevation
{
self = [super initWithFrame:aRect];
self = [self initWithFrame:aRect];

if (self)
{
[self initialize];
[self updateStartElevation:aStartElevation];
}
return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
- (instancetype)initWithCoder:(NSCoder *)aDecoder {

self = [super initWithCoder:aDecoder];

Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/UIColor+ColorWithHex.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@

@interface UIColor (ColorFromHex)

+(UIColor*)colorWithHex:(int)hex;
+(UIColor*)colorWithHex:(unsigned long)hex;

@end
@end
2 changes: 1 addition & 1 deletion Pod/Classes/UIColor+ColorWithHex.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@implementation UIColor (ColorFromHex)

+(UIColor*)colorWithHex:(int)hex
+(UIColor*)colorWithHex:(unsigned long)hex
{
return UIColorFromRGB(hex);
}
Expand Down

0 comments on commit 4ad1b7d

Please sign in to comment.