forked from efrederickson/Multiplexer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RAAppSliderProviderView.mm
100 lines (84 loc) · 2.71 KB
/
RAAppSliderProviderView.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import "RAAppSliderProviderView.h"
#import "RAHostedAppView.h"
#import "RAGestureManager.h"
#import "RAAppSliderProvider.h"
#include <execinfo.h>
@implementation RAAppSliderProviderView
@synthesize swipeProvider;
- (void)goToTheLeft {
[swipeProvider goToTheLeft];
[self updateCurrentView];
}
- (void)goToTheRight {
[swipeProvider goToTheRight];
[self updateCurrentView];
}
- (void)load {
[currentView loadApp];
}
- (void)unload {
if (!currentView || !currentView.bundleIdentifier) {
return;
}
[RAGestureManager.sharedInstance removeGestureWithIdentifier:currentView.bundleIdentifier];
[currentView unloadApp];
}
- (void)updateCurrentView {
[self unload];
if (currentView) {
[currentView removeFromSuperview];
}
currentView = [swipeProvider viewAtCurrentIndex];
if (self.isSwipeable && self.swipeProvider) {
self.backgroundColor = [UIColor clearColor]; // redColor];
self.userInteractionEnabled = YES;
[RAGestureManager.sharedInstance addGestureRecognizerWithTarget:self forEdge:UIRectEdgeLeft | UIRectEdgeRight identifier:currentView.bundleIdentifier priority:RAGesturePriorityHigh];
//[RAGestureManager.sharedInstance addGestureRecognizerWithTarget:self forEdge:UIRectEdgeRight identifier:currentView.bundleIdentifier priority:RAGesturePriorityHigh];
currentView.frame = CGRectMake(0, 0, self.frame.size.width - 0, self.frame.size.height);
} else {
currentView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}
[self addSubview:currentView];
[self load];
}
- (CGRect)clientFrame {
if (!currentView) {
return CGRectZero;
}
CGRect frame = currentView.frame;
frame.size.height = self.frame.size.height;
return frame;
}
- (NSString*)currentBundleIdentifier {
return currentView ? currentView.bundleIdentifier : nil;
}
- (BOOL)RAGestureCallback_canHandle:(CGPoint)point velocity:(CGPoint)velocity {
return point.y <= [self convertPoint:self.frame.origin toView:nil].y + self.frame.size.height;
}
- (RAGestureCallbackResult)RAGestureCallback_handle:(UIGestureRecognizerState)state withPoint:(CGPoint)location velocity:(CGPoint)velocity forEdge:(UIRectEdge)edge {
static BOOL didHandle = NO;
if (state == UIGestureRecognizerStateEnded) {
didHandle = NO;
return RAGestureCallbackResultSuccessAndStop;
}
if (didHandle) {
return RAGestureCallbackResultSuccessAndStop;
}
if (edge == UIRectEdgeLeft) {
didHandle = YES;
if (self.swipeProvider.canGoLeft) {
[self unload];
[self goToTheLeft];
}
return RAGestureCallbackResultSuccessAndStop;
} else if (edge == UIRectEdgeRight) {
didHandle = YES;
if (self.swipeProvider.canGoRight) {
[self unload];
[self goToTheRight];
}
return RAGestureCallbackResultSuccessAndStop;
}
return RAGestureCallbackResultFailure;
}
@end