AndroidTextInput: keep track of mostRecentEventCount in C++ State

Summary:
Keep track of AndroidTextInput's mostRecentEventCount in C++ State.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D18672368

fbshipit-source-id: ea7a635629050a6d4957cbcef6ec0bda5faaad9a
This commit is contained in:
Joshua Gross 2019-11-27 12:53:14 -08:00 коммит произвёл Facebook Github Bot
Родитель 309de462bd
Коммит da5ea0215a
5 изменённых файлов: 31 добавлений и 7 удалений

Просмотреть файл

@ -36,6 +36,9 @@ import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.views.text.ReactSpan;
import com.facebook.react.views.text.ReactTextUpdate;
@ -92,6 +95,8 @@ public class ReactEditText extends EditText {
private ReactViewBackgroundManager mReactBackgroundManager;
protected @Nullable StateWrapper mStateWrapper = null;
private static final KeyListener sKeyListener = QwertyKeyListener.getInstanceForFullKeyboard();
public ReactEditText(Context context) {
@ -274,7 +279,17 @@ public class ReactEditText extends EditText {
}
public void setMostRecentEventCount(int mostRecentEventCount) {
if (mMostRecentEventCount == mostRecentEventCount) {
return;
}
mMostRecentEventCount = mostRecentEventCount;
if (mStateWrapper != null) {
WritableMap map = new WritableNativeMap();
map.putInt("mostRecentEventCount", mMostRecentEventCount);
mStateWrapper.updateState(map);
}
}
public void setScrollWatcher(ScrollWatcher scrollWatcher) {
@ -416,8 +431,9 @@ public class ReactEditText extends EditText {
mTypefaceDirty = false;
Typeface newTypeface = ReactTypefaceUtils.applyStyles(
getTypeface(), mFontStyle, mFontWeight, mFontFamily, getContext().getAssets());
Typeface newTypeface =
ReactTypefaceUtils.applyStyles(
getTypeface(), mFontStyle, mFontWeight, mFontFamily, getContext().getAssets());
setTypeface(newTypeface);
}

Просмотреть файл

@ -1072,10 +1072,11 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
// TODO add justificationMode prop into local Data
int justificationMode = Layout.JUSTIFICATION_MODE_NONE;
view.mStateWrapper = stateWrapper;
return new ReactTextUpdate(
spanned,
view.mNativeEventCount, // TODO add this into state, and call setState when the native event
// count is incremented?
state.getInt("mostRecentEventCount"),
false, // TODO add this into local Data
textViewProps.getTextAlign(),
textBreakStrategy,

Просмотреть файл

@ -82,8 +82,10 @@ void AndroidTextInputShadowNode::updateStateIfNeeded() {
return;
}
setStateData(AndroidTextInputState{
attributedString, getProps()->paragraphAttributes, textLayoutManager_});
setStateData(AndroidTextInputState{state.mostRecentEventCount,
attributedString,
getProps()->paragraphAttributes,
textLayoutManager_});
}
#pragma mark - LayoutableShadowNode

Просмотреть файл

@ -16,6 +16,7 @@ namespace react {
#ifdef ANDROID
folly::dynamic AndroidTextInputState::getDynamic() const {
folly::dynamic newState = folly::dynamic::object();
newState["mostRecentEventCount"] = mostRecentEventCount;
newState["attributedString"] = toDynamic(attributedString);
newState["paragraphAttributes"] = toDynamic(paragraphAttributes);
newState["hash"] = newState["attributedString"]["hash"];

Просмотреть файл

@ -24,6 +24,8 @@ namespace react {
*/
class AndroidTextInputState final {
public:
int64_t mostRecentEventCount{0};
/*
* All content of <Paragraph> component represented as an `AttributedString`.
*/
@ -44,10 +46,12 @@ class AndroidTextInputState final {
#ifdef ANDROID
AndroidTextInputState(
int64_t mostRecentEventCount,
AttributedString const &attributedString,
ParagraphAttributes const &paragraphAttributes,
SharedTextLayoutManager const &layoutManager)
: attributedString(attributedString),
: mostRecentEventCount(mostRecentEventCount),
attributedString(attributedString),
paragraphAttributes(paragraphAttributes),
layoutManager(layoutManager) {}
AndroidTextInputState() = default;