mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 23:24:06 +08:00
Set padding on ModalFullscreenView to offset status bar frame
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#import "RCTStatusBarManager.h"
|
||||
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTLog.h"
|
||||
|
||||
@implementation RCTConvert (UIStatusBar)
|
||||
@@ -42,11 +43,53 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc addObserver:self selector:@selector(applicationDidChangeStatusBarFrame:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
|
||||
[nc addObserver:self selector:@selector(applicationWillChangeStatusBarFrame:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
{
|
||||
return dispatch_get_main_queue();
|
||||
}
|
||||
|
||||
- (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notification
|
||||
{
|
||||
CGRect frame = [notification.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue];
|
||||
NSDictionary *event = @{
|
||||
@"frame": @{
|
||||
@"x": @(frame.origin.x),
|
||||
@"y": @(frame.origin.y),
|
||||
@"width": @(frame.size.width),
|
||||
@"height": @(frame.size.height),
|
||||
},
|
||||
};
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:eventName body:event];
|
||||
}
|
||||
|
||||
- (void)applicationDidChangeStatusBarFrame:(NSNotification *)notification
|
||||
{
|
||||
[self emitEvent:@"statusBarFrameDidChange" forNotification:notification];
|
||||
}
|
||||
|
||||
- (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
|
||||
{
|
||||
[self emitEvent:@"statusBarFrameWillChange" forNotification:notification];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setStyle:(UIStatusBarStyle)statusBarStyle
|
||||
animated:(BOOL)animated)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user