Skip to content
This repository was archived by the owner on Mar 21, 2019. It is now read-only.

fix(FlexboxLayout): issue #6156 and replace auto RTL detected by manual #163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ public class FlexboxLayout extends ViewGroup {
* The default value is {@link #FLEX_DIRECTION_ROW}.
*/
private int mFlexDirection = FLEX_DIRECTION_ROW;


@IntDef({FLEX_WRAP_NOWRAP, FLEX_WRAP_WRAP, FLEX_WRAP_WRAP_REVERSE})
@Retention(RetentionPolicy.SOURCE)
@@ -290,7 +290,20 @@ public class FlexboxLayout extends ViewGroup {
private SparseIntArray mOrderCache;

private List<FlexLine> mFlexLines = new ArrayList<>();


/**
* force change RTL direction
*/

private boolean mIsRtl = false;
public void setRtl(boolean rtl) {
mIsRtl = rtl;
}

public boolean getRtl() {
return mIsRtl;
}

/**
* Holds the 'frozen' state of children during measure. If a view is frozen it will no longer
* expand or shrink regardless of flexGrow/flexShrink. Items are indexed by the child's
@@ -1557,25 +1570,21 @@ private boolean isMainAxisDirectionHorizontal(@FlexDirection int flexDirection)
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int layoutDirection = ViewCompat.getLayoutDirection(this);
boolean isRtl;
boolean isRtl = mIsRtl;
switch (mFlexDirection) {
case FLEX_DIRECTION_ROW:
isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
layoutHorizontal(isRtl, left, top, right, bottom);
break;
case FLEX_DIRECTION_ROW_REVERSE:
isRtl = layoutDirection != ViewCompat.LAYOUT_DIRECTION_RTL;
layoutHorizontal(isRtl, left, top, right, bottom);
break;
case FLEX_DIRECTION_COLUMN:
isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
isRtl = !isRtl;
}
layoutVertical(isRtl, false, left, top, right, bottom);
break;
case FLEX_DIRECTION_COLUMN_REVERSE:
isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
isRtl = !isRtl;
}
@@ -2016,33 +2025,29 @@ protected void onDraw(Canvas canvas) {
}

int layoutDirection = ViewCompat.getLayoutDirection(this);
boolean isRtl;
boolean isRtl = mIsRtl;
boolean fromBottomToTop = false;
switch (mFlexDirection) {
case FLEX_DIRECTION_ROW:
isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
fromBottomToTop = true;
}
drawDividersHorizontal(canvas, isRtl, fromBottomToTop);
break;
case FLEX_DIRECTION_ROW_REVERSE:
isRtl = layoutDirection != ViewCompat.LAYOUT_DIRECTION_RTL;
if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
fromBottomToTop = true;
}
drawDividersHorizontal(canvas, isRtl, fromBottomToTop);
break;
case FLEX_DIRECTION_COLUMN:
isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
isRtl = !isRtl;
}
fromBottomToTop = false;
drawDividersVertical(canvas, isRtl, fromBottomToTop);
break;
case FLEX_DIRECTION_COLUMN_REVERSE:
isRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL;
if (mFlexWrap == FLEX_WRAP_WRAP_REVERSE) {
isRtl = !isRtl;
}
@@ -2715,4 +2720,4 @@ public String toString() {
'}';
}
}
}
}