Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

made the tab-bar-hiding logic more generic by accepting a function in…

…stead of a class name, so clients are in full control of which V.C. need to hide the tab-bar under what circumstances
  • Loading branch information...
commit c875a6cee505f800300967e83f2f0c30e064b29e 1 parent 3805250
@ettore authored
Showing with 24 additions and 14 deletions.
  1. +19 −10 clcg_gfx.h
  2. +5 −4 clcg_gfx.m
View
29 clcg_gfx.h
@@ -52,8 +52,16 @@ UIImage *clcg_do_snapshot(UIView *v, NSString *title);
/**
- * Scenario: you want to hide the bottom bar when a VC of class 'hiding_vc_class'
- * is pushed on the stack.
+ * Clients should define a function with this signature to determine if
+ * the bottom bar should be hidden when the given vc is pushed on the stack,
+ * or if should be show it back when the vc is popped from the stack.
+ */
+typedef BOOL (*clcg_should_hide_vc_f)(UIViewController *vc);
+
+
+/**
+ * Scenario: you want to hide the bottom bar when a given VC is pushed on the
+ * stack and certain conditions are met.
*
* Usage: from your UINavigationController subclass, override
* pushViewController:animated: and call this function before calling super.
@@ -62,27 +70,28 @@ UIImage *clcg_do_snapshot(UIView *v, NSString *title);
* @param nc The Navigation Controller who's pushing the view controllers on
* the navigation stack.
* @param vc The view conroller about to be pushed.
- * @param hiding_vc_class The specific class for which we want to hide the
- * bottom bar.
+ * @param clcg_should_hide_vc_f Function determining if we should hide the
+ * bottom bar when pushing `vc' on the stack.
*/
void clcg_pushing_vc_for_hiding(UINavigationController *nc,
UIViewController *vc,
- Class hiding_vc_class);
+ clcg_should_hide_vc_f fun);
/**
- * Scenario: you want to show back the bottom bar when a VC of class
- * 'hiding_vc_class' is popped from the stack.
+ * Scenario: you want to show back the bottom bar when a given VC is popped
+ * from the stack and certain conditions are met.
*
* Usage: from your UINavigationController subclass, override
* popViewControllerAnimated: and call this function before calling super.
*
* @param nc The Navigation Controller who's popping the view controllers on
* the navigation stack.
- * @param hiding_vc_class The specific class for which we want to hide the
- * bottom bar.
+ * @param clcg_should_hide_vc_f Function determining if we should hide the
+ * bottom bar when pushing `vc' on the stack.
*/
-void clcg_popping_vc_from_hiding(UINavigationController *nc, Class hiding_vc_class);
+void clcg_popping_vc_from_hiding(UINavigationController *nc,
+ clcg_should_hide_vc_f fun);
/**
View
9 clcg_gfx.m
@@ -79,9 +79,9 @@ void clcg_safe_remove_from_superview(id view)
void clcg_pushing_vc_for_hiding(UINavigationController *nc,
UIViewController *vc,
- Class hiding_vc_class)
+ clcg_should_hide_vc_f shouldhide_callback)
{
- BOOL is_vc_for_hiding = [vc isKindOfClass:hiding_vc_class];
+ BOOL is_vc_for_hiding = shouldhide_callback(vc);
vc.hidesBottomBarWhenPushed = is_vc_for_hiding;
@@ -92,7 +92,8 @@ void clcg_pushing_vc_for_hiding(UINavigationController *nc,
}
-void clcg_popping_vc_from_hiding(UINavigationController *nc, Class hiding_vc_class)
+void clcg_popping_vc_from_hiding(UINavigationController *nc,
+ clcg_should_hide_vc_f shouldhide_callback)
{
// this is the controller about to be removed
//UIViewController *curr = [nc topViewController];
@@ -101,7 +102,7 @@ void clcg_popping_vc_from_hiding(UINavigationController *nc, Class hiding_vc_cla
int cnt = [vcs count];
if (cnt >= 2) {
UIViewController *prev = [vcs objectAtIndex:cnt-2];
- if ([prev isKindOfClass:hiding_vc_class]) {
+ if (shouldhide_callback(prev)) {
prev.hidesBottomBarWhenPushed = YES;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.