]> git.saurik.com Git - cydia.git/blob - CyteKit/TabBarController.mm
Move some of our clearly shared code into CyteKit.
[cydia.git] / CyteKit / TabBarController.mm
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "CyteKit/UCPlatform.h"
23
24 #include "CyteKit/TabBarController.h"
25
26 #include "iPhonePrivate.h"
27 #include <Menes/ObjectHandle.h>
28
29 @implementation UITabBarController (Cydia)
30
31 @end
32
33 @implementation CyteTabBarController {
34 _transient UIViewController *transient_;
35 _H<UIViewController> remembered_;
36 }
37
38 - (NSArray *) navigationURLCollection {
39 NSMutableArray *items([NSMutableArray array]);
40
41 // XXX: Should this deal with transient view controllers?
42 for (id navigation in [self viewControllers]) {
43 NSArray *stack = [navigation performSelector:@selector(navigationURLCollection)];
44 if (stack != nil)
45 [items addObject:stack];
46 }
47
48 return items;
49 }
50
51 - (void) didReceiveMemoryWarning {
52 [super didReceiveMemoryWarning];
53
54 // presenting a UINavigationController on 2.x does not update its transitionView
55 // it thereby will not allow its topViewController to be unloaded by memory pressure
56 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
57 UIViewController *selected([self selectedViewController]);
58 for (UINavigationController *controller in [self viewControllers])
59 if (controller != selected)
60 if (UIViewController *top = [controller topViewController])
61 [top unloadView];
62 }
63 }
64
65 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
66 if ([self unselectedViewController])
67 [self setUnselectedViewController:nil];
68
69 // presenting a UINavigationController on 2.x does not update its transitionView
70 // if this view was unloaded, the tranitionView may currently be presenting nothing
71 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
72 UINavigationController *navigation((UINavigationController *) viewController);
73 [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
74 [navigation popViewControllerAnimated:NO];
75 }
76 }
77
78 - (void) dismissModalViewControllerAnimated:(BOOL)animated {
79 if ([self modalViewController] == nil && [self unselectedViewController] != nil)
80 [self setUnselectedViewController:nil];
81 else
82 [super dismissModalViewControllerAnimated:YES];
83 }
84
85 - (void) setUnselectedViewController:(UIViewController *)transient {
86 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
87 if (transient != nil) {
88 [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
89 [self setSelectedIndex:0];
90 } return;
91 }
92
93 NSMutableArray *controllers = [[[self viewControllers] mutableCopy] autorelease];
94 if (transient != nil) {
95 UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
96 [navigation setViewControllers:[NSArray arrayWithObject:transient]];
97 transient = navigation;
98
99 if (transient_ == nil)
100 remembered_ = [controllers objectAtIndex:0];
101 transient_ = transient;
102 [transient_ setTabBarItem:[remembered_ tabBarItem]];
103 [controllers replaceObjectAtIndex:0 withObject:transient_];
104 [self setSelectedIndex:0];
105 [self setViewControllers:controllers];
106 [self concealTabBarSelection];
107 } else if (remembered_ != nil) {
108 [remembered_ setTabBarItem:[transient_ tabBarItem]];
109 transient_ = transient;
110 [controllers replaceObjectAtIndex:0 withObject:remembered_];
111 remembered_ = nil;
112 [self setViewControllers:controllers];
113 [self revealTabBarSelection];
114 }
115 }
116
117 - (UIViewController *) unselectedViewController {
118 return transient_;
119 }
120
121 - (void) unloadData {
122 [super unloadData];
123
124 for (UINavigationController *controller in [self viewControllers])
125 [controller unloadData];
126
127 if (UIViewController *selected = [self selectedViewController])
128 [selected reloadData];
129
130 if (UIViewController *unselected = [self unselectedViewController]) {
131 [unselected unloadData];
132 [unselected reloadData];
133 }
134 }
135
136 #include "InterfaceOrientation.h"
137
138 @end