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

Commit 156c966

Browse files
wqyfavorjianhan-he
authored andcommitted
[iOS] Public methods for getting/setting global device size. (#2534)
1 parent 74ea092 commit 156c966

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,13 +1046,15 @@ + (void)setDefaultDimensionIntoRoot:(NSString*)pageId width:(CGFloat)width heigh
10461046

10471047
+ (void)setDeviceSize:(CGSize)size
10481048
{
1049+
[WXCoreBridge install];
10491050
WeexCore::WXCoreEnvironment* env = WeexCore::WXCoreEnvironment::getInstance();
10501051
env->SetDeviceWidth(std::to_string(size.width));
10511052
env->SetDeviceHeight(std::to_string(size.height));
10521053
}
10531054

10541055
+ (CGSize)getDeviceSize
10551056
{
1057+
[WXCoreBridge install];
10561058
WeexCore::WXCoreEnvironment* env = WeexCore::WXCoreEnvironment::getInstance();
10571059
return CGSizeMake(env->DeviceWidth(), env->DeviceHeight());
10581060
}

ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@
215215
*/
216216
+ (void)connectDevToolServer:(NSString *)URL;
217217

218+
/**
219+
* @abstract Set the global device size of all pages.
220+
* You could also set unique device size used by a page using interface of WXSDKInstance.
221+
*
222+
* @param size, the device size in UIKit system.
223+
*
224+
*/
225+
+ (void)setGlobalDeviceSize:(CGSize)size;
226+
227+
/**
228+
* @abstract Get the current global device size used by pages.
229+
*
230+
*/
231+
+ (CGSize)getGlobalDeviceSize;
232+
218233
@end
219234

220235
@interface WXSDKEngine (Deprecated)

ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#import "WXExceptionUtils.h"
4242
#import "WXConfigCenterProtocol.h"
4343
#import "WXComponent+Layout.h"
44+
#import "WXCoreBridge.h"
4445

4546
@implementation WXSDKEngine
4647

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

374+
+ (void)setGlobalDeviceSize:(CGSize)size
375+
{
376+
[WXCoreBridge setDeviceSize:size];
377+
}
378+
379+
+ (CGSize)getGlobalDeviceSize
380+
{
381+
return [WXCoreBridge getDeviceSize];
382+
}
383+
373384
+ (void)_originalRegisterComponents:(NSDictionary *)components {
374385
NSMutableDictionary * mutableComponents = [components mutableCopy];
375386
void (^componentBlock)(id, id, BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {

0 commit comments

Comments
 (0)