Skip to content

Commit

Permalink
Updated to latest version of Yoga
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Usbergo committed Apr 25, 2017
1 parent a246b45 commit 1492d6d
Show file tree
Hide file tree
Showing 16 changed files with 1,407 additions and 913 deletions.
4 changes: 4 additions & 0 deletions Render.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
164C11691E5A203100766914 /* Reset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 164C11681E5A203100766914 /* Reset.swift */; };
164C116B1E5A257300766914 /* ComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 164C116A1E5A257300766914 /* ComponentView.swift */; };
164C11A81E5E2F4400766914 /* ComponentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 164C11A71E5E2F4400766914 /* ComponentCell.swift */; };
165649D71EAF82EB00E02BC1 /* YGEnums.c in Sources */ = {isa = PBXBuildFile; fileRef = 165649D61EAF82EB00E02BC1 /* YGEnums.c */; };
16C59F811E75BE9900D9E297 /* TableNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16C59F801E75BE9900D9E297 /* TableNode.swift */; };
/* End PBXBuildFile section */

Expand All @@ -47,6 +48,7 @@
164C11681E5A203100766914 /* Reset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reset.swift; sourceTree = "<group>"; };
164C116A1E5A257300766914 /* ComponentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentView.swift; sourceTree = "<group>"; };
164C11A71E5E2F4400766914 /* ComponentCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentCell.swift; sourceTree = "<group>"; };
165649D61EAF82EB00E02BC1 /* YGEnums.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = YGEnums.c; sourceTree = "<group>"; };
16C59F801E75BE9900D9E297 /* TableNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableNode.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -98,6 +100,7 @@
children = (
164C114C1E59ECC600766914 /* UIView+Yoga.h */,
164C114D1E59ECC600766914 /* UIView+Yoga.m */,
165649D61EAF82EB00E02BC1 /* YGEnums.c */,
164C114E1E59ECC600766914 /* YGEnums.h */,
164C114F1E59ECC600766914 /* YGLayout+Private.h */,
164C11501E59ECC600766914 /* YGLayout.h */,
Expand Down Expand Up @@ -198,6 +201,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
165649D71EAF82EB00E02BC1 /* YGEnums.c in Sources */,
164C11691E5A203100766914 /* Reset.swift in Sources */,
16C59F811E75BE9900D9E297 /* TableNode.swift in Sources */,
164C11631E59ECEC00766914 /* Node.swift in Sources */,
Expand Down
Binary file not shown.
16 changes: 15 additions & 1 deletion Render/ComponentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public enum RenderOption {
options: UIViewAnimationOptions,
alongside: ((Void) -> Void)?)

case flexibleWidth
case flexibleHeigth

