[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Public methods for getting/setting global device size. (#2534)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and jianhan-he committed Jun 12, 2019
1 parent 74ea092 commit 156c966
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1046,13 +1046,15 @@ + (void)setDefaultDimensionIntoRoot:(NSString*)pageId width:(CGFloat)width heigh

+ (void)setDeviceSize:(CGSize)size
{
[WXCoreBridge install];
WeexCore::WXCoreEnvironment* env = WeexCore::WXCoreEnvironment::getInstance();
env->SetDeviceWidth(std::to_string(size.width));
env->SetDeviceHeight(std::to_string(size.height));
}

+ (CGSize)getDeviceSize
{
[WXCoreBridge install];
WeexCore::WXCoreEnvironment* env = WeexCore::WXCoreEnvironment::getInstance();
return CGSizeMake(env->DeviceWidth(), env->DeviceHeight());
}
Expand Down
15 changes: 15 additions & 0 deletions ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@
*/
+ (void)connectDevToolServer:(NSString *)URL;

/**
* @abstract Set the global device size of all pages.
* You could also set unique device size used by a page using interface of WXSDKInstance.
*
* @param size, the device size in UIKit system.
*
*/
+ (void)setGlobalDeviceSize:(CGSize)size;

/**
* @abstract Get the current global device size used by pages.
*
*/
+ (CGSize)getGlobalDeviceSize;

@end

@interface WXSDKEngine (Deprecated)
Expand Down
11 changes: 11 additions & 0 deletions ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#import "WXExceptionUtils.h"
#import "WXConfigCenterProtocol.h"
#import "WXComponent+Layout.h"
#import "WXCoreBridge.h"

@implementation WXSDKEngine

Expand Down Expand Up @@ -370,6 +371,16 @@ + (void)connectDevToolServer:(NSString *)URL
[[WXSDKManager bridgeMgr] connectToDevToolWithUrl:[NSURL URLWithString:URL]];
}

+ (void)setGlobalDeviceSize:(CGSize)size
{
[WXCoreBridge setDeviceSize:size];
}

+ (CGSize)getGlobalDeviceSize
{
return [WXCoreBridge getDeviceSize];
}

+ (void)_originalRegisterComponents:(NSDictionary *)components {
NSMutableDictionary * mutableComponents = [components mutableCopy];
void (^componentBlock)(id, id, BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {
Expand Down

0 comments on commit 156c966

Please sign in to comment.