Skip to content
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

Fix for some links not tappable in RTL languages. #896

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class TextDrawable extends Drawable implements Touchable, TextContent, Dr
private @Nullable ClickableSpanListener mSpanListener;
private @Nullable TouchableSpanListener mTouchableSpanListener;
private @Nullable String mContextLogTag;
private boolean mRtl;

@Override
public void draw(Canvas canvas) {
Expand Down Expand Up @@ -351,7 +352,8 @@ public void mount(
-1,
-1,
0f,
null);
null,
false);
}

public void mount(
Expand All @@ -370,7 +372,8 @@ public void mount(
int highlightStartOffset,
int highlightEndOffset,
float clickableSpanExpandedOffset,
String contextLogTag) {
String contextLogTag,
boolean rtl) {
mLayout = layout;
mLayoutTranslationY = layoutTranslationY;
mClipToBounds = clipToBounds;
Expand All @@ -385,6 +388,7 @@ public void mount(
mShouldHandleTouch = (clickableSpans != null && clickableSpans.length > 0);
mHighlightColor = highlightColor;
mClickableSpanExpandedOffset = clickableSpanExpandedOffset;
mRtl = rtl;
if (userColor != 0) {
mColorStateList = null;
mUserColor = userColor;
Expand Down Expand Up @@ -444,6 +448,7 @@ public void unmount() {
mTextOffsetOnTouchListener = null;
mColorStateList = null;
mUserColor = 0;
mRtl = false;
if (mImageSpans != null) {
for (int i = 0, size = mImageSpans.length; i < size; i++) {
Drawable drawable = mImageSpans[i].getDrawable();
Expand Down Expand Up @@ -538,9 +543,8 @@ private int getTextOffsetAt(int x, int y) {
* direction, and {@link Layout#getLineMax} gives the extent *plus* the leading margin, so we
* can figure out the rest from there.
*/
final boolean rtl = mLayout.getParagraphDirection(line) == Layout.DIR_RIGHT_TO_LEFT;
left = rtl ? mLayout.getWidth() - mLayout.getLineMax(line) : mLayout.getParagraphLeft(line);
right = rtl ? mLayout.getParagraphRight(line) : mLayout.getLineMax(line);
left = mRtl ? mLayout.getWidth() - mLayout.getLineMax(line) : mLayout.getParagraphLeft(line);
right = mRtl ? mLayout.getParagraphRight(line) : mLayout.getLineMax(line);
}

if (x < left || x > right) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.facebook.litho.widget;

import static android.content.res.Configuration.SCREENLAYOUT_LAYOUTDIR_MASK;
import static android.content.res.Configuration.SCREENLAYOUT_LAYOUTDIR_RTL;
import static androidx.customview.widget.ExploreByTouchHelper.INVALID_ID;
import static com.facebook.litho.SizeSpec.AT_MOST;
import static com.facebook.litho.SizeSpec.EXACTLY;
Expand Down Expand Up @@ -906,7 +908,8 @@ public void textOffsetOnTouch(int textOffset) {
highlightStartOffset,
highlightEndOffset,
clickableSpanExpandedOffset,
c.getLogTag());
c.getLogTag(),
isRtl(c.getAndroidContext()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout direction can be explicitly set as well, and should take precedence over this. You can get the resolved layout direction in @OnBoundsDefined from the ComponentLayout by invoking layout.getResolvedLayoutDirection(). The resolved direction can be returned as an Output from @OnBoundsDefined.

The default value is YogaDirection.INHERIT, so here it would be something like:

layout == YogaDirection.INHERIT ? isRtl(c.getAndroidContext()) : layout == YogaDirection.RTL


if (processedText instanceof MountableCharSequence) {
((MountableCharSequence) processedText).onMount(textDrawable);
Expand Down Expand Up @@ -1178,4 +1181,9 @@ private static Alignment getLayoutAlignment(
}
return alignment;
}

private static boolean isRtl(Context context) {
return (context.getResources().getConfiguration().screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)
== SCREENLAYOUT_LAYOUTDIR_RTL;
}
}