-
Notifications
You must be signed in to change notification settings - Fork 4
/
SBIconListView+ApexAdditions.xm
175 lines (155 loc) · 5.4 KB
/
SBIconListView+ApexAdditions.xm
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#import <SpringBoard/SpringBoard.h>
#import <dlfcn.h>
#import "STKConstants.h"
#import "SBIconListView+ApexAdditions.h"
#define kInvalidIconPadding -1337.f
static BOOL _hasGridlock;
%hook SBIconListView
%new
- (NSUInteger)stk_visibleIconRowsForCurrentOrientation
{
return ([self rowForIcon:[[self icons] lastObject]] + 1);
}
%new
- (NSUInteger)stk_visibleIconColumnsForCurrentOrientation
{
return MIN([self icons].count, [self iconColumnsForCurrentOrientation]);
}
%new
- (void)setStk_realVerticalIconPadding:(CGFloat)padding
{
objc_setAssociatedObject(self, @selector(stk_realVerticalIconPadding), @(padding), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new
- (CGFloat)stk_realVerticalIconPadding
{
CGFloat padding = [objc_getAssociatedObject(self, @selector(stk_realVerticalIconPadding)) floatValue];
if (padding == kInvalidIconPadding || padding == 0.f) {
if ([self isKindOfClass:CLASS(SBDockIconListView)]) {
padding = [[CLASS(SBIconController) sharedInstance] currentRootIconList].stk_realVerticalIconPadding;
}
else {
CGFloat defaultIconHeight = [%c(SBIconView) defaultIconSize].height;
CGFloat position1 = [self originForIconAtCoordinate:(SBIconCoordinate){1, 1}].y;
CGFloat position2 = [self originForIconAtCoordinate:(SBIconCoordinate){2, 1}].y;
padding = (position2 - position1 - defaultIconHeight);
}
self.stk_realVerticalIconPadding = padding;
}
return padding;
}
%new
- (void)setStk_realHorizontalIconPadding:(CGFloat)padding
{
objc_setAssociatedObject(self, @selector(stk_realHorizontalIconPadding), @(padding), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new
- (CGFloat)stk_realHorizontalIconPadding
{
CGFloat padding = [objc_getAssociatedObject(self, @selector(stk_realHorizontalIconPadding)) floatValue];
if (padding == kInvalidIconPadding || padding == 0.f) {
CGFloat defaultIconWidth = [%c(SBIconView) defaultIconSize].width;
CGFloat position1 = 0.f;
CGFloat position2 = 0.f;
if (([self visibleIcons].count >= 2) && _hasGridlock == NO) {
position1 = [[self viewMap] mappedIconViewForIcon:[self visibleIcons][0]].frame.origin.x;
position2 = [[self viewMap] mappedIconViewForIcon:[self visibleIcons][1]].frame.origin.x;
}
else {
position1 = [self originForIconAtCoordinate:(SBIconCoordinate){1, 1}].x;
position2 = [self originForIconAtCoordinate:(SBIconCoordinate){1, 2}].x;
}
padding = (position2 - position1 - defaultIconWidth);
self.stk_realHorizontalIconPadding = padding;
}
return padding;
}
%new
- (void)setStk_modifyDisplacedIconOrigin:(BOOL)modify
{
objc_setAssociatedObject(self, @selector(stk_modifyDisplacedIconOrigin), @(modify), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new
- (BOOL)stk_modifyDisplacedIconOrigin
{
return [objc_getAssociatedObject(self, @selector(stk_modifyDisplacedIconOrigin)) boolValue];
}
%new
- (void)setStk_preventRelayout:(BOOL)prevent
{
objc_setAssociatedObject(self, @selector(stk_preventRelayout), @(prevent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new
- (BOOL)stk_preventRelayout
{
return [objc_getAssociatedObject(self, @selector(stk_preventRelayout)) boolValue];
}
%new
- (void)stk_makeIconViewsPerformBlock:(void(^)(SBIconView *iv))block
{
[self enumerateIconViewsUsingBlock:block];
}
%new
- (void)stk_reorderIconViews
{
NSMutableArray *iconViews = [self.subviews mutableCopy];
[iconViews sortUsingComparator:^NSComparisonResult(UIView *view1, UIView *view2) {
if(fabs(view1.frame.origin.y - view2.frame.origin.y) > 0.01)
return [@(view1.frame.origin.y) compare:@(view2.frame.origin.y)];
else
return [@(view1.frame.origin.x) compare:@(view2.frame.origin.x)];
}];
for (UIView *view in iconViews) {
[view.superview bringSubviewToFront:view];
}
}
- (void)prepareToRotateToInterfaceOrientation:(UIInterfaceOrientation)orient
{
self.stk_realVerticalIconPadding = kInvalidIconPadding;
self.stk_realHorizontalIconPadding = kInvalidIconPadding;
%orig(orient);
}
- (CGPoint)originForIconAtCoordinate:(SBIconCoordinate)coordinate
{
if (self.stk_modifyDisplacedIconOrigin) {
SBIcon *icon = [[self model] iconAtIndex:[self indexForCoordinate:coordinate forOrientation:[UIApplication sharedApplication].statusBarOrientation]];
STKGroupController *controller = [STKGroupController sharedController];
STKGroupView *groupView = controller.openGroupView ?: controller.openingGroupView;
if (!groupView.isAnimating && [[groupView.displacedIconLayout allIcons] containsObject:icon]) {
return [self viewForIcon:icon].frame.origin;
}
}
return %orig(coordinate);
}
- (void)layoutIconsNow
{
if (self.stk_preventRelayout) {
return;
}
self.stk_realHorizontalIconPadding = kInvalidIconPadding;
self.stk_realHorizontalIconPadding = kInvalidIconPadding;
%orig();
}
- (SBIcon *)layoutIconsIfNeeded:(NSTimeInterval)duration domino:(BOOL)domino
{
if (self.stk_preventRelayout) {
return nil;
}
return %orig();
}
- (void)setIconsNeedLayout
{
if (self.stk_preventRelayout) {
return;
}
%orig();
}
%end
%ctor
{
@autoreleasepool {
%init();
void *handle = dlopen("/Library/MobileSubstrate/DynamicLibraries/Gridlock.dylib", RTLD_NOW);
_hasGridlock = (handle != nil);
}
}