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

Commit

Permalink
[iOS] Fix setViewportWidth on iOS. (#2107)
Browse files Browse the repository at this point in the history
* [iOS] Fix setViewportWidth on iOS.

* [iOS] Add set device size method.
  • Loading branch information
wqyfavor authored and doumafang committed Feb 12, 2019
1 parent 2d9eeb9 commit f4aea82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ namespace WeexCore
isWidthWrapContent:(BOOL)isWidthWrapContent
isHeightWrapContent:(BOOL)isHeightWrapContent;

+ (void)setDeviceSize:(CGSize)size;

+ (void)setViewportWidth:(NSString*)pageId width:(CGFloat)width;

+ (void)layoutPage:(NSString*)pageId forced:(BOOL)forced;
Expand Down Expand Up @@ -204,6 +206,7 @@ namespace WeexCore
+ (void)registerComponentAffineType:(NSString *)type asType:(NSString *)baseType;

+ (BOOL)isComponentAffineType:(NSString *)type asType:(NSString *)baseType;

+ (void)registerCoreEnv:(NSString*)key withValue:(NSString*)value;

@end
Expand Down
7 changes: 7 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,13 @@ + (void)setDefaultDimensionIntoRoot:(NSString*)pageId width:(CGFloat)width heigh
}
}

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

+ (void)setViewportWidth:(NSString*)pageId width:(CGFloat)width
{
if (platformBridge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ void CoreSideInPlatform::MarkDirty(const std::string &instance_id,

void CoreSideInPlatform::SetViewPortWidth(const std::string &instance_id,
float width) {
RenderPage *page = RenderManager::GetInstance()->GetPage(instance_id);
if (page == nullptr) return;

page->set_viewport_width(width);
RenderManager::GetInstance()->set_viewport_width(instance_id, width);
}

void CoreSideInPlatform::SetPageDirty(const std::string &instance_id) {
Expand Down
12 changes: 8 additions & 4 deletions weex_core/Source/core/render/manager/render_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool RenderManager::CreatePage(const std::string& page_id, const char *data) {
std::map<std::string, float>::iterator iter_viewport =
this->viewports_.find(page_id);
if (iter_viewport != this->viewports_.end()) {
this->set_viewport_width(page_id, iter_viewport->second);
page->set_viewport_width(iter_viewport->second);
this->viewports_.erase(page_id);
}

Expand Down Expand Up @@ -82,7 +82,7 @@ bool RenderManager::CreatePage(const std::string& page_id, RenderObject *root) {
std::map<std::string, float>::iterator iter =
this->viewports_.find(page_id);
if (iter != this->viewports_.end()) {
RenderManager::GetInstance()->set_viewport_width(page_id, iter->second);
page->set_viewport_width(iter->second);
this->viewports_.erase(page_id);
}

Expand All @@ -101,7 +101,7 @@ bool RenderManager::CreatePage(const std::string& page_id, std::function<RenderO
std::map<std::string, float>::iterator iter =
this->viewports_.find(page_id);
if (iter != this->viewports_.end()) {
RenderManager::GetInstance()->set_viewport_width(page_id, iter->second);
page->set_viewport_width(iter->second);
this->viewports_.erase(page_id);
}

Expand Down Expand Up @@ -371,7 +371,11 @@ float RenderManager::viewport_width(const std::string &page_id) {

void RenderManager::set_viewport_width(const std::string &page_id, float viewport_width) {
RenderPage *page = GetPage(page_id);
if (page == nullptr) return;
if (page == nullptr) {
// page is not created yet, we should store the view port value
viewports_.insert(std::pair<std::string, float>(page_id, viewport_width));
return;
}

page->set_viewport_width(viewport_width);
}
Expand Down

0 comments on commit f4aea82

Please sign in to comment.