mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c62840c7a8
Summary: Text in Nodes is squashed into a single DrawCommand for drawing a Boring or StaticLayout. Touch is handled using a TextNodeRegion subclass of NodeRegion that knows how to identify pieces of text inside of the DrawCommand based on spans in the text. However, we only use a TextNodeRegion on the second call for updateNodeRegion for an RCTText. If there is only one call, the NodeRegion will just be a normal one. This patch ensures that the NodeRegion for an RCTText is always a TextNodeRegion, allowing for null Layouts that are set when the DrawCommand is made. Reviewed By: astreet Differential Revision: D3291682
63 lines
1.7 KiB
Java
63 lines
1.7 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.flat;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import android.text.Layout;
|
|
import android.text.Spanned;
|
|
|
|
/* package */ final class TextNodeRegion extends NodeRegion {
|
|
private @Nullable Layout mLayout;
|
|
|
|
/* package */ TextNodeRegion(
|
|
float left,
|
|
float top,
|
|
float right,
|
|
float bottom,
|
|
int tag,
|
|
boolean isVirtual,
|
|
@Nullable Layout layout) {
|
|
super(left, top, right, bottom, tag, isVirtual);
|
|
mLayout = layout;
|
|
}
|
|
|
|
public void setLayout(Layout layout) {
|
|
mLayout = layout;
|
|
}
|
|
|
|
/* package */ @Nullable Layout getLayout() {
|
|
return mLayout;
|
|
}
|
|
|
|
/* package */ int getReactTag(float touchX, float touchY) {
|
|
if (mLayout != null) {
|
|
int y = Math.round(touchY - mTop);
|
|
if (y >= mLayout.getLineTop(0) && y < mLayout.getLineBottom(mLayout.getLineCount() - 1)) {
|
|
float x = Math.round(touchX - mLeft);
|
|
int line = mLayout.getLineForVertical(y);
|
|
|
|
if (mLayout.getLineLeft(line) <= x && x <= mLayout.getLineRight(line)) {
|
|
int off = mLayout.getOffsetForHorizontal(line, x);
|
|
|
|
Spanned text = (Spanned) mLayout.getText();
|
|
RCTRawText[] link = text.getSpans(off, off, RCTRawText.class);
|
|
|
|
if (link.length != 0) {
|
|
return link[0].getReactTag();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return super.getReactTag(touchX, touchY);
|
|
}
|
|
}
|