From 02dfe22389f986ee50d9405bc2ff98c9e107abce Mon Sep 17 00:00:00 2001 From: "huanglei.hl" Date: Thu, 28 Mar 2019 18:19:54 +0800 Subject: [PATCH] [iOS] Support change device width and height by external interface. * feature: used on landscape started apps. --- ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h | 2 ++ ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm | 8 ++++++++ ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h | 5 ++++- ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h index 93689e84e7..a90ad75074 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h @@ -163,6 +163,8 @@ namespace WeexCore + (void)setViewportWidth:(NSString*)pageId width:(CGFloat)width; ++ (void)setPageRequired:(NSString *)pageId width:(CGFloat)width height:(CGFloat)height; + + (void)layoutPage:(NSString*)pageId forced:(BOOL)forced; + (void)closePage:(NSString*)pageId; diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm index 1802d3f3fa..344687968b 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm @@ -845,6 +845,14 @@ + (void)setViewportWidth:(NSString*)pageId width:(CGFloat)width } } ++ (void)setPageRequired:(NSString *)pageId width:(CGFloat)width height:(CGFloat)height +{ + /// Because env is global, pageId is not used now time. + WeexCore::WXCoreEnvironment* env = WeexCore::WXCoreEnvironment::getInstance(); + env->SetDeviceWidth(std::to_string(width)); + env->SetDeviceHeight(std::to_string(height)); +} + + (void)layoutPage:(NSString*)pageId forced:(BOOL)forced { if (platformBridge) { diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h index 87e26f9129..6127745c2a 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h @@ -345,7 +345,10 @@ typedef NS_ENUM(NSInteger, WXErrorCode) {//error.code @property (nonatomic ,strong) WXApmForInstance* apmInstance; - +/** + * Application required Page Width and Height to prevent Weex use DeviceWidth directly. + */ +- (void)setPageRequiredWidth:(CGFloat)width height:(CGFloat)height; /** * Deprecated diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index ee72b35721..96aabee55b 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -210,6 +210,11 @@ - (void)setViewportWidth:(CGFloat)viewportWidth [WXCoreBridge setViewportWidth:_instanceId width:viewportWidth]; } +- (void)setPageRequiredWidth:(CGFloat)width height:(CGFloat)height +{ + [WXCoreBridge setPageRequired:_instanceId width:width height:height]; +} + - (void)renderWithURL:(NSURL *)url { [self renderWithURL:url options:nil data:nil];