mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-08 22:42:40 +08:00
implement android maxlength prop
Summary: Fixes https://github.com/facebook/react-native/issues/3864 But I don't sure that this code is correct. But it works and works same as in iOS. Closes https://github.com/facebook/react-native/pull/3873 Reviewed By: mikearmstrong001 Differential Revision: D2626122 Pulled By: andreicoman11 fb-gh-sync-id: 316915c99b218ed5f32ca90fd72ce9810571383a
This commit is contained in:
committed by
facebook-github-bot-2
parent
527d11ce01
commit
b6340ee2b0
@@ -24,6 +24,7 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.TextView;
|
||||
import android.text.InputFilter;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.JSApplicationCausedNativeException;
|
||||
@@ -53,6 +54,7 @@ public class ReactTextInputManager extends
|
||||
|
||||
private static final String KEYBOARD_TYPE_EMAIL_ADDRESS = "email-address";
|
||||
private static final String KEYBOARD_TYPE_NUMERIC = "numeric";
|
||||
private static final InputFilter[] EMPTY_FILTERS = new InputFilter[0];
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -199,6 +201,17 @@ public class ReactTextInputManager extends
|
||||
view.setLines(numLines);
|
||||
}
|
||||
|
||||
@ReactProp(name = "maxLength")
|
||||
public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {
|
||||
if (maxLength == null) {
|
||||
view.setFilters(EMPTY_FILTERS);
|
||||
} else {
|
||||
InputFilter[] filterArray = new InputFilter[1];
|
||||
filterArray[0] = new InputFilter.LengthFilter(maxLength);
|
||||
view.setFilters(filterArray);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "autoCorrect")
|
||||
public void setAutoCorrect(ReactEditText view, @Nullable Boolean autoCorrect) {
|
||||
// clear auto correct flags, set SUGGESTIONS or NO_SUGGESTIONS depending on value
|
||||
|
||||
Reference in New Issue
Block a user