Skip to content

Instantly share code, notes, and snippets.

@Palisand
Last active October 11, 2017 16:17
Show Gist options
  • Save Palisand/af824464ea335327fd7f25eb441a3497 to your computer and use it in GitHub Desktop.
Save Palisand/af824464ea335327fd7f25eb441a3497 to your computer and use it in GitHub Desktop.
Changes for scroll-to-cursor functionality.
/**
* Event emitted by EditText native view when the text selection changes.
*/
/* package */ class ReactTextInputSelectionEvent
extends Event<ReactTextInputSelectionEvent> {
private static final String EVENT_NAME = "topSelectionChange";
private int mSelectionStart;
private int mSelectionEnd;
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
private float mCursorPositionX;
private float mCursorPositionY;
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
public ReactTextInputSelectionEvent(
int viewId,
int selectionStart,
int selectionEnd,
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
float cursorPositionX,
float cursorPositionY) {
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
super(viewId);
mSelectionStart = selectionStart;
mSelectionEnd = selectionEnd;
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
mCursorPositionX = cursorPositionX;
mCursorPositionY = cursorPositionY;
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
}
@Override
public String getEventName() {
return EVENT_NAME;
}
@Override
public void dispatch(RCTEventEmitter rctEventEmitter) {
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());
}
private WritableMap serializeEventData() {
WritableMap eventData = Arguments.createMap();
WritableMap selectionData = Arguments.createMap();
selectionData.putInt("end", mSelectionEnd);
selectionData.putInt("start", mSelectionStart);
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
selectionData.putDouble("cursorPositionX", mCursorPositionX);
selectionData.putDouble("cursorPositionY", mCursorPositionY);
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
eventData.putMap("selection", selectionData);
return eventData;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment