Skip to content

Instantly share code, notes, and snippets.

@rborn
Forked from artanisdesign/TiUIWindowProxy.m
Last active August 29, 2015 14:17
Show Gist options
  • Save rborn/a5dd651c3c86e43d417c to your computer and use it in GitHub Desktop.
Save rborn/a5dd651c3c86e43d417c to your computer and use it in GitHub Desktop.
//from line 502
-(void)setRightNavButton:(id)proxy withObject:(id)properties
{
ENSURE_UI_THREAD_WITH_OBJ(setRightNavButton,proxy,properties);
if (properties == nil) {
properties = [self valueForKey:@"rightNavSettings"];
}
else {
[self setValue:properties forKey:@"rightNavSettings"];
}
if (controller!=nil &&
[controller navigationController] != nil)
{
ENSURE_TYPE_OR_NIL(proxy,TiViewProxy);
[self replaceValue:proxy forKey:@"rightNavButton" notification:NO];
if (proxy==nil || [proxy supportsNavBarPositioning])
{
// detach existing one
UIBarButtonItem *item = controller.navigationItem.rightBarButtonItem;
if ([item respondsToSelector:@selector(proxy)])
{
TiViewProxy* p = (TiViewProxy*)[item performSelector:@selector(proxy)];
[p removeBarButtonView];
}
if (proxy!=nil)
{
// add the new one
BOOL animated = [TiUtils boolValue:@"animated" properties:properties def:NO];
//only ios7+ and if the view has the value set
if([proxy valueForKey:@"rightNavNegativeSpace"] != nil && [TiUtils isIOS7OrGreater]){
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = [[proxy valueForKey:@"rightNavNegativeSpace"] floatValue];
[controller.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:negativeSpacer, [proxy barButtonItem], nil] animated:animated];
} else{
[controller.navigationItem setRightBarButtonItem:[proxy barButtonItem] animated:animated];
}
}
else
{
controller.navigationItem.rightBarButtonItem = nil;
}
}
else
{
NSString *msg = [NSString stringWithFormat:@"%@ doesn't support positioning on the nav bar",proxy];
THROW_INVALID_ARG(msg);
}
}
else
{
[self replaceValue:[[[TiComplexValue alloc] initWithValue:proxy properties:properties] autorelease] forKey:@"rightNavButton" notification:NO];
}
}
-(void)setLeftNavButton:(id)proxy withObject:(id)properties
{
ENSURE_UI_THREAD_WITH_OBJ(setLeftNavButton,proxy,properties);
if (properties == nil) {
properties = [self valueForKey:@"leftNavSettings"];
}
else {
[self setValue:properties forKey:@"leftNavSettings"];
}
if (controller!=nil && [controller navigationController] != nil)
{
ENSURE_TYPE_OR_NIL(proxy,TiViewProxy);
[self replaceValue:proxy forKey:@"leftNavButton" notification:NO];
if (proxy==nil || [proxy supportsNavBarPositioning])
{
// detach existing one
UIBarButtonItem *item = controller.navigationItem.leftBarButtonItem;
if ([item respondsToSelector:@selector(proxy)])
{
TiViewProxy* p = (TiViewProxy*)[item performSelector:@selector(proxy)];
[p removeBarButtonView];
}
controller.navigationItem.leftBarButtonItem = nil;
if (proxy!=nil)
{
// add the new one
BOOL animated = [TiUtils boolValue:@"animated" properties:properties def:NO];
if([proxy valueForKey:@"leftNavNegativeSpace"] != nil && [TiUtils isIOS7OrGreater]){
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = [[proxy valueForKey:@"leftNavNegativeSpace"] floatValue];
[controller.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:negativeSpacer, [proxy barButtonItem], nil] animated:animated];
} else{
[controller.navigationItem setLeftBarButtonItem:[proxy barButtonItem] animated:animated];
}
}
else
{
controller.navigationItem.leftBarButtonItem = nil;
}
}
else
{
NSString *msg = [NSString stringWithFormat:@"%@ doesn't support positioning on the nav bar",proxy];
THROW_INVALID_ARG(msg);
}
}
else
{
[self replaceValue:[[[TiComplexValue alloc] initWithValue:proxy properties:properties] autorelease] forKey:@"leftNavButton" notification:NO];
}
}
//if you put a custom view/button/etc into rightNavButton, set rightNavNegativeSpace (if right side, obviously left for leftside)
//correct spacing is -16, both side
var rightView = $.UI.create('View', {
classes : "rightview",
rightNavNegativeSpace : -16
});
$.win.rightNavButton = rightView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment