mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-04 22:56:32 +08:00
Implement TextNodeRegion
Summary: NodeRegion is only able to describe a rectangular region for touch, which is not good enough for text, where we want to be able to assign different touch ids to individual words (and those can span more than one line and in general have non-rectangular structure). This diff adds TextNodeRegion which inserts additional markers into text Layout to allow individual words to have unique react tags. Reviewed By: ahmedre Differential Revision: D2757387
This commit is contained in:
committed by
Ahmed El-Helw
parent
85cdfcd1f7
commit
381bf1b76f
@@ -31,43 +31,29 @@ import com.facebook.react.uimanager.ViewProps;
|
||||
|
||||
private FontStylingSpan mFontStylingSpan = new FontStylingSpan();
|
||||
|
||||
// these 2 are only used between collectText() and applySpans() calls.
|
||||
private int mTextBegin;
|
||||
private int mTextEnd;
|
||||
|
||||
RCTVirtualText() {
|
||||
mFontStylingSpan.setFontSize(getDefaultFontSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectText(SpannableStringBuilder builder) {
|
||||
int childCount = getChildCount();
|
||||
|
||||
mTextBegin = builder.length();
|
||||
for (int i = 0; i < childCount; ++i) {
|
||||
protected void performCollectText(SpannableStringBuilder builder) {
|
||||
for (int i = 0, childCount = getChildCount(); i < childCount; ++i) {
|
||||
FlatTextShadowNode child = (FlatTextShadowNode) getChildAt(i);
|
||||
child.collectText(builder);
|
||||
}
|
||||
mTextEnd = builder.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applySpans(SpannableStringBuilder builder) {
|
||||
if (mTextBegin == mTextEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
protected void performApplySpans(SpannableStringBuilder builder, int begin, int end) {
|
||||
mFontStylingSpan.freeze();
|
||||
|
||||
builder.setSpan(
|
||||
mFontStylingSpan,
|
||||
mTextBegin,
|
||||
mTextEnd,
|
||||
begin,
|
||||
end,
|
||||
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
||||
int childCount = getChildCount();
|
||||
|
||||
for (int i = 0; i < childCount; ++i) {
|
||||
for (int i = 0, childCount = getChildCount(); i < childCount; ++i) {
|
||||
FlatTextShadowNode child = (FlatTextShadowNode) getChildAt(i);
|
||||
child.applySpans(builder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user