Minor code improvements for RCTTextInput

Summary: @public Expose hasUnseenUpdates in ReactShadowNode. Various text input cleanup and fixes.

Differential Revision: D2975870
This commit is contained in:
Ahmed El-Helw 2016-02-29 16:42:21 -08:00
parent df382e986c
commit 75117fc91a
5 changed files with 23 additions and 33 deletions

View File

@ -30,11 +30,6 @@ import com.facebook.react.uimanager.ReactShadowNode;
if (parent instanceof FlatTextShadowNode) {
((FlatTextShadowNode) parent).notifyChanged(shouldRemeasure);
}
if (this instanceof RCTTextInput) {
// needed to trigger onCollectExtraUpdates
markUpdated();
}
}
@Override

View File

@ -13,7 +13,6 @@ import javax.annotation.Nullable;
import android.text.BoringLayout;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
@ -275,16 +274,6 @@ import com.facebook.react.uimanager.annotations.ReactProp;
notifyChanged(false);
}
/**
* Returns a new CharSequence that includes all the text and styling information to create Layout.
*/
private CharSequence getText() {
SpannableStringBuilder sb = new SpannableStringBuilder();
collectText(sb);
applySpans(sb);
return sb;
}
/**
* Returns measured line height according to an includePadding flag.
*/

View File

@ -44,6 +44,13 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
setMeasureFunction(this);
}
@Override
protected void notifyChanged(boolean shouldRemeasure) {
super.notifyChanged(shouldRemeasure);
// needed to trigger onCollectExtraUpdates
markUpdated();
}
@Override
public void setThemedContext(ThemedReactContext themedContext) {
super.setThemedContext(themedContext);
@ -107,8 +114,7 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
super.onCollectExtraUpdates(uiViewOperationQueue);
if (mJsEventCount != UNSET) {
ReactTextUpdate reactTextUpdate =
new ReactTextUpdate(getText(), mJsEventCount, false);
ReactTextUpdate reactTextUpdate = new ReactTextUpdate(getText(), mJsEventCount, false);
uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), reactTextUpdate);
}
}
@ -127,7 +133,7 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
@ReactProp(name = PROP_TEXT)
public void setText(@Nullable String text) {
mText = text;
markUpdated();
notifyChanged(true);
}
@Override
@ -153,6 +159,7 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
return true;
}
@Override
protected void performCollectText(SpannableStringBuilder builder) {
if (mText != null) {
builder.append(mText);
@ -160,16 +167,6 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
super.performCollectText(builder);
}
/**
* Returns a new CharSequence that includes all the text and styling information to create Layout.
*/
SpannableStringBuilder getText() {
SpannableStringBuilder sb = new SpannableStringBuilder();
collectText(sb);
applySpans(sb);
return sb;
}
@Override
public boolean needsCustomLayoutForChildren() {
return false;

View File

@ -238,6 +238,17 @@ import com.facebook.react.uimanager.ViewProps;
return mFontStylingSpan;
}
/**
* Returns a new SpannableStringBuilder that includes all the text and styling information to
* create the Layout.
*/
/* package */ final SpannableStringBuilder getText() {
SpannableStringBuilder sb = new SpannableStringBuilder();
collectText(sb);
applySpans(sb);
return sb;
}
private final ShadowStyleSpan getShadowSpan() {
if (mShadowStyleSpan.isFrozen()) {
mShadowStyleSpan = mShadowStyleSpan.mutableCopy();

View File

@ -239,9 +239,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
float clipTop,
float clipRight,
float clipBottom) {
// Normally, this would be a node.hasNewLayout() check, but we also need to check if a node
// needs onCollectExtraUpdates() call.
boolean hasUpdates = node.hasUpdates();
boolean hasUpdates = node.hasNewLayout();
boolean expectingUpdate = hasUpdates || node.isUpdated() ||
node.clipBoundsChanged(clipLeft, clipTop, clipRight, clipBottom);
@ -323,7 +321,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
nodeRegions);
}
if (hasUpdates) {
if (node.hasUnseenUpdates()) {
node.onCollectExtraUpdates(mOperationsQueue);
node.markUpdateSeen();
}