mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 22:40:55 +08:00
Implement returnKeyType/returnKeyLabel on Android
Summary:
This PR implements [`returnKeyType`](http://facebook.github.io/react-native/docs/textinput.html#returnkeytype) on Android.
It is implemented with [`EditText.setImeOptions()`](http://developer.android.com/reference/android/widget/TextView.html#setImeOptions(int)) that allows us to specify options on an input, in this case change the return button icon. To be noted that it is also possible to specify a string instead of an icon with [`EditText.setImeActionLabel()`](http://developer.android.com/reference/android/widget/TextView.html#setImeActionLabel(java.lang.CharSequence, int)) while being 2 different things I added both of these behaviors in this PR since it was mostly at the same place/component.
**Problems encountered :**
- All the `ReactEditText`s were set to `IME_ACTION_DONE` by default ([reference](a2157dbbe0/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java (L78))). I'm not sure
Closes https://github.com/facebook/react-native/pull/6905
Differential Revision: D3264755
Pulled By: dmmiller
fb-gh-sync-id: 4a090e31b620a245847c06ba1895cfea02e88d0f
fbshipit-source-id: 4a090e31b620a245847c06ba1895cfea02e88d0f
This commit is contained in:
committed by
Facebook Github Bot 2
parent
02af7b57d0
commit
dd8caf4cf2
@@ -44,8 +44,8 @@ import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.views.text.DefaultStyleValuesUtil;
|
||||
import com.facebook.react.views.text.TextInlineImageSpan;
|
||||
import com.facebook.react.views.text.ReactTextUpdate;
|
||||
import com.facebook.react.views.text.TextInlineImageSpan;
|
||||
|
||||
/**
|
||||
* Manages instances of TextInput.
|
||||
@@ -431,6 +431,40 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
checkPasswordType(view);
|
||||
}
|
||||
|
||||
@ReactProp(name = "returnKeyType")
|
||||
public void setReturnKeyType(ReactEditText view, String returnKeyType) {
|
||||
switch (returnKeyType) {
|
||||
case "done":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
break;
|
||||
case "go":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_GO);
|
||||
break;
|
||||
case "next":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_NEXT);
|
||||
break;
|
||||
case "none":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
|
||||
break;
|
||||
case "previous":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_PREVIOUS);
|
||||
break;
|
||||
case "search":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
|
||||
break;
|
||||
case "send":
|
||||
view.setImeOptions(EditorInfo.IME_ACTION_SEND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int IME_ACTION_ID = 0x670;
|
||||
|
||||
@ReactProp(name = "returnKeyLabel")
|
||||
public void setReturnKeyLabel(ReactEditText view, String returnKeyLabel) {
|
||||
view.setImeActionLabel(returnKeyLabel, IME_ACTION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAfterUpdateTransaction(ReactEditText view) {
|
||||
super.onAfterUpdateTransaction(view);
|
||||
@@ -587,6 +621,13 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
SystemClock.nanoTime(),
|
||||
editText.getText().toString()));
|
||||
}
|
||||
if (actionId == EditorInfo.IME_ACTION_NEXT ||
|
||||
actionId == EditorInfo.IME_ACTION_PREVIOUS) {
|
||||
if (editText.getBlurOnSubmit()) {
|
||||
editText.clearFocus();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return !editText.getBlurOnSubmit();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user