2015-03-23 13:28:42 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-19 20:10:52 -08:00
|
|
|
|
|
|
|
#import "RCTStatusBarManager.h"
|
|
|
|
|
2015-08-19 12:37:53 -01:00
|
|
|
#import "RCTEventDispatcher.h"
|
2015-02-19 20:10:52 -08:00
|
|
|
#import "RCTLog.h"
|
2015-09-22 10:43:56 -07:00
|
|
|
#import "RCTUtils.h"
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2015-06-05 08:46:17 -07:00
|
|
|
@implementation RCTConvert (UIStatusBar)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(UIStatusBarStyle, (@{
|
|
|
|
@"default": @(UIStatusBarStyleDefault),
|
|
|
|
@"light-content": @(UIStatusBarStyleLightContent),
|
|
|
|
}), UIStatusBarStyleDefault, integerValue);
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(UIStatusBarAnimation, (@{
|
|
|
|
@"none": @(UIStatusBarAnimationNone),
|
|
|
|
@"fade": @(UIStatusBarAnimationFade),
|
|
|
|
@"slide": @(UIStatusBarAnimationSlide),
|
|
|
|
}), UIStatusBarAnimationNone, integerValue);
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
@implementation RCTStatusBarManager
|
|
|
|
|
|
|
|
static BOOL RCTViewControllerBasedStatusBarAppearance()
|
|
|
|
{
|
|
|
|
static BOOL value;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
2015-06-05 08:46:17 -07:00
|
|
|
value = [[[NSBundle mainBundle] objectForInfoDictionaryKey:
|
|
|
|
@"UIViewControllerBasedStatusBarAppearance"] ?: @YES boolValue];
|
2015-02-19 20:10:52 -08:00
|
|
|
});
|
2015-03-10 19:03:59 -07:00
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-04-08 05:42:43 -07:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-08-19 12:37:53 -01:00
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
2016-05-04 07:06:09 -07:00
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
// We're only overriding this to ensure the module gets created at startup
|
|
|
|
// TODO (t11106126): Remove once we have more declarative control over module setup.
|
|
|
|
return [super init];
|
|
|
|
}
|
|
|
|
|
2015-11-25 03:09:00 -08:00
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
2015-08-19 12:37:53 -01:00
|
|
|
{
|
2015-11-25 03:09:00 -08:00
|
|
|
_bridge = bridge;
|
|
|
|
|
2016-05-04 07:06:09 -07:00
|
|
|
// TODO: if we add an explicit "startObserving" method, we can take this out
|
|
|
|
// of the application startup path
|
|
|
|
|
2015-11-25 03:09:00 -08:00
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc addObserver:self selector:@selector(applicationDidChangeStatusBarFrame:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
|
|
|
|
[nc addObserver:self selector:@selector(applicationWillChangeStatusBarFrame:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
|
2015-08-19 12:37:53 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
2015-04-20 12:06:02 -07:00
|
|
|
- (dispatch_queue_t)methodQueue
|
|
|
|
{
|
|
|
|
return dispatch_get_main_queue();
|
|
|
|
}
|
|
|
|
|
2015-08-19 12:37:53 -01:00
|
|
|
- (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
CGRect frame = [notification.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue];
|
|
|
|
NSDictionary *event = @{
|
|
|
|
@"frame": @{
|
2015-11-16 03:15:31 -08:00
|
|
|
@"x": @(frame.origin.x),
|
|
|
|
@"y": @(frame.origin.y),
|
|
|
|
@"width": @(frame.size.width),
|
|
|
|
@"height": @(frame.size.height),
|
2015-08-19 12:37:53 -01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
[_bridge.eventDispatcher sendDeviceEventWithName:eventName body:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidChangeStatusBarFrame:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self emitEvent:@"statusBarFrameDidChange" forNotification:notification];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self emitEvent:@"statusBarFrameWillChange" forNotification:notification];
|
|
|
|
}
|
|
|
|
|
2016-01-04 04:30:37 -08:00
|
|
|
RCT_EXPORT_METHOD(getHeight:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
callback(@[@{
|
|
|
|
@"height": @([UIApplication sharedApplication].statusBarFrame.size.height),
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
2015-04-08 08:52:48 -07:00
|
|
|
RCT_EXPORT_METHOD(setStyle:(UIStatusBarStyle)statusBarStyle
|
|
|
|
animated:(BOOL)animated)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2015-04-18 10:43:20 -07:00
|
|
|
if (RCTViewControllerBasedStatusBarAppearance()) {
|
|
|
|
RCTLogError(@"RCTStatusBarManager module requires that the \
|
|
|
|
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
|
|
|
|
} else {
|
2015-09-22 10:43:56 -07:00
|
|
|
[RCTSharedApplication() setStatusBarStyle:statusBarStyle
|
|
|
|
animated:animated];
|
2015-04-18 10:43:20 -07:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
|
|
|
|
2015-04-08 08:52:48 -07:00
|
|
|
RCT_EXPORT_METHOD(setHidden:(BOOL)hidden
|
|
|
|
withAnimation:(UIStatusBarAnimation)animation)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2015-04-18 10:43:20 -07:00
|
|
|
if (RCTViewControllerBasedStatusBarAppearance()) {
|
|
|
|
RCTLogError(@"RCTStatusBarManager module requires that the \
|
|
|
|
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
|
|
|
|
} else {
|
2015-09-22 10:43:56 -07:00
|
|
|
[RCTSharedApplication() setStatusBarHidden:hidden
|
|
|
|
withAnimation:animation];
|
2015-04-18 10:43:20 -07:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
|
|
|
|
2015-07-23 16:19:27 -07:00
|
|
|
RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible:(BOOL)visible)
|
|
|
|
{
|
2015-09-22 10:43:56 -07:00
|
|
|
RCTSharedApplication().networkActivityIndicatorVisible = visible;
|
2015-07-23 16:19:27 -07:00
|
|
|
}
|
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
@end
|