Skip to content

Commit

Permalink
Merge pull request #62 from zintus/yoga-core
Browse files Browse the repository at this point in the history
[WIP] Update yoga core to latest master
  • Loading branch information
lucdion authored Feb 27, 2018
2 parents df3eee6 + e4dba12 commit 7b9e498
Show file tree
Hide file tree
Showing 477 changed files with 188,012 additions and 3,929 deletions.
2 changes: 2 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[cxx]
gtest_dep = //lib/gtest:gtest
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ Carthage/Build/iOS/*.dSYM
Carthage/Build/iOS/*.bcsymbolmap
Carthage/Build/tvOS
Carthage/Checkouts

# Buck
/buck-cache/
/buck-out/
/.buckconfig.local
/.buckd
/gentest/test.html
.buckversion
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
language: objective-c
osx_image: xcode9.2

cache:
directories:
- buck-out/cache

before_install:
# Update homebrew and ensure our bundle
- brew update && brew bundle

# - rvm use $RVM_RUBY_VERSION
- bundle install
- gem install xcpretty-travis-formatter;
Expand All @@ -11,6 +18,7 @@ before_install:
# - carthage bootstrap --verbose --platform iOS --cache-builds --use-ssh

script:
- buck test :yoga
- set -o pipefail && bundle exec fastlane travis

after_success:
Expand Down
45 changes: 45 additions & 0 deletions BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//:yoga_defs.bzl", "LIBRARY_COMPILER_FLAGS", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "yoga_dep", "cxx_library", "cxx_test")

GMOCK_OVERRIDE_FLAGS = [
# gmock does not mark mocked methods as override, ignore the warnings in tests
"-Wno-inconsistent-missing-override",
]

COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
"-std=c++1y",
]

TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
"-std=c++1y",
]

cxx_library(
name = "yoga",
srcs = glob(["Sources/yoga/*.cpp"]),
header_namespace = "yoga",
exported_headers = subdir_glob([("Sources/yoga", "*.h")]),
compiler_flags = COMPILER_FLAGS,
soname = "libyogacore.$(ext)",
tests = [":YogaTests"],
visibility = ["PUBLIC"],
deps = [
yoga_dep("lib/fb:ndklog"),
],
)

cxx_test(
name = "YogaTests",
srcs = glob(["core-tests/*.cpp"]),
compiler_flags = TEST_COMPILER_FLAGS,
contacts = ["emilsj@fb.com"],
visibility = ["PUBLIC"],
deps = [
":yoga",
GTEST_TARGET,
],
)
2 changes: 2 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tap 'facebook/fb'
brew 'buck'
21 changes: 12 additions & 9 deletions FlexLayout.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ Pod::Spec.new do |spec|
spec.platform = :ios, "9.0"

spec.source = { :git => "https://github.com/lucdion/FlexLayout.git", :tag => "#{spec.version}" }
spec.source_files = "Sources/**/*.{swift,h,m,cpp,c}"
spec.source_files = "Sources/**/*.{swift,h,m,mm,cpp,c}"
spec.public_header_files = "Sources/yoga/{Yoga,YGEnums,YGMacros}.h", "Sources/YogaKit/{UIView+Yoga,YGLayout}.h"

#spec.compiler_flags = [
# '-fno-omit-frame-pointer',
# '-fexceptions',
# '-Wall',
# '-Werror',
# '-std=c11',
# '-fPIC'
#]

# Should match yoga_defs.bzl + BUCK configuration
spec.compiler_flags = [
'-fno-omit-frame-pointer',
'-fexceptions',
'-Wall',
'-Werror',
'-std=c++1y',
'-fPIC'
]
end
108 changes: 72 additions & 36 deletions FlexLayout.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions FlexLayout.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Sources/SupportingFiles/FlexLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,3 @@ FOUNDATION_EXPORT const unsigned char FlexLayoutVersionString[];
#import "Yoga.h"
#import "YGEnums.h"
#import "YGMacros.h"
#import "YGMacros.h"





File renamed without changes.
6 changes: 2 additions & 4 deletions Sources/YogaKit/YGLayout+Private.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import "YGLayout.h"
Expand Down
16 changes: 11 additions & 5 deletions Sources/YogaKit/YGLayout.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <UIKit/UIKit.h>
Expand All @@ -29,7 +27,15 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
@interface YGLayout : NSObject

/**
The property that decides if we should include this view when calculating layout. Defaults to YES.
Make default init unavailable, as it will not initialise YGNode which is
required for the setters and getters of YGLayout's properties to work properly.
*/
- (instancetype)init
__attribute__((unavailable("you are not meant to initialise YGLayout")));

/**
The property that decides if we should include this view when calculating
layout. Defaults to YES.
*/
@property (nonatomic, readwrite, assign, setter=setIncludedInLayout:) BOOL isIncludedInLayout;

