Skip to content

Commit

Permalink
improve RTL (#24069)
Browse files Browse the repository at this point in the history
Summary:
Google recommends to use Gravity.START and Gravity.END instead of Gravity.LEFT and Gravity.RIGHT to support RTL better.

[Android] [Changed] - Improve RTL support
Pull Request resolved: #24069

Differential Revision: D14541569

Pulled By: cpojer

fbshipit-source-id: 5c104d8bd666e1270d5410216c7f2efa6152692a
  • Loading branch information
dulmandakh authored and kelset committed Mar 29, 2019
1 parent 9bb5c32 commit 871290f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ public ReactBaseTextShadowNode() {
private int getTextAlign() {
int textAlign = mTextAlign;
if (getLayoutDirection() == YogaDirection.RTL) {
if (textAlign == Gravity.RIGHT) {
textAlign = Gravity.LEFT;
} else if (textAlign == Gravity.LEFT) {
textAlign = Gravity.RIGHT;
if (textAlign == Gravity.END) {
textAlign = Gravity.START;
} else if (textAlign == Gravity.START) {
textAlign = Gravity.END;
}
}
return textAlign;
Expand Down Expand Up @@ -364,7 +364,7 @@ public void setTextAlign(@Nullable String textAlign) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mJustificationMode = Layout.JUSTIFICATION_MODE_INTER_WORD;
}
mTextAlign = Gravity.LEFT;
mTextAlign = Gravity.START;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mJustificationMode = Layout.JUSTIFICATION_MODE_NONE;
Expand All @@ -373,9 +373,9 @@ public void setTextAlign(@Nullable String textAlign) {
if (textAlign == null || "auto".equals(textAlign)) {
mTextAlign = Gravity.NO_GRAVITY;
} else if ("left".equals(textAlign)) {
mTextAlign = Gravity.LEFT;
mTextAlign = Gravity.START;
} else if ("right".equals(textAlign)) {
mTextAlign = Gravity.RIGHT;
mTextAlign = Gravity.END;
} else if ("center".equals(textAlign)) {
mTextAlign = Gravity.CENTER_HORIZONTAL;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public long measure(

Layout.Alignment alignment = Layout.Alignment.ALIGN_NORMAL;
switch (getTextAlign()) {
case Gravity.LEFT:
case Gravity.START:
alignment = Layout.Alignment.ALIGN_NORMAL;
break;
case Gravity.RIGHT:
case Gravity.END:
alignment = Layout.Alignment.ALIGN_OPPOSITE;
break;
case Gravity.CENTER_HORIZONTAL:
Expand Down Expand Up @@ -179,10 +179,10 @@ private void initMeasureFunction() {
private int getTextAlign() {
int textAlign = mTextAlign;
if (getLayoutDirection() == YogaDirection.RTL) {
if (textAlign == Gravity.RIGHT) {
textAlign = Gravity.LEFT;
} else if (textAlign == Gravity.LEFT) {
textAlign = Gravity.RIGHT;
if (textAlign == Gravity.END) {
textAlign = Gravity.START;
} else if (textAlign == Gravity.START) {
textAlign = Gravity.END;
}
}
return textAlign;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ public float getEffectiveLineHeight() {
public int getTextAlign() {
int textAlign = mTextAlign;
if (getLayoutDirection() == YogaDirection.RTL) {
if (textAlign == Gravity.RIGHT) {
textAlign = Gravity.LEFT;
} else if (textAlign == Gravity.LEFT) {
textAlign = Gravity.RIGHT;
if (textAlign == Gravity.END) {
textAlign = Gravity.START;
} else if (textAlign == Gravity.START) {
textAlign = Gravity.END;
}
}
return textAlign;
Expand Down Expand Up @@ -210,7 +210,7 @@ public void setTextAlign(@Nullable String textAlign) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mJustificationMode = Layout.JUSTIFICATION_MODE_INTER_WORD;
}
mTextAlign = Gravity.LEFT;
mTextAlign = Gravity.START;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mJustificationMode = Layout.JUSTIFICATION_MODE_NONE;
Expand All @@ -219,9 +219,9 @@ public void setTextAlign(@Nullable String textAlign) {
if (textAlign == null || "auto".equals(textAlign)) {
mTextAlign = Gravity.NO_GRAVITY;
} else if ("left".equals(textAlign)) {
mTextAlign = Gravity.LEFT;
mTextAlign = Gravity.START;
} else if ("right".equals(textAlign)) {
mTextAlign = Gravity.RIGHT;
mTextAlign = Gravity.END;
} else if ("center".equals(textAlign)) {
mTextAlign = Gravity.CENTER_HORIZONTAL;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react.views.textinput;

import android.annotation.TargetApi;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -459,7 +460,7 @@ public void setTextAlign(ReactEditText view, @Nullable String textAlign) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
view.setJustificationMode(Layout.JUSTIFICATION_MODE_INTER_WORD);
}
view.setGravityHorizontal(Gravity.LEFT);
view.setGravityHorizontal(Gravity.START);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
view.setJustificationMode(Layout.JUSTIFICATION_MODE_NONE);
Expand All @@ -468,9 +469,9 @@ public void setTextAlign(ReactEditText view, @Nullable String textAlign) {
if (textAlign == null || "auto".equals(textAlign)) {
view.setGravityHorizontal(Gravity.NO_GRAVITY);
} else if ("left".equals(textAlign)) {
view.setGravityHorizontal(Gravity.LEFT);
view.setGravityHorizontal(Gravity.START);
} else if ("right".equals(textAlign)) {
view.setGravityHorizontal(Gravity.RIGHT);
view.setGravityHorizontal(Gravity.END);
} else if ("center".equals(textAlign)) {
view.setGravityHorizontal(Gravity.CENTER_HORIZONTAL);
} else {
Expand Down

0 comments on commit 871290f

Please sign in to comment.