Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-23684] iOS: Expose properties to hide the navbar #8160

Merged
merged 10 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions apidoc/Titanium/UI/Window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,54 @@ properties:
default: false
since: 3.2.0

- name: hidesBarsOnSwipe
summary: Set this to true to hide the navigation bar on swipe.
description: |
When this property is set to true, an upward swipe hides the navigation bar and toolbar.
A downward swipe shows both bars again. If the toolbar does not have any items, it remains
visible even after a swipe.
platforms: [iphone, ipad]
type: Boolean
default: false
since: 6.0.0
osver: {ios: "8.0"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid. Check my comment again, it's

    osver: {ios: {min: "8.0"}}


- name: hidesBarsOnTap
summary: Set this to true to hide the navigation bar on tap.
description: |
When the value of this property is true, the navigation controller toggles the hiding and
showing of its navigation bar and toolbar in response to an otherwise unhandled tap
in the content area.
platforms: [iphone, ipad]
type: Boolean
default: false
since: 6.0.0
osver: {ios: "8.0"}

- name: hidesBarsWhenVerticallyCompact
summary: Set this to true to hide the navigation bar in a vertically compact environment.
description: |
When the value of this property is true, the navigation controller hides its navigation bar
and toolbar when it transitions to a vertically compact environment.
Upon returning to a vertically regular environment, the navigation controller automatically shows both bars again.
In addition, unhandled taps in the content area cause the navigation controller to show both bars again.
platforms: [iphone, ipad]
type: Boolean
default: false
since: 6.0.0
osver: {ios: "8.0"}

- name: hidesBarsWhenKeyboardAppears
summary: Set this to true to hide the navigation bar when the keyboard appears.
description: |
When this property is set to true, the appearance of the keyboard causes the
navigation controller to hide its navigation bar and toolbar.
platforms: [iphone, ipad]
type: Boolean
default: false
since: 6.0.0
osver: {ios: "8.0"}

- name: left
summary: Window's left position, in platform-specific units.
description: |
Expand Down
68 changes: 68 additions & 0 deletions iphone/Classes/TiUIWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,70 @@ -(void)setToolbar:(id)items withObject:(id)properties

}

-(void)setHidesBarsOnSwipe:(id)value
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need validation, please add

ENSURE_TYPE(value, NSNumber);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, it's a bool!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They come to the proxies as NSNumbers (because of the JavaScriptCore below it). So usually this is what you do in boolean-setters:

- (void)setHidesBarsOnSwipe:(id)value
{
    ENSURE_TYPE(value, NSNumber);

    [myView setWhatever:[TiUtils boolValue:value def:YES]];
    [self replaceValue:value forKey:@"hidesBarsOnSwipe" notification:NO];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thank you!

ENSURE_TYPE(value, NSNumber);

[self replaceValue:value forKey:@"hidesBarsOnSwipe" notification:NO];

if ([TiUtils isIOS8OrGreater]) {
TiThreadPerformOnMainThread(^{
if ((controller != nil) && ([controller navigationController] != nil)) {
UINavigationController *ourNC = [controller navigationController];
ourNC.hidesBarsOnSwipe = [TiUtils boolValue:[self valueForUndefinedKey:@"hidesBarsOnSwipe"] def:NO];
}
}, NO);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do that in the setters directly to keep the number of methods small and the code semantically together.


-(void)setHidesBarsOnTap:(id)value
{
ENSURE_TYPE(value, NSNumber);

[self replaceValue:value forKey:@"hidesBarsOnTap" notification:NO];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, add it for all please


if ([TiUtils isIOS8OrGreater]) {
TiThreadPerformOnMainThread(^{
if ((controller != nil) && ([controller navigationController] != nil)) {
UINavigationController *ourNC = [controller navigationController];
ourNC.hidesBarsOnTap = [TiUtils boolValue:[self valueForUndefinedKey:@"hidesBarsOnTap"] def:NO];
}
}, NO);
}
}

-(void)setHidesBarsWhenVerticallyCompact:(id)value
{
ENSURE_TYPE(value, NSNumber);

[self replaceValue:value forKey:@"hidesBarsWhenVerticallyCompact" notification:NO];

if ([TiUtils isIOS8OrGreater]) {
TiThreadPerformOnMainThread(^{
if ((controller != nil) && ([controller navigationController] != nil)) {
UINavigationController *ourNC = [controller navigationController];
ourNC.hidesBarsWhenVerticallyCompact = [TiUtils boolValue:[self valueForUndefinedKey:@"hidesBarsWhenVerticallyCompact"] def:NO];
}
}, NO);
}
}

-(void)setHidesBarsWhenKeyboardAppears:(id)value
{
ENSURE_TYPE(value, NSNumber);

[self replaceValue:value forKey:@"hidesBarsWhenKeyboardAppears" notification:NO];

if ([TiUtils isIOS8OrGreater]) {
TiThreadPerformOnMainThread(^{
if ((controller != nil) && ([controller navigationController] != nil)) {
UINavigationController *ourNC = [controller navigationController];
ourNC.hidesBarsWhenKeyboardAppears = [TiUtils boolValue:[self valueForUndefinedKey:@"hidesBarsWhenKeyboardAppears"] def:NO];
}
}, NO);
}
}


#define SETPROP(m,x) \
{\
Expand Down Expand Up @@ -970,6 +1034,10 @@ -(void)setupWindowDecorations
SETPROP(@"navTintColor",setNavTintColor);
SETPROP(@"translucent",setTranslucent);
SETPROP(@"tabBarHidden",setTabBarHidden);
SETPROP(@"hidesBarsOnSwipe", setHidesBarsOnSwipe);
SETPROP(@"hidesBarsOnTap", setHidesBarsOnTap);
SETPROP(@"hidesBarsWhenVerticallyCompact", setHidesBarsWhenVerticallyCompact);
SETPROP(@"hidesBarsWhenKeyboardAppears", setHidesBarsWhenKeyboardAppears);
SETPROPOBJ(@"toolbar",setToolbar);
[self updateBarImage];
[self updateNavButtons];
Expand Down