-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTabBarItems.xm
More file actions
155 lines (133 loc) · 5.1 KB
/
TabBarItems.xm
File metadata and controls
155 lines (133 loc) · 5.1 KB
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
//
// TabBarItems.xm
// RedditGold
//
// Created by Tanner Bennett on 2020-04-24
// Copyright © 2020 Tanner Bennett. All rights reserved.
//
#import "Interfaces.h"
%hook MainTabBarController
- (void)setViewControllers:(NSMutableArray<UIViewController *> *)controllers {
// Create the new last tab
UIViewController *userDrawer = [[%c(UserDrawerViewController) alloc]
initWithAccountContext:self.accountContext
];
// Replace the last tab
NSMutableArray<UIViewController *> *tabs = controllers.mutableCopy;
[tabs removeLastObject];
[tabs addObject:[[%c(BaseNavigationViewController) alloc]
initWithRootViewController:userDrawer
]];
// Set the tab bar icon to a cake icon
UITabBarItem *item = tabs.lastObject.tabBarItem;
item.imageInsets = tabs.firstObject.tabBarItem.imageInsets;
item.image = item.selectedImage = [UIImage imageNamed:@"icon_cake_24"];
// Add long press gesture recognizer to middle tab bar item
UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:userDrawer action:@selector(pressedSignUpOrLogInButton:)
];
gesture.minimumPressDuration = .2;
[self.postButton addGestureRecognizer:gesture];
%orig(tabs);
}
%end
%hook UserDrawerViewController
// Make the drawer full screen width
+ (CGFloat)panelWidth {
return UIScreen.mainScreen.bounds.size.width;
}
// Remove some useless actions
- (NSMutableArray *)availableUserActions {
NSMutableArray<NSNumber *> *actions = %orig;
[actions removeObject:@(UserDrawerActionRedditCoins)];
[actions removeObject:@(UserDrawerActionRedditPremium)];
return actions;
}
- (void)viewDidLoad {
%orig;
if (self.tabBarController) {
self.closeButton.hidden = YES;
// Experimental: set the tab bar icon to my avatar
// UITabBarItem *item = self.navigationController.tabBarItem;
// UIImage *icon = [self.iconImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// icon = [icon imageScaledToSize:CGSizeMake(24, 24)];
// item.image = icon;
// item.selectedImage = icon;
}
}
- (void)pressedAvatar:(id)sender {
if (self.tabBarController) {
// Push profile
[self.navigationController pushViewController:[[%c(UserProfileViewController) alloc]
initWithUsername:self.accountManager.currentService.account.user.username
accountContext:self.accountContext
analyticsReferrerInfo:nil
] animated:YES];
} else {
%orig;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!self.tabBarController) {
%orig;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIViewController *toPush = nil;
if (tableView == self.actionsTableView) {
switch (self.availableUserActions[indexPath.row].unsignedIntegerValue) {
case UserDrawerActionMyProfile:
[self pressedAvatar:nil];
break;
case UserDrawerActionRedditCoins:
// lol
break;
case UserDrawerActionRedditPremium:
// looool
break;
case UserDrawerActionSaved:
toPush = [[%c(SavedTabViewController) alloc] initWithCategoryName:nil];
break;
case UserDrawerActionHistory:
toPush = [%c(FeedViewControllerFactory)
aggregateHistoryFeedViewControllerWithAccountContext:self.accountContext
];
break;
case UserDrawerActionPendingPosts:
toPush = [[%c(Reddit.PendingPostsViewController) alloc]
initWithAccountContext:self.accountContext
];
break;
case UserDrawerActionDrafts:
// Previously without the `Reddit.`
toPush = [[%c(Reddit.DraftsListViewController) alloc]
initWithAccountContext:self.accountContext
];
break;
case UserDrawerActionCreateCommunity:
break;
}
if (toPush) {
[self.navigationController pushViewController:toPush animated:YES];
}
} else {
// Present settings
AppSettingsViewController *settings = [[%c(AppSettingsViewController) alloc]
initWithAccountManager:self.accountManager
];
settings.navigationItem.leftBarButtonItem = [%c(BaseBarButtonItem)
closeButtonWithTarget:settings action:NSSelectorFromString(@"didTapCloseButton:")
];
BaseNavigationViewController *nav = [[%c(BaseNavigationViewController) alloc]
initWithRootViewController:settings
];
[self.navigationController presentViewController:nav animated:YES completion:nil];
}
}
%end
%hook Reddit.AccountStatusViewController
// Used to be in UserDrawerViewController
- (void)actionSheetViewController:(id)sheet didSelectSwitchToAccount:(id)account {
%orig;
[%c(RootViewController) reloadAllControllers];
}
%end