Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
Fix the issue that horizontal margin is ignored on devices with API (g…
Browse files Browse the repository at this point in the history
…oogle#354)

level < 17.
Because the FlexboxHelper expected
ViewGroup.MarginLayoutParams#getMarginStart (getMarginEnd) methods when
calculating the wrap condition.

No devices are available on API level < 17  on Firebase Test Lab. So
manually ran the tests on an emulator with API level 16.
  • Loading branch information
thagikura authored Sep 11, 2017
1 parent 14f2a42 commit fb2b633
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:layout_width="24dp"
android:layout_height="0dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:text="1"
app:layout_flexBasisPercent="50%"
app:layout_flexGrow="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:layout_width="24dp"
android:layout_height="150dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:text="1"
app:layout_flexShrink="1" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,36 +738,49 @@ private int getFlexItemSizeCross(FlexItem flexItem, boolean isMainHorizontal) {

/**
* Returns the flexItem's start margin in the main axis. Either start or top.
* For the backward compatibility for API level < 17, the horizontal margin is returned using
* {@link FlexItem#getMarginLeft} (ViewGroup.MarginLayoutParams#getMarginStart isn't available
* in API level < 17). Thus this method needs to be used with {@link #getFlexItemMarginEndMain}
* not to misuse the margin in RTL.
*
*
* @param flexItem the flexItem
* @param isMainHorizontal is the main axis horizontal
* @return the flexItem's start margin in the main axis
*/
private int getFlexItemMarginStartMain(FlexItem flexItem, boolean isMainHorizontal) {
if (isMainHorizontal) {
return flexItem.getMarginStart();
return flexItem.getMarginLeft();
}

return flexItem.getMarginTop();
}

/**
* Returns the flexItem's end margin in the main axis. Either end or bottom.
* For the backward compatibility for API level < 17, the horizontal margin is returned using
* {@link FlexItem#getMarginRight} (ViewGroup.MarginLayoutParams#getMarginEnd isn't available
* in API level < 17). Thus this method needs to be used with
* {@link #getFlexItemMarginStartMain} not to misuse the margin in RTL.
*
* @param flexItem the flexItem
* @param isMainHorizontal is the main axis horizontal
* @return the flexItem's end margin in the main axis
*/
private int getFlexItemMarginEndMain(FlexItem flexItem, boolean isMainHorizontal) {
if (isMainHorizontal) {
return flexItem.getMarginEnd();
return flexItem.getMarginRight();
}

return flexItem.getMarginBottom();
}

/**
* Returns the flexItem's start margin in the cross axis. Either start or top.
* For the backward compatibility for API level < 17, the horizontal margin is returned using
* {@link FlexItem#getMarginLeft} (ViewGroup.MarginLayoutParams#getMarginStart isn't available
* in API level < 17). Thus this method needs to be used with
* {@link #getFlexItemMarginEndCross} to not to misuse the margin in RTL.
*
* @param flexItem the flexItem
* @param isMainHorizontal is the main axis horizontal
Expand All @@ -778,11 +791,15 @@ private int getFlexItemMarginStartCross(FlexItem flexItem, boolean isMainHorizon
return flexItem.getMarginTop();
}

return flexItem.getMarginStart();
return flexItem.getMarginLeft();
}

/**
* Returns the flexItem's end margin in the cross axis. Either end or bottom.
* For the backward compatibility for API level < 17, the horizontal margin is returned using
* {@link FlexItem#getMarginRight} (ViewGroup.MarginLayoutParams#getMarginEnd isn't available
* in API level < 17). Thus this method needs to be used with
* {@link #getFlexItemMarginStartCross} to not to misuse the margin in RTL.
*
* @param flexItem the flexItem
* @param isMainHorizontal is the main axis horizontal
Expand All @@ -793,7 +810,7 @@ private int getFlexItemMarginEndCross(FlexItem flexItem, boolean isMainHorizonta
return flexItem.getMarginBottom();
}

return flexItem.getMarginEnd();
return flexItem.getMarginRight();
}

/**
Expand Down

0 comments on commit fb2b633

Please sign in to comment.