Expand Down
14 changes: 6 additions & 8 deletions Sources/YogaKit/YGLayout.m → Sources/YogaKit/YGLayout.mm
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import "YGLayout+Private.h"
Expand Down Expand Up @@ -118,12 +116,12 @@ - (void)set##objc_capitalized_name:(YGValue)objc_lowercased_name

YGValue YGPointValue(CGFloat value)
{
return (YGValue) { .value = value, .unit = YGUnitPoint };
return (YGValue) { .value = (YGUnit) value, .unit = (YGUnit) YGUnitPoint };
}

YGValue YGPercentValue(CGFloat value)
{
return (YGValue) { .value = value, .unit = YGUnitPercent };
return (YGValue) { .value = (YGUnit) value, .unit = YGUnitPercent };
}

static YGConfigRef globalConfig;
Expand Down Expand Up @@ -339,8 +337,8 @@ static YGSize YGMeasureView(
}];

return (YGSize) {
.width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
.height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
.width = (YGUnit) YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
.height = (YGUnit) YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
};
}

Expand Down
8 changes: 3 additions & 5 deletions Sources/YogaKit/YGLayoutExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

postfix operator %
Expand All @@ -31,7 +29,7 @@ extension YGValue: ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral {
public init(integerLiteral value: Int) {
self = YGValue(value: Float(value), unit: .point)
}
public init(floatLiteral value: Float) {
self = YGValue(value: value, unit: .point)
}
Expand Down
29 changes: 29 additions & 0 deletions Sources/yoga/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "Utils.h"

YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction) {
return YGFlexDirectionIsColumn(flexDirection)
? YGResolveFlexDirection(YGFlexDirectionRow, direction)
: YGFlexDirectionColumn;
}

bool YGValueEqual(const YGValue a, const YGValue b) {
if (a.unit != b.unit) {
return false;
}

if (a.unit == YGUnitUndefined ||
(std::isnan(a.value) && std::isnan(b.value))) {
return true;
}

return fabs(a.value - b.value) < 0.0001f;
}
102 changes: 102 additions & 0 deletions Sources/yoga/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once
#include "YGNode.h"
#include "Yoga-internal.h"

// This struct is an helper model to hold the data for step 4 of flexbox
// algo, which is collecting the flex items in a line.
//
// - itemsOnLine: Number of items which can fit in a line considering the
// available Inner dimension, the flex items computed flexbasis and their
// margin. It may be different than the difference between start and end
// indicates because we skip over absolute-positioned items.
//
// - sizeConsumedOnCurrentLine: It is accumulation of the dimensions and margin
// of all the children on the current line. This will be used in order to either
// set the dimensions of the node if none already exist or to compute the
// remaining space left for the flexible children.
//
// - totalFlexGrowFactors: total flex grow factors of flex items which are to be
// layed in the current line
//
// - totalFlexShrinkFactors: total flex shrink factors of flex items which are
// to be layed in the current line
//
// - endOfLineIndex: Its the end index of the last flex item which was examined
// and it may or may not be part of the current line(as it may be absolutely
// positioned or inculding it may have caused to overshoot availableInnerDim)
//
// - relativeChildren: Maintain a vector of the child nodes that can shrink
// and/or grow.

struct YGCollectFlexItemsRowValues {
uint32_t itemsOnLine;
float sizeConsumedOnCurrentLine;
float totalFlexGrowFactors;
float totalFlexShrinkScaledFactors;
float endOfLineIndex;
std::vector<YGNodeRef> relativeChildren;
float remainingFreeSpace;
// The size of the mainDim for the row after considering size, padding, margin
// and border of flex items. This is used to calculate maxLineDim after going
// through all the rows to decide on the main axis size of parent.
float mainDim;
// The size of the crossDim for the row after considering size, padding,
// margin and border of flex items. Used for calculating containers crossSize.
float crossDim;
};

bool YGValueEqual(const YGValue a, const YGValue b);

YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction);

inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
return flexDirection == YGFlexDirectionRow ||
flexDirection == YGFlexDirectionRowReverse;
}

inline float YGResolveValue(const YGValue value, const float parentSize) {
switch (value.unit) {
case YGUnitUndefined:
case YGUnitAuto:
return YGUndefined;
case YGUnitPoint:
return value.value;
case YGUnitPercent:
return value.value * parentSize / 100.0f;
}
return YGUndefined;
}

inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) {
return flexDirection == YGFlexDirectionColumn ||
flexDirection == YGFlexDirectionColumnReverse;
}

inline YGFlexDirection YGResolveFlexDirection(
const YGFlexDirection flexDirection,
const YGDirection direction) {
if (direction == YGDirectionRTL) {
if (flexDirection == YGFlexDirectionRow) {
return YGFlexDirectionRowReverse;
} else if (flexDirection == YGFlexDirectionRowReverse) {
return YGFlexDirectionRow;
}
}

return flexDirection;
}

static inline float YGResolveValueMargin(
const YGValue value,
const float parentSize) {
return value.unit == YGUnitAuto ? 0 : YGResolveValue(value, parentSize);
}
Loading

0 comments on commit 7b9e498

Please sign in to comment.