Skip to content

Commit

Permalink
Signal if text has already been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hypest committed Apr 23, 2019
1 parent 16f223e commit 2372231
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class ReactAztecBackspaceEvent extends Event<ReactAztecBackspaceEvent> {
private String mText;
private int mSelectionStart;
private int mSelectionEnd;
private boolean mFiredAfterTextChanged;

public ReactAztecBackspaceEvent(int viewId, String text, int selectionStart, int selectionEnd) {
public ReactAztecBackspaceEvent(int viewId, String text, int selectionStart, int selectionEnd,
boolean firedAfterTextChanged) {
super(viewId);
mText = text;
mSelectionStart = selectionStart;
mSelectionEnd = selectionEnd;
mFiredAfterTextChanged = firedAfterTextChanged;
}

@Override
Expand All @@ -44,6 +47,7 @@ private WritableMap serializeEventData() {
eventData.putString("text", mText);
eventData.putInt("selectionStart", mSelectionStart);
eventData.putInt("selectionEnd", mSelectionEnd);
eventData.putBoolean("firedAfterTextChanged", mFiredAfterTextChanged);
return eventData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ class ReactAztecEnterEvent extends Event<ReactAztecEnterEvent> {
private String mText;
private int mSelectionStart;
private int mSelectionEnd;
private boolean mFiredAfterTextChanged;
private int mEventCount;

public ReactAztecEnterEvent(int viewId, String text, int selectionStart, int selectionEnd, int eventCount) {
public ReactAztecEnterEvent(int viewId, String text, int selectionStart, int selectionEnd,
boolean firedAfterTextChanged, int eventCount) {
super(viewId);
mText = text;
mSelectionStart = selectionStart;
mSelectionEnd = selectionEnd;
mFiredAfterTextChanged = firedAfterTextChanged;
mEventCount = eventCount;
}

Expand All @@ -46,6 +49,7 @@ private WritableMap serializeEventData() {
eventData.putString("text", mText);
eventData.putInt("selectionStart", mSelectionStart);
eventData.putInt("selectionEnd", mSelectionEnd);
eventData.putBoolean("firedAfterTextChanged", mFiredAfterTextChanged);
eventData.putInt("eventCount", mEventCount);
return eventData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ public ReactAztecText(ThemedReactContext reactContext) {

this.setAztecKeyListener(new ReactAztecText.OnAztecKeyListener() {
@Override
public boolean onEnterKey() {
public boolean onEnterKey(boolean firedAfterTextChanged) {
if (shouldHandleOnEnter && !isTextChangedListenerDisabled()) {
return onEnter();
return onEnter(firedAfterTextChanged);
}
return false;
}
@Override
public boolean onBackspaceKey() {
public boolean onBackspaceKey(boolean firedAfterTextChanged) {
if (shouldHandleOnBackspace && !isTextChangedListenerDisabled()) {
String content = toHtml(false);
if (TextUtils.isEmpty(content)) {
return onBackspace();
return onBackspace(firedAfterTextChanged);
}
else {
if (!content.equals(mEmptyTagHTML)) {
return onBackspace();
return onBackspace(firedAfterTextChanged);
}
}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ public void setIsSettingTextFromJS(boolean mIsSettingTextFromJS) {
this.mIsSettingTextFromJS = mIsSettingTextFromJS;
}

private boolean onEnter() {
private boolean onEnter(boolean firedAfterTextChanged) {
disableTextChangedListener();
String content = toHtml(false);
int cursorPositionStart = getSelectionStart();
Expand All @@ -364,12 +364,13 @@ private boolean onEnter() {
ReactContext reactContext = (ReactContext) getContext();
EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
eventDispatcher.dispatchEvent(
new ReactAztecEnterEvent(getId(), content, cursorPositionStart, cursorPositionEnd, incrementAndGetEventCounter())
new ReactAztecEnterEvent(getId(), content, cursorPositionStart, cursorPositionEnd,
firedAfterTextChanged, incrementAndGetEventCounter())
);
return true;
}

private boolean onBackspace() {
private boolean onBackspace(boolean firedAfterTextChanged) {
int cursorPositionStart = getSelectionStart();
int cursorPositionEnd = getSelectionEnd();
// Make sure to report backspace at the beginning only, with no selection.
Expand All @@ -384,7 +385,8 @@ private boolean onBackspace() {
EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
// TODO: isRTL? Should be passed here?
eventDispatcher.dispatchEvent(
new ReactAztecBackspaceEvent(getId(), content, cursorPositionStart, cursorPositionEnd)
new ReactAztecBackspaceEvent(getId(), content, cursorPositionStart, cursorPositionEnd,
firedAfterTextChanged)
);
return true;
}
Expand Down

0 comments on commit 2372231

Please sign in to comment.