mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-31 10:35:41 +08:00
ios: Use a persistent callbackId instead of calling sendJs
This commit is contained in:
parent
f0031ca2b4
commit
be8a3e5947
@ -23,12 +23,10 @@
|
|||||||
@interface CDVStatusBar : CDVPlugin {
|
@interface CDVStatusBar : CDVPlugin {
|
||||||
@protected
|
@protected
|
||||||
BOOL _statusBarOverlaysWebView;
|
BOOL _statusBarOverlaysWebView;
|
||||||
@protected
|
|
||||||
UIView* _statusBarBackgroundView;
|
UIView* _statusBarBackgroundView;
|
||||||
@protected
|
|
||||||
BOOL _uiviewControllerBasedStatusBarAppearance;
|
BOOL _uiviewControllerBasedStatusBarAppearance;
|
||||||
@protected
|
|
||||||
UIColor* _statusBarBackgroundColor;
|
UIColor* _statusBarBackgroundColor;
|
||||||
|
NSString* _eventsCallbackId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (atomic, assign) BOOL statusBarOverlaysWebView;
|
@property (atomic, assign) BOOL statusBarOverlaysWebView;
|
||||||
|
@ -70,8 +70,9 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface CDVStatusBar () <
|
@interface CDVStatusBar () <UIScrollViewDelegate>
|
||||||
UIScrollViewDelegate>
|
- (void)fireTappedEvent;
|
||||||
|
- (void)updateIsVisible:(BOOL)visible;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CDVStatusBar
|
@implementation CDVStatusBar
|
||||||
@ -85,9 +86,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
{
|
{
|
||||||
if ([keyPath isEqual:@"statusBarHidden"]) {
|
if ([keyPath isEqual:@"statusBarHidden"]) {
|
||||||
NSNumber* newValue = [change objectForKey:NSKeyValueChangeNewKey];
|
NSNumber* newValue = [change objectForKey:NSKeyValueChangeNewKey];
|
||||||
BOOL boolValue = [newValue boolValue];
|
[self updateIsVisible:![newValue boolValue]];
|
||||||
|
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", boolValue? @"false" : @"true" ]];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,10 +135,34 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
fakeScrollView.contentOffset = CGPointMake(0.0f, UIScreen.mainScreen.bounds.size.height); // Scroll down so a tap will take scroll view back to the top
|
fakeScrollView.contentOffset = CGPointMake(0.0f, UIScreen.mainScreen.bounds.size.height); // Scroll down so a tap will take scroll view back to the top
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)onReset {
|
||||||
|
_eventsCallbackId = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)fireTappedEvent {
|
||||||
|
if (_eventsCallbackId == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSDictionary* payload = @{@"type": @"tap"};
|
||||||
|
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:payload];
|
||||||
|
[result setKeepCallbackAsBool:YES];
|
||||||
|
[self.commandDelegate sendPluginResult:result callbackId:_eventsCallbackId];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)updateIsVisible:(BOOL)visible {
|
||||||
|
if (_eventsCallbackId == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:visible];
|
||||||
|
[result setKeepCallbackAsBool:YES];
|
||||||
|
[self.commandDelegate sendPluginResult:result callbackId:_eventsCallbackId];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) _ready:(CDVInvokedUrlCommand*)command
|
- (void) _ready:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
// set the initial value
|
_eventsCallbackId = command.callbackId;
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", [UIApplication sharedApplication].statusBarHidden? @"false" : @"true" ]];
|
[self updateIsVisible:![UIApplication sharedApplication].statusBarHidden];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) initializeStatusBarBackgroundView
|
- (void) initializeStatusBarBackgroundView
|
||||||
@ -429,7 +452,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
|
|
||||||
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
|
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
|
||||||
{
|
{
|
||||||
[self.webView stringByEvaluatingJavaScriptFromString:@"var evt = document.createEvent(\"Event\"); evt.initEvent(\"statusTap\",true,true); window.dispatchEvent(evt);"];
|
[self fireTappedEvent];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,13 @@ var StatusBar = {
|
|||||||
|
|
||||||
// prime it
|
// prime it
|
||||||
exec(function (res) {
|
exec(function (res) {
|
||||||
|
if (typeof res == 'object') {
|
||||||
|
if (res.type == 'tap') {
|
||||||
|
cordova.fireWindowEvent('statusTap');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
StatusBar.isVisible = res;
|
StatusBar.isVisible = res;
|
||||||
|
}
|
||||||
}, null, "StatusBar", "_ready", []);
|
}, null, "StatusBar", "_ready", []);
|
||||||
|
|
||||||
module.exports = StatusBar;
|
module.exports = StatusBar;
|
||||||
|
Loading…
Reference in New Issue
Block a user