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

Commit 113f234

Browse files
wqyfavorjianhan-he
authored andcommitted
[iOS] Screen rotation adjust. Initialize WeexCore before setting page required width and viewportwidth. (#2568)
1 parent a43c768 commit 113f234

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

ios/playground/WeexDemo/WXDemoViewController.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ - (void)viewDidAppear:(BOOL)animated
8282
[self updateInstanceState:WeexInstanceAppear];
8383

8484
AppDelegate* appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
85-
appDelegate.allowRotation = _instance && [_instance isKeepingRawCssStyles];
85+
appDelegate.allowRotation = NO;
86+
[_instance isKeepingRawCssStyles:^(BOOL value) {
87+
appDelegate.allowRotation = value;
88+
}];
8689
}
8790

8891
- (void)viewDidDisappear:(BOOL)animated
@@ -191,7 +194,10 @@ - (void)render
191194
[weakSelf updateInstanceState:WeexInstanceAppear];
192195

193196
AppDelegate* appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
194-
appDelegate.allowRotation = theInstance && [theInstance isKeepingRawCssStyles];
197+
appDelegate.allowRotation = NO;
198+
[theInstance isKeepingRawCssStyles:^(BOOL value) {
199+
appDelegate.allowRotation = value;
200+
}];
195201
};
196202

197203
_instance.updateFinish = ^(UIView *view) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,15 @@ + (CGSize)getDeviceSize
10611061

10621062
+ (void)setViewportWidth:(NSString*)pageId width:(CGFloat)width
10631063
{
1064+
[WXCoreBridge install];
10641065
if (platformBridge) {
10651066
platformBridge->core_side()->SetViewPortWidth([pageId UTF8String] ?: "", (float)width);
10661067
}
10671068
}
10681069

10691070
+ (void)setPageRequired:(NSString *)pageId width:(CGFloat)width height:(CGFloat)height
10701071
{
1072+
[WXCoreBridge install];
10711073
if (platformBridge) {
10721074
platformBridge->core_side()->SetDeviceDisplayOfPage([pageId UTF8String] ?: "", (float)width, (float)height);
10731075
}

ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,25 +367,26 @@ typedef NS_ENUM(NSInteger, WXErrorCode) {//error.code
367367
* internally for later use. Or you can use MetaModule's setPageArguments method and provide "reserveCssStyles" as "true" before rendering the page.
368368
*/
369369
- (void)setPageKeepRawCssStyles;
370-
- (BOOL)isKeepingRawCssStyles;
370+
- (void)isKeepingRawCssStyles:(void(^)(BOOL))callback;
371371

372372
/**
373373
* Set additional argument value for WeexCore
374374
*/
375375
- (void)setPageArgument:(NSString*)key value:(NSString*)value;
376376

377377
/**
378-
* Application required Page Width and Height to prevent Weex use DeviceWidth directly.
378+
* Set specific required page width and height to prevent this page using global values.
379379
*/
380380
- (void)setPageRequiredWidth:(CGFloat)width height:(CGFloat)height;
381381

382+
/**
383+
* Set specific required view port width prevent this page using global value (750px).
384+
*/
382385
- (void)setViewportWidth:(CGFloat)width;
383386

384387
/**
385388
* Deprecated
386389
*/
387-
388-
389390
@property (nonatomic, strong) NSDictionary *properties DEPRECATED_MSG_ATTRIBUTE();
390391
@property (nonatomic, assign) NSTimeInterval networkTime DEPRECATED_MSG_ATTRIBUTE();
391392
@property (nonatomic, copy) void (^updateFinish)(UIView *);

ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,13 @@ - (void)setPageKeepRawCssStyles
223223
[self setPageArgument:@"reserveCssStyles" value:@"true"];
224224
}
225225

226-
- (BOOL)isKeepingRawCssStyles
227-
{
228-
if ([NSThread currentThread] == [WXComponentManager componentThread]) {
229-
return [WXCoreBridge isKeepingRawCssStyles:_instanceId];
230-
}
231-
else {
232-
__block BOOL result = NO;
233-
NSString* pageId = _instanceId;
234-
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
235-
WXPerformBlockOnComponentThread(^{
236-
result = [WXCoreBridge isKeepingRawCssStyles:pageId];
237-
dispatch_semaphore_signal(sem);
238-
});
239-
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
240-
return result;
241-
}
226+
- (void)isKeepingRawCssStyles:(void(^)(BOOL))callback {
227+
NSString* pageId = _instanceId;
228+
WXPerformBlockOnComponentThread(^{
229+
if (callback) {
230+
callback([WXCoreBridge isKeepingRawCssStyles:pageId]);
231+
}
232+
});
242233
}
243234

244235
- (void)setPageArgument:(NSString*)key value:(NSString*)value

0 commit comments

Comments
 (0)