Skip to content

Commit

Permalink
Merge pull request #219 from kbshl/fix-ios-statusbar-handling
Browse files Browse the repository at this point in the history
iOS: Fix statusbar style handling (#56 / #13)
  • Loading branch information
hansemannn authored Jul 13, 2018
2 parents 5567e5b + 9a42c08 commit 4223428
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 31 deletions.
90 changes: 71 additions & 19 deletions ios/Classes/DkNappDrawerDrawer.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

@implementation DkNappDrawerDrawer

#pragma mark - Accessibility

- (id)accessibilityElement
{
return controllerView_;
Expand Down Expand Up @@ -82,6 +84,8 @@ - (NSInteger)indexOfAccessibilityElement:(id)element
return [[self accessibleElements] indexOfObject:element];
}

#pragma mark - Init

- (MMDrawerController *)controller
{
if (controller == nil) {
Expand All @@ -100,23 +104,59 @@ - (MMDrawerController *)controller
__weak __typeof__(self) weakSelf = self;

if (leftWindow != nil) {

//both left and right
if (rightWindow != nil) {
//both left and right

TiViewController *leftController = ControllerForViewProxy(leftWindow);
TiViewController *rightController = ControllerForViewProxy(rightWindow);

TiUIiOSNavWindowProxy *centerProxy = [self.proxy valueForUndefinedKey:@"centerWindow"];

TiThreadPerformOnMainThread(^{
[centerProxy windowWillOpen];
[centerProxy windowDidOpen];
},
YES);

controller = [[CustomMMDrawerController alloc] initWithCenterViewController:centerWindow
leftDrawerViewController:ControllerForViewProxy(leftWindow)
rightDrawerViewController:ControllerForViewProxy(rightWindow)];
} else {
leftDrawerViewController:leftController
rightDrawerViewController:rightController];
//left only
} else {

TiViewController *leftController = ControllerForViewProxy(leftWindow);

TiUIiOSNavWindowProxy *centerProxy = [self.proxy valueForUndefinedKey:@"centerWindow"];

TiThreadPerformOnMainThread(^{
[centerProxy windowWillOpen];
[centerProxy windowDidOpen];
},
YES);

controller = [[CustomMMDrawerController alloc] initWithCenterViewController:centerWindow
leftDrawerViewController:ControllerForViewProxy(leftWindow)];
leftDrawerViewController:leftController];
}
} else if (rightWindow != nil) {
//right only
} else if (rightWindow != nil) {

TiViewController *rightController = ControllerForViewProxy(rightWindow);

TiUIiOSNavWindowProxy *centerProxy = [self.proxy valueForUndefinedKey:@"centerWindow"];

TiThreadPerformOnMainThread(^{
[centerProxy windowWillOpen];
[centerProxy windowDidOpen];
},
YES);

controller = [[CustomMMDrawerController alloc] initWithCenterViewController:centerWindow
rightDrawerViewController:ControllerForViewProxy(rightWindow)];
} else {
rightDrawerViewController:rightController];

//error
NSLog(@"[ERROR] NappDrawer: No windows assigned");
} else {
NSLog(@"[ERROR][DkNappDrawerDrawer] No windows assigned");
return nil;
}

Expand Down Expand Up @@ -174,7 +214,7 @@ - (MMDrawerController *)controller
} else if ([state isEqualToString:@"close"]) {
[[strongSelf proxy] fireEvent:@"windowDidClose"];
}

[strongSelf _fireStateEventForCurrentState];
}];

Expand Down Expand Up @@ -213,7 +253,7 @@ - (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
[super frameSizeChanged:frame bounds:bounds];
}

// PROPERTIES
#pragma mark - Properties

- (void)setCenterWindow_:(id)args
{
Expand All @@ -223,12 +263,21 @@ - (void)setCenterWindow_:(id)args
useNavController = YES;
}
UIViewController *centerWindow = useNavController ? NavigationControllerForViewProxy([self.proxy valueForUndefinedKey:@"centerWindow"]) : ControllerForViewProxy([self.proxy valueForUndefinedKey:@"centerWindow"]);
if (useNavController) {
TiUIiOSNavWindowProxy *centerProxy = [self.proxy valueForUndefinedKey:@"centerWindow"];

if (controller != nil) {
[centerProxy windowWillOpen];
[centerProxy windowDidOpen];
}
}

[controller setCenterViewController:centerWindow];

