From 3d656e13c64fcad14ef89be62ef7417db8586102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 25 Aug 2020 17:15:21 +0800 Subject: [PATCH] iOS: pick width & height as default constant in portrait orientation --- doric-iOS/Pod/Classes/Engine/DoricJSEngine.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index e28a5ed0..4606a97d 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -62,13 +62,25 @@ - (instancetype)init { if (TARGET_OS_SIMULATOR == 1) { platform = [NSProcessInfo new].environment[@"SIMULATOR_MODEL_IDENTIFIER"]; } + + UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; + CGFloat screenWidth; + CGFloat screenHeight; + if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { + screenWidth = [[UIScreen mainScreen] bounds].size.width; + screenHeight = [[UIScreen mainScreen] bounds].size.height; + } else { + screenWidth = [[UIScreen mainScreen] bounds].size.height; + screenHeight = [[UIScreen mainScreen] bounds].size.width; + } + _innerEnvironmentDictionary = @{ @"platform": @"iOS", @"platformVersion": [[UIDevice currentDevice] systemVersion], @"appName": infoDictionary[@"CFBundleName"], @"appVersion": infoDictionary[@"CFBundleShortVersionString"], - @"screenWidth": @([[UIScreen mainScreen] bounds].size.width), - @"screenHeight": @([[UIScreen mainScreen] bounds].size.height), + @"screenWidth": @(screenWidth), + @"screenHeight": @(screenHeight), @"screenScale": @([[UIScreen mainScreen] scale]), @"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height), @"hasNotch": @(hasNotch()),