3030import java .util .HashMap ;
3131import java .util .LinkedList ;
3232import java .util .Map ;
33- public class VariableTextInputViewManager extends SimpleViewManager <VariableTextInput > {
33+
34+ public class VariableTextInputViewManager extends SimpleViewManager <VariableTextInput > {
3435 private enum RNTONATIVEMETHOD {
3536 focus ("focus" ),
3637 blur ("blur" ),
3738 insertEmoji ("insertEmoji" ),
3839 insertMentions ("insertMentions" ),
3940 changeAttributedText ("changeAttributedText" );
41+
4042 private String name ;
41- RNTONATIVEMETHOD (String name ){
43+
44+ RNTONATIVEMETHOD (String name ) {
4245 this .name = name ;
4346 }
44- public String getName (){
47+
48+ public String getName () {
4549 return name ;
4650 }
4751 }
52+
4853 private static final int [] PADDING_TYPES = {
49- Spacing .ALL , Spacing .LEFT , Spacing .RIGHT , Spacing .TOP , Spacing .BOTTOM ,
54+ Spacing .ALL , Spacing .LEFT , Spacing .RIGHT , Spacing .TOP , Spacing .BOTTOM ,
5055 };
5156 private static final int [] SPACING_TYPES = {
52- Spacing .ALL , Spacing .LEFT , Spacing .RIGHT , Spacing .TOP , Spacing .BOTTOM ,
57+ Spacing .ALL , Spacing .LEFT , Spacing .RIGHT , Spacing .TOP , Spacing .BOTTOM ,
5358 };
5459 public static final String REACT_CLASS = "VariableTextInputView" ;
5560 ReactApplicationContext mCallerContext ;
5661 VariableTextInput editText ;
57- public VariableTextInputViewManager (ReactApplicationContext reactContext ){
62+
63+ public VariableTextInputViewManager (ReactApplicationContext reactContext ) {
5864 mCallerContext = reactContext ;
5965 }
66+
6067 @ Override
6168 @ NonNull
6269 public String getName () {
6370 return REACT_CLASS ;
6471 }
72+
6573 @ Override
6674 @ NonNull
6775 public VariableTextInput createViewInstance (final ThemedReactContext reactContext ) {
6876 editText = new VariableTextInput (reactContext );
6977 return editText ;
7078 }
79+
7180 @ ReactProp (name = "text" )
7281 public void setText (VariableTextInput view , String text ) {
7382 view .setText (text );
@@ -79,34 +88,40 @@ public void setColor(VariableTextInput view, @Nullable Integer color) {
7988 view .setTextColor (color );
8089 }
8190 }
91+
8292 @ ReactProp (name = ViewProps .BACKGROUND_COLOR , customType = "Color" )
8393 public void setBackGroundColor (VariableTextInput view , @ Nullable Integer color ) {
8494 if (color != null ) {
8595 view .setBackGroundColor (color );
8696 }
8797 }
98+
8899 @ ReactProp (name = ViewProps .FONT_SIZE , customType = "FontColor" )
89100 public void setFontSize (VariableTextInput view , @ Nullable Integer fontSize ) {
90101 if (fontSize != null ) {
91102 view .setFontSize (fontSize );
92103 }
93104 }
94- @ ReactProp (name =ViewProps .FONT_FAMILY ,customType = "FontFamily" )
95- public void setFontFontFamily (VariableTextInput view ,@ Nullable String fontFamily ){
96- if (fontFamily != null ){
105+
106+ @ ReactProp (name = ViewProps .FONT_FAMILY , customType = "FontFamily" )
107+ public void setFontFontFamily (VariableTextInput view , @ Nullable String fontFamily ) {
108+ if (fontFamily != null ) {
97109 view .setFontFamily (fontFamily );
98110 }
99111 }
112+
100113 @ ReactProp (name = "selectionColor" , customType = "Color" )
101114 public void setSelectionColor (VariableTextInput view , @ Nullable Integer color ) {
102115 if (color != null ) {
103116 view .setHighlightColor (color );
104117 }
105118 }
119+
106120 @ ReactProp (name = "maxLength" )
107121 public void setMaxLength (VariableTextInput view , @ Nullable Integer maxLength ) {
108- view .setMaxLength (maxLength );
122+ view .setMaxLength (maxLength );
109123 }
124+
110125 @ ReactProp (name = "handlesColor" , customType = "Color" )
111126 public void setHandlesColor (VariableTextInput view , @ Nullable Integer color ) {
112127 if (color != null ) {
@@ -115,20 +130,19 @@ public void setHandlesColor(VariableTextInput view, @Nullable Integer color) {
115130 }
116131
117132 @ ReactPropGroup (names = {
118- "padding" , "paddingLeft" , "paddingRight" , "paddingTop" , "paddingBottom"
133+ "padding" , "paddingLeft" , "paddingRight" , "paddingTop" , "paddingBottom"
119134 }, customType = "String" )
120135 public void setPadding (VariableTextInput view , int index , Integer padding ) {
121136 view .setContentPadding (PADDING_TYPES [index ], padding );
122137 }
123- @ ReactPropGroup (
124- names = {
138+
139+ @ ReactPropGroup ( names = {
125140 ViewProps .BORDER_RADIUS ,
126141 ViewProps .BORDER_TOP_LEFT_RADIUS ,
127142 ViewProps .BORDER_TOP_RIGHT_RADIUS ,
128143 ViewProps .BORDER_BOTTOM_RIGHT_RADIUS ,
129144 ViewProps .BORDER_BOTTOM_LEFT_RADIUS
130- },
131- defaultFloat = YogaConstants .UNDEFINED )
145+ }, defaultFloat = YogaConstants .UNDEFINED )
132146 public void setBorderRadius (VariableTextInput view , int index , float borderRadius ) {
133147 if (!YogaConstants .isUndefined (borderRadius )) {
134148 borderRadius = PixelUtil .toPixelFromDIP (borderRadius );
@@ -140,40 +154,39 @@ public void setBorderRadius(VariableTextInput view, int index, float borderRadiu
140154 view .setBorderRadius (borderRadius , index - 1 );
141155 }
142156 }
143- @ ReactPropGroup (
144- names = {
157+
158+ @ ReactPropGroup ( names = {
145159 ViewProps .BORDER_WIDTH ,
146160 ViewProps .BORDER_LEFT_WIDTH ,
147161 ViewProps .BORDER_RIGHT_WIDTH ,
148162 ViewProps .BORDER_TOP_WIDTH ,
149163 ViewProps .BORDER_BOTTOM_WIDTH ,
150- },
151- defaultFloat = YogaConstants .UNDEFINED )
164+ }, defaultFloat = YogaConstants .UNDEFINED )
152165 public void setBorderWidth (VariableTextInput view , int index , float width ) {
153166 if (!YogaConstants .isUndefined (width )) {
154167 width = PixelUtil .toPixelFromDIP (width );
155168 }
156169 view .setBorderWidth (SPACING_TYPES [index ], width );
157170 }
158- @ ReactPropGroup (
159- names = {
171+
172+ @ ReactPropGroup ( names = {
160173 "borderColor" ,
161174 "borderLeftColor" ,
162175 "borderRightColor" ,
163176 "borderTopColor" ,
164177 "borderBottomColor"
165- },
166- customType = "Color" )
178+ }, customType = "Color" )
167179 public void setBorderColor (VariableTextInput view , int index , Integer color ) {
168- float rgbComponent =
169- color == null ? YogaConstants .UNDEFINED : (float ) ((int ) color & 0x00FFFFFF );
180+ float rgbComponent = color == null ? YogaConstants .UNDEFINED : (float ) ((int ) color & 0x00FFFFFF );
170181 float alphaComponent = color == null ? YogaConstants .UNDEFINED : (float ) ((int ) color >>> 24 );
171182 view .setBorderColor (SPACING_TYPES [index ], rgbComponent , alphaComponent );
172183 }
184+
173185 @ ReactProp (name = "borderStyle" )
174186 public void setBorderStyle (VariableTextInput view , @ Nullable String borderStyle ) {
175187 view .setBorderStyle (borderStyle );
176188 }
189+
177190 @ ReactProp (name = "autoFocus" )
178191 public void setAutoFocus (VariableTextInput view , boolean autoFocus ) {
179192 view .setAutoFocus (autoFocus );
@@ -188,38 +201,45 @@ public void blur(VariableTextInput view) {
188201 view .blur ();
189202 }
190203
191- @ ReactProp (name = "placeholder" )
192- public void setPlaceholder (VariableTextInput view , String placeholder ){
204+ @ ReactProp (name = "placeholder" )
205+ public void setPlaceholder (VariableTextInput view , String placeholder ) {
193206 view .setPlaceholder (placeholder );
194207 }
195- @ ReactProp (name ="placeholderTextColor" ,customType = "Color" )
196- public void setPlaceholderTextColor (VariableTextInput view , @ Nullable Integer placeholderColor ){
208+
209+ @ ReactProp (name = "placeholderTextColor" , customType = "Color" )
210+ public void setPlaceholderTextColor (VariableTextInput view , @ Nullable Integer placeholderColor ) {
197211 view .setPlaceholderColor (placeholderColor );
198212 }
213+
199214 @ ReactProp (name = "selectionColor" , customType = "Color" )
200215 public void setSelectionColor (EditText view , @ Nullable Integer color ) {
201216 if (color != null ) {
202217 view .setHighlightColor (color );
203218 }
204219 }
220+
205221 @ ReactProp (name = "disableFullscreenUI" , defaultBoolean = false )
206222 public void setDisableFullscreenUI (VariableTextInput view , boolean disableFullscreenUI ) {
207223 view .setDisableFullscreenUI (disableFullscreenUI );
208224 }
225+
209226 @ ReactProp (name = "returnKeyType" )
210227 public void setReturnKeyType (VariableTextInput view , String returnKeyType ) {
211228 view .setReturnKeyType (returnKeyType );
212229 }
230+
213231 private static final int IME_ACTION_ID = 0x670 ;
214232
215233 @ ReactProp (name = "returnKeyLabel" )
216234 public void setReturnKeyLabel (VariableTextInput view , String returnKeyLabel ) {
217235 view .setImeActionLabel (returnKeyLabel , IME_ACTION_ID );
218236 }
237+
219238 @ ReactProp (name = "submitBehavior" )
220239 public void setSubmitBehavior (VariableTextInput view , @ Nullable String submitBehavior ) {
221240 view .setSubmitBehavior (submitBehavior );
222241 }
242+
223243 @ ReactProp (name = "underlineColorAndroid" , customType = "Color" )
224244 public void setUnderlineColor (VariableTextInput view , @ Nullable Integer underlineColor ) {
225245 // Drawable.mutate() can sometimes crash due to an AOSP bug:
@@ -235,7 +255,8 @@ public void setUnderlineColor(VariableTextInput view, @Nullable Integer underlin
235255 try {
236256 drawableToMutate = background .mutate ();
237257 } catch (NullPointerException e ) {
238- // FLog.e(TAG, "NullPointerException when setting underlineColorAndroid for TextInput", e);
258+ // FLog.e(TAG, "NullPointerException when setting underlineColorAndroid for
259+ // TextInput", e);
239260 }
240261 }
241262
@@ -254,19 +275,20 @@ public void setUnderlineColor(VariableTextInput view, @Nullable Integer underlin
254275 }
255276 }
256277 }
278+
257279 @ ReactProp (name = "onSelectionChange" , defaultBoolean = false )
258280 public void setOnSelectionChange (final VariableTextInput view , boolean onSelectionChange ) {
259- // if (onSelectionChange) {
260- // view.setSelectionWatcher(new ReactSelectionWatcher(view));
261- // } else {
262- // view.setSelectionWatcher(null);
263- // }
281+ // if (onSelectionChange) {
282+ // view.setSelectionWatcher(new ReactSelectionWatcher(view));
283+ // } else {
284+ // view.setSelectionWatcher(null);
285+ // }
264286 }
287+
265288 @ ReactProp (name = "keyboardType" )
266289 public void setKeyboardType (VariableTextInput view , String keyboardType ) {
267290 switch (keyboardType ) {
268- case "default" :
269- {
291+ case "default" : {
270292 view .setImeOptions (EditorInfo .IME_ACTION_NONE );
271293 view .setInputType (EditorInfo .TYPE_CLASS_TEXT );
272294 }
@@ -293,33 +315,37 @@ public void setKeyboardType(VariableTextInput view, String keyboardType) {
293315 break ;
294316 }
295317 }
318+
296319 /**
297320 * 接受交互通知
321+ *
298322 * @return
299- * * /
323+ */
300324 @ Nullable
301325 @ Override
302326 public Map <String , Integer > getCommandsMap () {
303- Map <String ,Integer > map = new HashMap <>();
304- map .put (RNTONATIVEMETHOD .focus .name ,5 );
327+ Map <String , Integer > map = new HashMap <>();
328+ map .put (RNTONATIVEMETHOD .focus .name , 5 );
305329 map .put (RNTONATIVEMETHOD .blur .name , 1 );
306330 map .put (RNTONATIVEMETHOD .insertEmoji .name , 2 );
307331 map .put (RNTONATIVEMETHOD .insertMentions .name , 3 );
308332 map .put (RNTONATIVEMETHOD .changeAttributedText .name , 4 );
309333 return map ;
310334 }
335+
311336 /**
312337 * 根据命令ID,处理对应任务
338+ *
313339 * @param root
314340 * @param commandId
315341 * @param args
316- * * /
342+ */
317343 @ Override
318344 public void receiveCommand (VariableTextInput root , int commandId , @ Nullable ReadableArray args ) {
319345
320- switch (commandId ){
346+ switch (commandId ) {
321347 case 5 :
322- //focus打开键盘
348+ // focus打开键盘
323349 root .focus ();
324350 break ;
325351 case 1 :
@@ -330,7 +356,7 @@ public void receiveCommand(VariableTextInput root, int commandId, @Nullable Read
330356 root .handleRichText (args );
331357 break ;
332358 case 4 :
333- //更改富文本
359+ // 更改富文本
334360 root .clearText ();
335361 root .handleRichText (args );
336362 break ;
@@ -345,12 +371,13 @@ public Map<String, Object> getConstants() {
345371 constants .put ("EVENT_NAME" , "onChange" );
346372 return constants ;
347373 }
374+
348375 @ Override
349376 public @ Nullable Map getExportedCustomDirectEventTypeConstants () {
350377 return MapBuilder .builder ().put (
351- "onAndroidChange" ,
352- MapBuilder .of ("registrationName" , "onAndroidChange" )
353- ). put ( "onAndroidContentSizeChange" ,
354- MapBuilder . of ( "registrationName" , "onAndroidTextInput" )) .put ("onAndroidTextInput" ,MapBuilder .of ("registrationName" ,"onAndroidTextInput" )).build ();
378+ "onAndroidChange" ,
379+ MapBuilder .of ("registrationName" , "onAndroidChange" )). put ( "onAndroidContentSizeChange" ,
380+ MapBuilder . of ( "registrationName" , "onAndroidContentSizeChange" ))
381+ .put ("onAndroidTextInput" , MapBuilder .of ("registrationName" , "onAndroidTextInput" )).build ();
355382 }
356383}
0 commit comments