You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mo...@apache.org on 2019/04/01 02:51:41 UTC

[incubator-weex] branch master updated: [iOS] Support change device width and height by external interface.

This is an automated email from the ASF dual-hosted git repository.

moshen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 02dfe22  [iOS] Support change device width and height by external interface.
     new 34ef37d  Merge pull request #2263 from sunshl/feature_setpagesize
02dfe22 is described below

commit 02dfe22389f986ee50d9405bc2ff98c9e107abce
Author: huanglei.hl <hu...@alibaba-inc.com>
AuthorDate: Thu Mar 28 18:19:54 2019 +0800

    [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 93689e8..a90ad75 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 1802d3f..3446879 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
@@ -845,6 +845,14 @@ static WeexCore::ScriptBridge* jsBridge = nullptr;
     }
 }
 
++ (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 87e26f9..6127745 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 ee72b35..96aabee 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -210,6 +210,11 @@ typedef enum : NSUInteger {
     [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];