/** Internal use only. */
case __animated
}
Expand Down Expand Up @@ -138,9 +141,18 @@ open class ComponentView<S: StateType>: UIView, ComponentViewType {
func layout() {
// Applies the configuration closures and recursively computes the layout.
self.root.render(in: bounds)
self.rootView.yoga.applyLayout(preservingOrigin: false)

let preservingOrigin = false
let yoga = self.rootView.yoga

if RenderOption.contains(opts, .flexibleWidth) {
yoga.applyLayout(preservingOrigin: preservingOrigin, dimensionFlexibility: .flexibleWidth)
} else if RenderOption.contains(opts, .flexibleHeigth) {
yoga.applyLayout(preservingOrigin: preservingOrigin, dimensionFlexibility: .flexibleHeigth)
} else {
yoga.applyLayout(preservingOrigin: false)
}

// Applies the frame to the host view.
self.rootView.frame.normalize()
self.contentView.frame.size = rootView.bounds.size
Expand Down Expand Up @@ -277,6 +289,8 @@ extension RenderOption: Equatable {
switch self {
case .preventViewHierarchyDiff: return 0
case .animated(_), .__animated: return 1
case .flexibleWidth: return 2
case .flexibleHeigth: return 3
}
}

Expand Down
4 changes: 2 additions & 2 deletions Render/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import UIKit

public extension CGFloat {
public static let undefined: CGFloat = YGNaNSize.width
public static let max: CGFloat = CGFloat(FLT_MAX)
public static let epsilon: CGFloat = CGFloat(FLT_EPSILON)
public static let max: CGFloat = CGFloat(Float.greatestFiniteMagnitude)
public static let epsilon: CGFloat = CGFloat(Float.ulpOfOne)
}

public extension CGSize {
Expand Down
13 changes: 9 additions & 4 deletions Render/objc/UIView+Yoga.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/** Copyright (c) 2014-present, Facebook, Inc. */
/**
* 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.
*/

#import "YGLayout.h"
#import <UIKit/UIKit.h>
Expand All @@ -20,9 +27,7 @@ typedef void (^YGLayoutConfigurationBlock)(YGLayout *);
to use this method, which uses a single objc_msgSend call.
*/
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
NS_SWIFT_NAME(configureLayout(block:));

- (void)resetYoga;
NS_SWIFT_NAME(configureLayout(block:));

@end

Expand Down
15 changes: 8 additions & 7 deletions Render/objc/UIView+Yoga.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/** Copyright (c) 2014-present, Facebook, Inc. */
/**
* 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.
*/

#import "UIView+Yoga.h"
#import "YGLayout+Private.h"
Expand All @@ -19,12 +26,6 @@ - (YGLayout *)yoga
return yoga;
}

- (void)resetYoga
{
YGLayout *yoga = [[YGLayout alloc] initWithView:self];
objc_setAssociatedObject(self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
{
if (block != nil) {
Expand Down
219 changes: 219 additions & 0 deletions Render/objc/YGEnums.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/**
* 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.
*/

#include "YGEnums.h"

const char *YGAlignToString(const YGAlign value){
switch(value){
case YGAlignAuto:
return "auto";
case YGAlignFlexStart:
return "flex-start";
case YGAlignCenter:
return "center";
case YGAlignFlexEnd:
return "flex-end";
case YGAlignStretch:
return "stretch";
case YGAlignBaseline:
return "baseline";
case YGAlignSpaceBetween:
return "space-between";
case YGAlignSpaceAround:
return "space-around";
}
return "unknown";
}

const char *YGDimensionToString(const YGDimension value){
switch(value){
case YGDimensionWidth:
return "width";
case YGDimensionHeight:
return "height";
}
return "unknown";
}

const char *YGDirectionToString(const YGDirection value){
switch(value){
case YGDirectionInherit:
return "inherit";
case YGDirectionLTR:
return "ltr";
case YGDirectionRTL:
return "rtl";
}
return "unknown";
}

const char *YGDisplayToString(const YGDisplay value){
switch(value){
case YGDisplayFlex:
return "flex";
case YGDisplayNone:
return "none";
}
return "unknown";
}

const char *YGEdgeToString(const YGEdge value){
switch(value){
case YGEdgeLeft:
return "left";
case YGEdgeTop:
return "top";
case YGEdgeRight:
return "right";
case YGEdgeBottom:
return "bottom";
case YGEdgeStart:
return "start";
case YGEdgeEnd:
return "end";
case YGEdgeHorizontal:
return "horizontal";
case YGEdgeVertical:
return "vertical";
case YGEdgeAll:
return "all";
}
return "unknown";
}

const char *YGExperimentalFeatureToString(const YGExperimentalFeature value){
switch(value){
case YGExperimentalFeatureRounding:
return "rounding";
case YGExperimentalFeatureWebFlexBasis:
return "web-flex-basis";
case YGExperimentalFeatureMinFlexFix:
return "min-flex-fix";
}
return "unknown";
}

const char *YGFlexDirectionToString(const YGFlexDirection value){
switch(value){
case YGFlexDirectionColumn:
return "column";
case YGFlexDirectionColumnReverse:
return "column-reverse";
case YGFlexDirectionRow:
return "row";
case YGFlexDirectionRowReverse:
return "row-reverse";
}
return "unknown";
}

const char *YGJustifyToString(const YGJustify value){
switch(value){
case YGJustifyFlexStart:
return "flex-start";
case YGJustifyCenter:
return "center";
case YGJustifyFlexEnd:
return "flex-end";
case YGJustifySpaceBetween:
return "space-between";
case YGJustifySpaceAround:
return "space-around";
}
return "unknown";
}

const char *YGLogLevelToString(const YGLogLevel value){
switch(value){
case YGLogLevelError:
return "error";
case YGLogLevelWarn:
return "warn";
case YGLogLevelInfo:
return "info";
case YGLogLevelDebug:
return "debug";
case YGLogLevelVerbose:
return "verbose";
}
return "unknown";
}

const char *YGMeasureModeToString(const YGMeasureMode value){
switch(value){
case YGMeasureModeUndefined:
return "undefined";
case YGMeasureModeExactly:
return "exactly";
case YGMeasureModeAtMost:
return "at-most";
}
return "unknown";
}

const char *YGOverflowToString(const YGOverflow value){
switch(value){
case YGOverflowVisible:
return "visible";
case YGOverflowHidden:
return "hidden";
case YGOverflowScroll:
return "scroll";
}
return "unknown";
}

const char *YGPositionTypeToString(const YGPositionType value){
switch(value){
case YGPositionTypeRelative:
return "relative";
case YGPositionTypeAbsolute:
return "absolute";
}
return "unknown";
}

const char *YGPrintOptionsToString(const YGPrintOptions value){
switch(value){
case YGPrintOptionsLayout:
return "layout";
case YGPrintOptionsStyle:
return "style";
case YGPrintOptionsChildren:
return "children";
}
return "unknown";
}

const char *YGUnitToString(const YGUnit value){
switch(value){
case YGUnitUndefined:
return "undefined";
case YGUnitPoint:
return "point";
case YGUnitPercent:
return "percent";
case YGUnitAuto:
return "auto";
}
return "unknown";
}

const char *YGWrapToString(const YGWrap value){
switch(value){
case YGWrapNoWrap:
return "no-wrap";
case YGWrapWrap:
return "wrap";
case YGWrapWrapReverse:
return "wrap-reverse";
}
return "unknown";
}

Loading

0 comments on commit 1492d6d

Please sign in to comment.