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

Commit

Permalink
* [iOS] layoutEngin Fix text height problem. (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-chen authored and YorkShen committed Aug 9, 2018
1 parent 539621f commit 6f16af7
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "WXCoreLayout.h"
#include <tuple>

using namespace WeexCore;

Expand Down Expand Up @@ -192,7 +193,14 @@ namespace WeexCore {
(widthMeasureMode == kUnspecified
|| heightMeasureMode == kUnspecified)) {
float constrainsWidth = width;
if(widthMeasureMode == kExactly && !isnan(width)){
if(isnan(width)){
if(!isnan(mCssStyle->mMaxWidth)){
constrainsWidth = mCssStyle->mMaxWidth;
}
}

if((!isnan(width)&&widthMeasureMode == kExactly) ||
(isnan(width) && !isnan(mCssStyle->mMaxWidth))) {
constrainsWidth -= sumPaddingBorderAlongAxis(this, true);
}
WXCoreSize dimension = measureFunc(this, constrainsWidth,
Expand Down Expand Up @@ -240,7 +248,6 @@ namespace WeexCore {
}
}


/**
* @param flexDirection the flex direction attribute
* @param width stylewidth by this node
Expand Down Expand Up @@ -335,9 +342,11 @@ namespace WeexCore {
child->hypotheticalMeasure(childWidth, childHeight, stretch);
} else {
if(isSingleFlexLine(isMainAxisHorizontal(this) ? parentWidth : parentHeight)
&& !isMainAxisHorizontal(this) && child->widthMeasureMode == kUnspecified){
child->setLayoutWidth(parentWidth - sumPaddingBorderAlongAxis(this, true)
-child->mCssStyle->sumMarginOfDirection(true));
&& !isMainAxisHorizontal(this)){
if(child->widthMeasureMode == kUnspecified) {
child->setLayoutWidth(parentWidth - sumPaddingBorderAlongAxis(this, true)
- child->mCssStyle->sumMarginOfDirection(true));
}
if(child->heightMeasureMode == kUnspecified && child->widthDirty) {
child->mLayoutResult->mLayoutSize.height = NAN;
}
Expand Down Expand Up @@ -464,6 +473,11 @@ namespace WeexCore {
if (isMainAxisHorizontal(this)) {
child->setWidthMeasureMode(kExactly);
child->setLayoutWidth(childMainSize);
//TODO Fix https://jsplayground.taobao.org/raxplayground/97efee70-775f-45a6-b07d-d84c8d1b4387
//TODO This is just a temporary fix, we need to make things beauty and clean.
if(child->heightMeasureMode == kUnspecified && child->measureFunc != nullptr && child->getChildCount() == 0){
child->setLayoutHeight(NAN);
}
} else {
child->setHeightMeasureMode(kExactly);
child->setLayoutHeight(childMainSize);
Expand Down Expand Up @@ -494,10 +508,11 @@ namespace WeexCore {

void WXCoreLayoutNode::stretchViewCrossSize(WXCoreLayoutNode* const child, float crossSize){
if (isMainAxisHorizontal(this)) {
if (child->heightMeasureMode != kExactly) {
crossSize -=
child->mCssStyle->mMargin.getMargin(kMarginTop) +
child->mCssStyle->mMargin.getMargin(kMarginBottom);
if (child->heightMeasureMode != kExactly &&
!(child->measureFunc != nullptr && child->getChildCount() == 0)) {
crossSize -=
child->mCssStyle->mMargin.getMargin(kMarginTop) +
child->mCssStyle->mMargin.getMargin(kMarginBottom);
child->setHeightMeasureMode(kExactly);
child->setLayoutHeight(std::max(0.f, crossSize));
}
Expand Down

0 comments on commit 6f16af7

Please sign in to comment.