-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intrinsic content size for ReactTextInput (aka autoexpandable <TextIn…
…put> on Android) Summary: After this diff the intrinsic content size of <TextInput> reflects the size of text inside EditText, it means that if there is no additional style constraints, <TextInput> will grow with containing text. If you want to constraint minimum or maximum height, just do it via Yoga styling. Reviewed By: achen1 Differential Revision: D5828366 fbshipit-source-id: eccd0cb4ccf724c7096c947332a64a0a1e402673
- Loading branch information
1 parent
d0790fe
commit c550f27
Showing
4 changed files
with
191 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputLocalData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.views.textinput; | ||
|
||
import android.os.Build; | ||
import android.text.SpannableString; | ||
import android.util.TypedValue; | ||
import android.widget.EditText; | ||
|
||
/** Local state bearer for EditText instance. */ | ||
public final class ReactTextInputLocalData { | ||
|
||
private final SpannableString mText; | ||
private final float mTextSize; | ||
private final int mMinLines; | ||
private final int mMaxLines; | ||
private final int mInputType; | ||
private final int mBreakStrategy; | ||
|
||
public ReactTextInputLocalData(EditText editText) { | ||
mText = new SpannableString(editText.getText()); | ||
mTextSize = editText.getTextSize(); | ||
mMinLines = editText.getMinLines(); | ||
mMaxLines = editText.getMaxLines(); | ||
mInputType = editText.getInputType(); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
mBreakStrategy = editText.getBreakStrategy(); | ||
} else { | ||
mBreakStrategy = 0; | ||
} | ||
} | ||
|
||
public void apply(EditText editText) { | ||
editText.setText(mText); | ||
editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); | ||
editText.setMinLines(mMinLines); | ||
editText.setMaxLines(mMaxLines); | ||
editText.setInputType(mInputType); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
editText.setBreakStrategy(mBreakStrategy); | ||
} | ||
} | ||
} |
Oops, something went wrong.