Skip to content

Add support for reverse direction to yoga layouts #1413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/Layout/ASStackLayoutDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ typedef NS_ENUM(NSUInteger, ASStackLayoutDirection) {
ASStackLayoutDirectionVertical,
/** Children are stacked horizontally */
ASStackLayoutDirectionHorizontal,
#if YOGA
/** Children are stacked vertically, but in reverse. Only used by Yoga spec. */
ASStackLayoutDirectionVerticalReverse,
/** Children are stacked horizontally, but in reverse. Only used by Yoga spec. */
ASStackLayoutDirectionHorizontalReverse,
#endif
};

/** If no children are flexible, how should this spec justify its children in the available space? */
Expand Down
7 changes: 7 additions & 0 deletions Source/Layout/ASStackLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ - (void)resolveVerticalAlignment
case ASStackLayoutDirectionHorizontal:
[result insertObject:@{ (id)kCFNull: @"horizontal" } atIndex:0];
break;
#if YOGA
case ASStackLayoutDirectionVerticalReverse:
case ASStackLayoutDirectionHorizontalReverse:
// Currently not handled.
ASDisplayNodeFailAssert(@"Reverse directions not implemented.");
break;
#endif
}

return result;
Expand Down
11 changes: 10 additions & 1 deletion Source/Layout/ASYogaUtilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ YGAlign yogaAlignSelf(ASStackLayoutAlignSelf alignSelf)

YGFlexDirection yogaFlexDirection(ASStackLayoutDirection direction)
{
return direction == ASStackLayoutDirectionVertical ? YGFlexDirectionColumn : YGFlexDirectionRow;
switch (direction) {
case ASStackLayoutDirectionVertical:
return YGFlexDirectionColumn;
case ASStackLayoutDirectionVerticalReverse:
return YGFlexDirectionColumnReverse;
case ASStackLayoutDirectionHorizontal:
return YGFlexDirectionRow;
case ASStackLayoutDirectionHorizontalReverse:
return YGFlexDirectionRowReverse;
}
}

float yogaFloatForCGFloat(CGFloat value)
Expand Down