You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/05/10 03:35:45 UTC
incubator-weex git commit: [WEEX-347][iOS]fix wrap bug caused by
precision
Repository: incubator-weex
Updated Branches:
refs/heads/master 6d2bdd0c8 -> 59d4c2f0c
[WEEX-347][iOS]fix wrap bug caused by precision
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/59d4c2f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/59d4c2f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/59d4c2f0
Branch: refs/heads/master
Commit: 59d4c2f0cb144d1d70548ea1fa779a3143eb45da
Parents: 6d2bdd0
Author: zouming.zm <zo...@alibaba-inc.com>
Authored: Wed May 9 13:33:09 2018 +0800
Committer: YorkShen <sh...@gmail.com>
Committed: Thu May 10 11:35:26 2018 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/59d4c2f0/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h b/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
index 498c243..522bc8c 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
@@ -9,6 +9,7 @@
#include <iostream>
#include <string>
#include <algorithm>
+#include <cfloat>
namespace WeexCore {
@@ -352,9 +353,24 @@ namespace WeexCore {
}
inline bool isWrapRequired(const float &width, const float &height,
- const float ¤tLength, const float &childLength) const {
- float freeMainSize = calcFreeSpaceAlongMainAxis(width, height, currentLength);
- return !isSingleFlexLine(freeMainSize) && freeMainSize < childLength;
+ const float ¤tLength, const float &childLength) const {
+ float freeMainSize = calcFreeSpaceAlongMainAxis(width, height, currentLength);
+ return !isSingleFlexLine(freeMainSize)
+ && freeMainSize < childLength
+ && !almostEqualRelative(childLength,freeMainSize); //childLength is bigger than freeMainSize but not almost equal (precision)
+ }
+
+ inline bool almostEqualRelative(const float A, const float B) const{
+ float maxRelDiff = FLT_EPSILON;
+ // Calculate the difference.
+ float diff = std::fabs(A - B);
+ float absA = std::fabs(A);
+ float absB = std::fabs(B);
+ // Find the largest
+ float largest = (absB > absA) ? absB : absA;
+
+ if (diff <= largest * maxRelDiff) return true;
+ return false;
}
//If width/height is NAN, ret is NAN, which property we use on purpose.