// Cleanup
if (useNavController) {
if (navProxy != nil) {
NSLog(@"[DEBUG| Destroying old nav proxy");
[navProxy windowWillClose];
[navProxy windowDidClose];
}
// Save new proxy
Expand Down Expand Up @@ -329,11 +378,12 @@ - (void)setShowsStatusBarBackgroundView_:(id)args

- (UIStatusBarStyle)preferredStatusBarStyle
{
if (self.controller.showsStatusBarBackgroundView) {
return UIStatusBarStyleLightContent;
} else {
return UIStatusBarStyleDefault;
}
return [controller preferredStatusBarStyle];
}

- (UIViewController *)childViewControllerForStatusBarStyle
{
return nil;
}

- (void)setStatusBarStyle_:(NSNumber *)style
Expand All @@ -354,7 +404,6 @@ - (void)setAnimationMode_:(id)args
[controller setDrawerVisualStateBlock:[NappDrawerVisualState slideVisualStateBlock]];
break;
case 3:
//[controller setDrawerVisualStateBlock:[NappDrawerVisualState swingingDoorVisualStateBlock]];
[controller setDrawerVisualStateBlock:[NappDrawerVisualState noneVisualStateBlock]];
break;
case 4:
Expand All @@ -377,7 +426,8 @@ - (void)setAnimationMode_:(id)args
}
}

// API
#pragma mark - API

- (void)toggleLeftWindow:(id)args
{
ENSURE_UI_THREAD(toggleLeftWindow, args);
Expand Down Expand Up @@ -417,6 +467,8 @@ - (NSNumber *)isRightWindowOpen:(id)args
return NUMBOOL(controller.openSide == MMDrawerSideRight);
}

#pragma mark - Events

// Little hack to propagate focus/blur events
- (void)_fireStateEventForCurrentState
{
Expand Down
10 changes: 10 additions & 0 deletions ios/Classes/DkNappDrawerDrawerProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ - (TiUIView *)newView
return [[DkNappDrawerDrawer alloc] init];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return [[self _controller] preferredStatusBarStyle];
}

- (UIViewController *)childViewControllerForStatusBarStyle
{
return nil;
}

#pragma API

- (void)toggleLeftWindow:(id)args
Expand Down
1 change: 0 additions & 1 deletion ios/Classes/DkNappDrawerModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ - (NSString *)moduleId
- (void)startup
{
[super startup];
NSLog(@"[DEBUG] %@ loaded", self);
}

#pragma Public APIs
Expand Down
4 changes: 1 addition & 3 deletions ios/Classes/DkNappDrawerModuleAssets.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
*/
#import "DkNappDrawerModuleAssets.h"

extern NSData* filterDataInRange(NSData* thedata, NSRange range);
extern NSData *filterDataInRange(NSData *thedata, NSRange range);

@implementation DkNappDrawerModuleAssets

- (NSData *)moduleAsset
{


return nil;
}

- (NSData *)resolveModuleAsset:(NSString *)path
{


return nil;
}
Expand Down
7 changes: 0 additions & 7 deletions ios/Classes/NappDrawerVisualState.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ @implementation NappDrawerVisualState
+ (MMDrawerControllerDrawerVisualStateBlock)slideAndScaleVisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand Down Expand Up @@ -48,7 +47,6 @@ + (MMDrawerControllerDrawerVisualStateBlock)slideAndScaleVisualStateBlock
+ (MMDrawerControllerDrawerVisualStateBlock)swingingDoorVisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand Down Expand Up @@ -110,7 +108,6 @@ + (MMDrawerControllerDrawerVisualStateBlock)swingingDoorVisualStateBlock
+ (MMDrawerControllerDrawerVisualStateBlock)fadeVisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand All @@ -136,7 +133,6 @@ + (MMDrawerControllerDrawerVisualStateBlock)noneVisualStateBlock
+ (MMDrawerControllerDrawerVisualStateBlock)slideVisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand Down Expand Up @@ -177,7 +173,6 @@ + (MMDrawerControllerDrawerVisualStateBlock)slideVisualStateBlock
+ (MMDrawerControllerDrawerVisualStateBlock)parallax3VisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand Down Expand Up @@ -217,7 +212,6 @@ + (MMDrawerControllerDrawerVisualStateBlock)parallax3VisualStateBlock
+ (MMDrawerControllerDrawerVisualStateBlock)parallax5VisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand Down Expand Up @@ -258,7 +252,6 @@ + (MMDrawerControllerDrawerVisualStateBlock)parallax5VisualStateBlock
+ (MMDrawerControllerDrawerVisualStateBlock)parallax7VisualStateBlock
{
MMDrawerControllerDrawerVisualStateBlock visualStateBlock = ^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {

if (drawerSide == MMDrawerSideNone) {
return;
}
Expand Down
Binary file added ios/dist/dk.napp.drawer-iphone-2.1.1.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.1.0
version: 2.1.1
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Drawer controller
Expand Down

0 comments on commit 4223428

Please sign in to comment.