-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ScrollAction and ControllerTransition
- Loading branch information
galenlin
committed
Jul 27, 2017
1 parent
db33109
commit 9ade2c0
Showing
30 changed files
with
1,087 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// PBAnimation.h | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import "PBFrameAnimation.h" | ||
|
||
#import "PBScrollAction.h" | ||
#import "PBScrollProgressAction.h" | ||
#import "PBScrollTriggerAction.h" | ||
#import "UIScrollView+PBScrollAction.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PBFrameAnimation.h | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface PBFrameAnimation : NSObject | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(CGFloat progress))animations; | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(CGFloat progress))animations completion:(void (^)(BOOL finished))completion; | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay animations:(void (^)(CGFloat progress))animations completion:(void (^)(BOOL finished))completion; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// PBFrameAnimation.m | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import "PBFrameAnimation.h" | ||
|
||
@implementation PBFrameAnimation | ||
{ | ||
NSTimeInterval _duration; | ||
NSTimeInterval _delay; | ||
CADisplayLink *_link; | ||
CFTimeInterval _timestamp; | ||
void (^_animations)(CGFloat progress); | ||
void (^_complection)(BOOL finished); | ||
} | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(CGFloat))animations { | ||
[self animateWithDuration:duration animations:animations completion:nil]; | ||
} | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(CGFloat))animations completion:(void (^)(BOOL))completion { | ||
[self animateWithDuration:duration delay:0.f animations:animations completion:completion]; | ||
} | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay animations:(void (^)(CGFloat progress))animations completion:(void (^)(BOOL finished))completion { | ||
if (duration == 0) { | ||
if (animations) { | ||
animations(1.f); | ||
} | ||
if (completion) { | ||
completion(YES); | ||
} | ||
return; | ||
} | ||
|
||
PBFrameAnimation *anim = [[PBFrameAnimation alloc] init]; | ||
anim->_duration = duration; | ||
anim->_delay = delay; | ||
anim->_animations = animations; | ||
anim->_complection = completion; | ||
[anim run]; | ||
} | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplay:)]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)run { | ||
_timestamp = CACurrentMediaTime(); | ||
[_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; | ||
} | ||
|
||
- (void)onDisplay:(CADisplayLink *)link { | ||
CGFloat progress = (CACurrentMediaTime() - _timestamp) / _duration; | ||
NSLog(@"==== %.2f", progress); | ||
BOOL complected = NO; | ||
if (progress >= 1.f) { | ||
progress = 1.f; | ||
complected = YES; | ||
[link invalidate]; | ||
} | ||
|
||
if (_animations) { | ||
_animations(progress); | ||
} | ||
|
||
if (complected) { | ||
if (_complection) { | ||
_complection(YES); | ||
} | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// NSNumber+PBScrollAction.h | ||
// PBScrollMonitor | ||
// | ||
// Created by galen on 17/7/20. | ||
// Copyright © 2017年 galen. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "PBScrollActionProgressing.h" | ||
|
||
@interface NSNumber (PBScrollAction) <PBScrollActionProgressing> | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// NSNumber+PBScrollAction.m | ||
// PBScrollMonitor | ||
// | ||
// Created by galen on 17/7/20. | ||
// Copyright © 2017年 galen. All rights reserved. | ||
// | ||
|
||
#import "NSNumber+PBScrollAction.h" | ||
|
||
@implementation NSNumber (PBScrollAction) | ||
|
||
+ (id)valueWithProgress:(double)progress fromValue:(id)fromValue toValue:(id)toValue { | ||
if ([fromValue isEqualToNumber:toValue]) { | ||
return fromValue; | ||
} | ||
|
||
double from = [fromValue doubleValue]; | ||
double to = [toValue doubleValue]; | ||
return @(from + progress * (to - from)); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// PBScrollAction.h | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
#import "PBScrollActionMapper.h" | ||
|
||
@protocol PBScrollAction <NSObject> | ||
|
||
- (BOOL)canRunActionWithScrollView:(UIScrollView *)scrollView; | ||
|
||
- (void)actionWithScrollView:(UIScrollView *)scrollView; | ||
|
||
@end | ||
|
||
@interface PBScrollAction : NSObject <PBScrollAction> | ||
|
||
+ (instancetype)actionWithMapper:(PBScrollActionMapper *)mapper; | ||
|
||
@property (nonatomic, strong) id target; | ||
|
||
@property (nonatomic, strong) NSString *keyPath; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// PBScrollAction.m | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import "PBScrollAction.h" | ||
#import <Pbind/Pbind.h> | ||
|
||
@implementation PBScrollAction | ||
{ | ||
PBScrollActionMapper *_mapper; | ||
} | ||
|
||
+ (instancetype)actionWithMapper:(PBScrollActionMapper *)mapper { | ||
PBScrollAction *action = [[mapper.actionClass alloc] init]; | ||
action->_mapper = mapper; | ||
return action; | ||
} | ||
|
||
- (void)_internalActionWithScrollView:(UIScrollView *)scrollView { | ||
if (_mapper != nil) { | ||
[_mapper setPropertiesToObject:self transform:nil]; | ||
self.target = _mapper.target; | ||
[_mapper mapPropertiesToObject:self withData:scrollView.rootData context:scrollView]; | ||
} | ||
|
||
if ([self respondsToSelector:@selector(canRunActionWithScrollView:)]) { | ||
if (![self canRunActionWithScrollView:scrollView]) { | ||
return; | ||
} | ||
} | ||
|
||
if ([self respondsToSelector:@selector(actionWithScrollView:)]) { | ||
[self actionWithScrollView:scrollView]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// PBScrollActionMapper.h | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import <Pbind/Pbind.h> | ||
|
||
@interface PBScrollActionMapper : PBMapper | ||
|
||
#pragma mark - Plisting | ||
///============================================================================= | ||
/// @name Plisting | ||
///============================================================================= | ||
|
||
/** | ||
The scroll action type, supports: | ||
- progress (DEFAULT) | ||
- evaluate | ||
- trigger | ||
which would dispatch the action to `PB[Type]ScrollAction' | ||
*/ | ||
@property (nonatomic, strong) NSString *type; | ||
|
||
/** | ||
The action plist used to map properties to `PB[Type]ScrollAction' | ||
*/ | ||
@property (nonatomic, strong) NSString *action; | ||
|
||
@property (nonatomic, strong) id target; | ||
|
||
#pragma mark - Caching | ||
///============================================================================= | ||
/// @name Caching | ||
///============================================================================= | ||
|
||
@property (nonatomic, weak) Class actionClass; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// PBScrollActionMapper.m | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import "PBScrollActionMapper.h" | ||
#import "PBScrollProgressAction.h" | ||
|
||
@implementation PBScrollActionMapper | ||
|
||
- (void)setType:(NSString *)type { | ||
_type = type; | ||
if (type == nil || type.length < 2) { | ||
_actionClass = nil; | ||
return; | ||
} | ||
|
||
NSString *clazz = [NSString stringWithFormat:@"PBScroll%c%@Action", toupper([type characterAtIndex:0]), [type substringFromIndex:1]]; | ||
_actionClass = NSClassFromString(clazz); | ||
} | ||
|
||
- (void)setAction:(NSString *)action { | ||
_viewProperties = [PBMapperProperties propertiesWithDictionary:PBPlist(action)]; | ||
} | ||
|
||
- (Class)actionClass { | ||
if (_actionClass != nil) { | ||
return _actionClass; | ||
} | ||
return [PBScrollProgressAction class]; | ||
} | ||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
PBKit/PBAnimation/ScrollAction/PBScrollActionProgressing.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// PBScrollActionProgressing.h | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@protocol PBScrollActionProgressing <NSObject> | ||
|
||
+ (id)valueWithProgress:(double)progress fromValue:(id)fromValue toValue:(id)toValue; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// PBScrollEvaluateAction.h | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import "PBScrollAction.h" | ||
|
||
@interface PBScrollEvaluateAction : PBScrollAction | ||
|
||
/** | ||
The Javascript for evaluating the value for the key of the target. | ||
@discussion The built-in variables are: | ||
- offset, scrollView.contentOffset | ||
- inset, scrollView.contentInsets | ||
*/ | ||
@property (nonatomic, strong) NSString *value; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// PBScrollEvaluateAction.m | ||
// Pods | ||
// | ||
// Created by galen on 17/7/24. | ||
// | ||
// | ||
|
||
#import "PBScrollEvaluateAction.h" | ||
|
||
@implementation PBScrollEvaluateAction | ||
|
||
- (BOOL)canRunActionWithScrollView:(UIScrollView *)scrollView { | ||
return YES; | ||
} | ||
|
||
- (void)actionWithScrollView:(UIScrollView *)scrollView { | ||
|
||
} | ||
|
||
@end |
Oops, something went wrong.