Permalink
Browse files

make sure multiline TextInput is scrollable within a ScrollView

Reviewed By: bestander

Differential Revision: D3668840

fbshipit-source-id: 349314588035935543944ea6a8ddcb730c3ee85e
  • Loading branch information...
1 parent 5405aeb commit b05c7f792f1337790c32e9b3a0822796a2359e05 @shengmin shengmin committed with Facebook Github Bot Aug 5, 2016
Showing with 19 additions and 0 deletions.
  1. +19 −0 ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java
@@ -29,6 +29,7 @@
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.KeyEvent;
+import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
@@ -95,6 +96,24 @@ public ReactEditText(Context context) {
mKeyListener = new InternalKeyListener();
}
+ /**
+ * Make sure multiline text input can be scrolled within a ScrollView
+ */
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent ev) {
+ switch (ev.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ // Disallow ScrollView to intercept touch events.
+ this.getParent().requestDisallowInterceptTouchEvent(true);
+ break;
+ case MotionEvent.ACTION_UP:
+ // Allow ScrollView to intercept touch events.
+ this.getParent().requestDisallowInterceptTouchEvent(false);
+ break;
+ }
+ return super.dispatchTouchEvent(ev);
+ }
+
// After the text changes inside an EditText, TextView checks if a layout() has been requested.
// If it has, it will not scroll the text to the end of the new text inserted, but wait for the
// next layout() to be called. However, we do not perform a layout() after a requestLayout(), so

0 comments on commit b05c7f7

Please sign in to comment.