Skip to content

Commit

Permalink
Merge pull request #4740 from vishalduggal/timob-15283
Browse files Browse the repository at this point in the history
[TIMOB-15283] iOS: SplitWindow does not respond to focus events
  • Loading branch information
srahim committed Sep 26, 2013
2 parents 48d3cf2 + 37d46c2 commit 62b0ab3
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 20 deletions.
10 changes: 5 additions & 5 deletions iphone/Classes/MGSplitView/MGSplitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,16 @@ - (IBAction)toggleMasterView:(id)sender
- (IBAction)showMasterPopover:(id)sender
{
if (_hiddenPopoverController && !(_hiddenPopoverController.popoverVisible)) {
// Show popover.
[(MGSplitView*)[self view] setSingleLayout];
[_hiddenPopoverController presentPopoverFromBarButtonItem:_barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
// Inform delegate.
if (_delegate && [_delegate respondsToSelector:@selector(splitViewController:popoverController:willPresentViewController:)]) {
[(NSObject <MGSplitViewControllerDelegate> *)_delegate splitViewController:self
popoverController:_hiddenPopoverController
[(NSObject <MGSplitViewControllerDelegate> *)_delegate splitViewController:self
popoverController:_hiddenPopoverController
willPresentViewController:self.masterViewController];
}

// Show popover.
[(MGSplitView*)[self view] setSingleLayout];
[_hiddenPopoverController presentPopoverFromBarButtonItem:_barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUIiPadSplitWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#import "TiUIView.h"
#import "MGSplitViewController.h"
#import "TiUIiPadSplitWindowProxy.h"

@class TiUIiPadPopoverProxy;

Expand Down
27 changes: 17 additions & 10 deletions iphone/Classes/TiUIiPadSplitWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{
if ([proxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy*)proxy setIsManaged:YES];
return [(TiWindowProxy*)proxy hostingController];
}

[[proxy view] setAutoresizingMask:UIViewAutoresizingNone];
Expand Down Expand Up @@ -67,13 +68,19 @@ -(UIViewController*)controller

[controller willAnimateRotationToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0.0];


[masterProxy windowWillOpen];
[masterProxy windowDidOpen];
if ([masterProxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy*)masterProxy open:nil];
} else {
[masterProxy windowWillOpen];
[masterProxy windowDidOpen];
}

[detailProxy windowWillOpen];
[detailProxy windowDidOpen];

if ([detailProxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy*)detailProxy open:nil];
} else {
[detailProxy windowWillOpen];
[detailProxy windowDidOpen];
}
[controller viewDidAppear:NO];
}
return controller;
Expand Down Expand Up @@ -130,7 +137,7 @@ -(void)setMasterPopupVisible_:(id)value

if (masterInSplit)
{
[[self proxy] replaceValue:NUMBOOL(NO) forKey:@"masterPopupVisibile" notification:NO];
[(TiUIiPadSplitWindowProxy*) [self proxy] popupVisibilityChanged:NO];
return;
}

Expand All @@ -157,7 +164,7 @@ -(void)setShowMasterInPortrait_:(id)value

- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc
{
[[self proxy] replaceValue:NUMBOOL(NO) forKey:@"masterPopupVisibile" notification:NO];
[(TiUIiPadSplitWindowProxy*) [self proxy] popupVisibilityChanged:NO];
if ([self.proxy _hasListeners:@"visible"])
{
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObject:@"detail" forKey:@"view"];
Expand All @@ -172,7 +179,7 @@ - (void)splitViewController:(UISplitViewController*)svc willHideViewController:(

- (void)splitViewController:(UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)button
{
[[self proxy] replaceValue:NUMBOOL(NO) forKey:@"masterPopupVisibile" notification:NO];
[(TiUIiPadSplitWindowProxy*) [self proxy] popupVisibilityChanged:NO];
if ([self.proxy _hasListeners:@"visible"])
{
NSDictionary *event = [NSDictionary dictionaryWithObject:@"master" forKey:@"view"];
Expand All @@ -182,7 +189,7 @@ - (void)splitViewController:(UISplitViewController*)svc willShowViewController:(

- (void)splitViewController:(UISplitViewController*)svc popoverController:(UIPopoverController*)pc willPresentViewController:(UIViewController *)aViewController
{
[[self proxy] replaceValue:NUMBOOL(YES) forKey:@"masterPopupVisibile" notification:NO];
[(TiUIiPadSplitWindowProxy*) [self proxy] popupVisibilityChanged:YES];
if ([self.proxy _hasListeners:@"visible"])
{
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObject:@"popover" forKey:@"view"];
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUIiPadSplitWindowProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@private
id<NSObject,TiOrientationController> detailView;
}

-(void)popupVisibilityChanged:(BOOL)newVal;
@end

#endif
67 changes: 67 additions & 0 deletions iphone/Classes/TiUIiPadSplitWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,55 @@ -(void)setToolbar:(id)items withObject:(id)properties
[(TiUIiPadSplitWindow*)[self view] setToolbar:items withObject:properties];
}

-(void)popupVisibilityChanged:(BOOL)newVal
{
[self replaceValue:NUMBOOL(newVal) forKey:@"masterPopupVisibile" notification:NO];
TiViewProxy* masterProxy = [self valueForUndefinedKey:@"masterView"];
if ([masterProxy isKindOfClass:[TiWindowProxy class]]) {
if (newVal) {
[(TiWindowProxy*) masterProxy gainFocus];
} else {
[(TiWindowProxy*) masterProxy resignFocus];
}
}
}

-(void)gainFocus
{
TiViewProxy* masterProxy = [self valueForUndefinedKey:@"masterView"];
TiViewProxy* detailProxy = [self valueForUndefinedKey:@"detailView"];
if ([detailProxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy*) detailProxy gainFocus];
}

if ([masterProxy isKindOfClass:[TiWindowProxy class]]) {
id showMasterInPortrait = [self valueForUndefinedKey:@"showMasterInPortrait"];
if ([TiUtils boolValue:showMasterInPortrait def:NO]) {
[(TiWindowProxy*) masterProxy gainFocus];
} else {
TiThreadPerformOnMainThread(^{
UIInterfaceOrientation curOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsLandscape(curOrientation)) {
[(TiWindowProxy*) masterProxy gainFocus];
}
}, YES);
}
}
[super gainFocus];
}

-(void)resignFocus
{
TiViewProxy* masterProxy = [self valueForUndefinedKey:@"masterView"];
TiViewProxy* detailProxy = [self valueForUndefinedKey:@"detailView"];
if ([detailProxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy*) detailProxy resignFocus];
}
if ([masterProxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy*) masterProxy resignFocus];
}
[super resignFocus];
}

-(void)setDetailView:(id<NSObject,TiOrientationController>)newDetailView
{
Expand Down Expand Up @@ -139,6 +188,24 @@ -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOr
if ([self viewAttached]) {
[[(TiUIiPadSplitWindow*)[self view] controller] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

if (focussed) {
TiViewProxy* masterProxy = [self valueForUndefinedKey:@"masterView"];
if ([masterProxy isKindOfClass:[TiWindowProxy class]]) {
BOOL showMaster = [TiUtils boolValue:[self valueForUndefinedKey:@"showMasterInPortrait"] def:NO];
if (!showMaster) {
UIInterfaceOrientation curOrientation = [[UIApplication sharedApplication] statusBarOrientation];
showMaster = UIInterfaceOrientationIsLandscape(curOrientation);
}
if (showMaster) {
[(TiWindowProxy*) masterProxy gainFocus];
} else {
[(TiWindowProxy*) masterProxy resignFocus];
}
}

}

[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

Expand Down
6 changes: 2 additions & 4 deletions iphone/Classes/TiWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,8 @@ -(void)viewDidAppear:(BOOL)animated
if (isModal && opening) {
[self windowDidOpen];
}
if (controller != nil) {
if (tab == nil) {
[self gainFocus];
}
if (controller != nil && !self.isManaged) {
[self gainFocus];
}
}
-(void)viewDidDisappear:(BOOL)animated
Expand Down

0 comments on commit 62b0ab3

Please sign in to comment.