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

Commit

Permalink
[iOS] Screen rotation adjust. Initialize WeexCore before setting page…
Browse files Browse the repository at this point in the history
… required width and viewportwidth. (#2568)
  • Loading branch information
wqyfavor authored and jianhan-he committed Jun 18, 2019
1 parent a43c768 commit 113f234
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 8 additions & 2 deletions ios/playground/WeexDemo/WXDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ - (void)viewDidAppear:(BOOL)animated
[self updateInstanceState:WeexInstanceAppear];

AppDelegate* appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.allowRotation = _instance && [_instance isKeepingRawCssStyles];
appDelegate.allowRotation = NO;
[_instance isKeepingRawCssStyles:^(BOOL value) {
appDelegate.allowRotation = value;
}];
}

- (void)viewDidDisappear:(BOOL)animated
Expand Down Expand Up @@ -191,7 +194,10 @@ - (void)render
[weakSelf updateInstanceState:WeexInstanceAppear];

AppDelegate* appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.allowRotation = theInstance && [theInstance isKeepingRawCssStyles];
appDelegate.allowRotation = NO;
[theInstance isKeepingRawCssStyles:^(BOOL value) {
appDelegate.allowRotation = value;
}];
};

_instance.updateFinish = ^(UIView *view) {
Expand Down
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 @@ -1061,13 +1061,15 @@ + (CGSize)getDeviceSize

+ (void)setViewportWidth:(NSString*)pageId width:(CGFloat)width
{
[WXCoreBridge install];
if (platformBridge) {
platformBridge->core_side()->SetViewPortWidth([pageId UTF8String] ?: "", (float)width);
}
}

+ (void)setPageRequired:(NSString *)pageId width:(CGFloat)width height:(CGFloat)height
{
[WXCoreBridge install];
if (platformBridge) {
platformBridge->core_side()->SetDeviceDisplayOfPage([pageId UTF8String] ?: "", (float)width, (float)height);
}
Expand Down
9 changes: 5 additions & 4 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,26 @@ typedef NS_ENUM(NSInteger, WXErrorCode) {//error.code
* internally for later use. Or you can use MetaModule's setPageArguments method and provide "reserveCssStyles" as "true" before rendering the page.
*/
- (void)setPageKeepRawCssStyles;
- (BOOL)isKeepingRawCssStyles;
- (void)isKeepingRawCssStyles:(void(^)(BOOL))callback;

/**
* Set additional argument value for WeexCore
*/
- (void)setPageArgument:(NSString*)key value:(NSString*)value;

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

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

/**
* Deprecated
*/


@property (nonatomic, strong) NSDictionary *properties DEPRECATED_MSG_ATTRIBUTE();
@property (nonatomic, assign) NSTimeInterval networkTime DEPRECATED_MSG_ATTRIBUTE();
@property (nonatomic, copy) void (^updateFinish)(UIView *);
Expand Down
23 changes: 7 additions & 16 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,13 @@ - (void)setPageKeepRawCssStyles
[self setPageArgument:@"reserveCssStyles" value:@"true"];
}

- (BOOL)isKeepingRawCssStyles
{
if ([NSThread currentThread] == [WXComponentManager componentThread]) {
return [WXCoreBridge isKeepingRawCssStyles:_instanceId];
}
else {
__block BOOL result = NO;
NSString* pageId = _instanceId;
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
WXPerformBlockOnComponentThread(^{
result = [WXCoreBridge isKeepingRawCssStyles:pageId];
dispatch_semaphore_signal(sem);
});
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
return result;
}
- (void)isKeepingRawCssStyles:(void(^)(BOOL))callback {
NSString* pageId = _instanceId;
WXPerformBlockOnComponentThread(^{
if (callback) {
callback([WXCoreBridge isKeepingRawCssStyles:pageId]);
}
});
}

- (void)setPageArgument:(NSString*)key value:(NSString*)value
Expand Down

0 comments on commit 113f234

Please sign in to comment.