diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index 7904f3f8..de194130 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -103,7 +103,7 @@ - (instancetype)init { @"screenWidth": @(screenWidth), @"screenHeight": @(screenHeight), @"screenScale": @([[UIScreen mainScreen] scale]), - @"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height), + @"statusBarHeight": @(systemStatusBarHeight()), @"hasNotch": @(hasNotch()), @"deviceBrand": @"Apple", @"deviceModel": platform, diff --git a/doric-iOS/Pod/Classes/Util/DoricUtil.h b/doric-iOS/Pod/Classes/Util/DoricUtil.h index ab11ac9f..b2ee003a 100644 --- a/doric-iOS/Pod/Classes/Util/DoricUtil.h +++ b/doric-iOS/Pod/Classes/Util/DoricUtil.h @@ -54,6 +54,14 @@ UIImage *_Nonnull UIImageWithColor(UIColor *_Nonnull color); BOOL hasNotch(void); +CGFloat systemStatusBarHeight(void); + +CGFloat statusBarHeightFixed(void); + +BOOL isDynamicIslandDevice(void); + +BOOL isX(void); + #ifdef __cplusplus } #endif diff --git a/doric-iOS/Pod/Classes/Util/DoricUtil.m b/doric-iOS/Pod/Classes/Util/DoricUtil.m index c8bb1f3b..e2eeba4c 100644 --- a/doric-iOS/Pod/Classes/Util/DoricUtil.m +++ b/doric-iOS/Pod/Classes/Util/DoricUtil.m @@ -23,6 +23,7 @@ #import "DoricUtil.h" #import "DoricContext.h" #import "UIView+Doric.h" +#import void DoricLog(NSString *_Nonnull format, ...) { va_list args; @@ -141,3 +142,52 @@ BOOL hasNotch() { return NO; } } + +CGFloat systemStatusBarHeight() { + CGFloat statusBarHeight = 0; + if (@available(iOS 13.0, *)) { + UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager; + statusBarHeight = statusBarManager.statusBarFrame.size.height; + } else { + statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; + } + statusBarHeight = statusBarHeight > 0 ? statusBarHeight : statusBarHeightFixed(); + return statusBarHeight; + +} + +CGFloat statusBarHeightFixed() { + if (isDynamicIslandDevice()) { + return 54.0f; + } + return isX() ? 44.0f : 20.0f; +} + +BOOL isDynamicIslandDevice() { + struct utsname systemInfo; + uname(&systemInfo); + NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding]; + if (TARGET_OS_SIMULATOR == 1) { + platform = [NSProcessInfo new].environment[@"SIMULATOR_MODEL_IDENTIFIER"]; + } + + if ([platform isEqualToString:@"iPhone15,2"] || [platform isEqualToString:@"iPhone15,3"]) { + return YES; + } else { + return NO; + } +} + +BOOL isX() { + BOOL iPhoneXSeries = NO; + if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) { + return iPhoneXSeries; + } + if (@available(iOS 11.0, *)) { + UIWindow *mainWindow = [UIApplication sharedApplication].windows.firstObject; + if (mainWindow.safeAreaInsets.bottom > 0) { + iPhoneXSeries = YES; + } + } + return iPhoneXSeries; +}