From f0031ca2b4d778d8feea1959ec1fd8773ad39872 Mon Sep 17 00:00:00 2001 From: Tiancheng Zhu Date: Thu, 10 Apr 2014 16:56:24 -0700 Subject: [PATCH] CB-6626 ios: Add a JS event for tapping on statusbar close #4 --- src/ios/CDVStatusBar.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m index e773397..98f2285 100644 --- a/src/ios/CDVStatusBar.m +++ b/src/ios/CDVStatusBar.m @@ -70,6 +70,10 @@ static const void *kStatusBarStyle = &kStatusBarStyle; @end +@interface CDVStatusBar () < + UIScrollViewDelegate> +@end + @implementation CDVStatusBar - (id)settingForKey:(NSString*)key @@ -120,6 +124,16 @@ static const void *kStatusBarStyle = &kStatusBarStyle; if ([self settingForKey:setting]) { [self setStatusBarStyle:[self settingForKey:setting]]; } + + // blank scroll view to intercept status bar taps + self.webView.scrollView.scrollsToTop = NO; + UIScrollView *fakeScrollView = [[UIScrollView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + fakeScrollView.delegate = self; + fakeScrollView.scrollsToTop = YES; + [self.viewController.view addSubview:fakeScrollView]; // Add scrollview to the view heirarchy so that it will begin accepting status bar taps + [self.viewController.view sendSubviewToBack:fakeScrollView]; // Send it to the very back of the view heirarchy + fakeScrollView.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height * 2.0f); // Make the scroll view longer than the screen itself + fakeScrollView.contentOffset = CGPointMake(0.0f, UIScreen.mainScreen.bounds.size.height); // Scroll down so a tap will take scroll view back to the top } - (void) _ready:(CDVInvokedUrlCommand*)command @@ -411,4 +425,12 @@ static const void *kStatusBarStyle = &kStatusBarStyle; } +#pragma mark - UIScrollViewDelegate + +- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView +{ + [self.webView stringByEvaluatingJavaScriptFromString:@"var evt = document.createEvent(\"Event\"); evt.initEvent(\"statusTap\",true,true); window.dispatchEvent(evt);"]; + return NO; +} + @end