public final class TextInput extends SpecGeneratedComponent
EditText. It is measured
based on the input text String representation.
Performance is critical for good user experience. Follow these tips for good performance:
OnTrigger to update text, request view
focus or set selection. TextInput.setText(c, key, text).
Because this component is backed by android EditText many native capabilities are
applicable:
InputFilter to set a text length limit or modify text input.
android.text.InputType
constants.
It is also treated by the system as an android EditText:
EditText receives focus, a system keyboard is shown.
EditText is the first element in the
View hierarchy, it gains focus.
Example of multiline editable text with custom text color, text length limit, removed underline drawable, and sentence capitalisation:
private static final InputFilter lenFilter = new InputFilter.LengthFilter(maxLength);
TextInput.create(c)
.initialText(text)
.textColorStateList(ColorStateList.valueOf(color))
.multiline(true)
.inputFilter(lenFilter)
.backgroundColor(Color.TRANSPARENT)
.inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
.build();
com.facebook.litho.widget.TextInputSpec| Modifier and Type | Class and Description |
|---|---|
static class |
TextInput.Builder |
SpecGeneratedComponent.TransitionContainerComponent.ContainerBuilder<T extends Component.ContainerBuilder<T>>, Component.MountType, Component.RenderData| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
acceptTriggerEventImpl(EventTrigger eventTrigger,
java.lang.Object eventState,
java.lang.Object[] params) |
protected boolean |
canMeasure()
Whether this
Component is able to measure itself according to
specific size constraints. |
boolean |
canPreallocate()
This API informs the framework to fill the content pool for this Mountable ahead of time.
|
static void |
clearFocus(ComponentContext c,
Handle handle)
This will send the clearFocus trigger to the component with the given handle.
|
static void |
clearFocus(ComponentContext c,
java.lang.String key)
Deprecated.
Use
clearFocus(ComponentContext, Handle) instead. |
static void |
clearFocus(EventTrigger trigger)
Deprecated.
Use
clearFocus(ComponentContext, Handle) instead. |
static EventTrigger<ClearFocusEvent> |
clearFocusTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
clearFocus(ComponentContext, Handle). |
static TextInput.Builder |
create(ComponentContext context) |
static TextInput.Builder |
create(ComponentContext context,
int defStyleAttr,
int defStyleRes) |
protected void |
createInitialState(ComponentContext _0) |
protected com.facebook.litho.widget.TextInput.TextInputStateContainer |
createStateContainer() |
static void |
dispatchKey(ComponentContext c,
Handle handle,
KeyEvent keyEvent)
This will send the dispatchKey trigger to the component with the given handle.
|
static void |
dispatchKey(ComponentContext c,
java.lang.String key,
KeyEvent keyEvent)
Deprecated.
Use
#dispatchKey(ComponentContext, Handle) instead. |
static void |
dispatchKey(EventTrigger trigger,
KeyEvent keyEvent)
Deprecated.
Use
#dispatchKey(ComponentContext, Handle) instead. |
static EventTrigger<DispatchKeyEvent> |
dispatchKeyTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
#dispatchKey(ComponentContext, Handle). |
static EventHandler<EditorActionEvent> |
getEditorActionEventHandler(ComponentContext context) |
static EventHandler<InputConnectionEvent> |
getInputConnectionEventHandler(ComponentContext context) |
static EventHandler<InputFocusChangedEvent> |
getInputFocusChangedEventHandler(ComponentContext context) |
static EventHandler<KeyPreImeEvent> |
getKeyPreImeEventHandler(ComponentContext context) |
static EventHandler<KeyUpEvent> |
getKeyUpEventHandler(ComponentContext context) |
static java.lang.Integer |
getLineCount(ComponentContext c,
Handle handle)
This will send the getLineCount trigger to the component with the given handle.
|
static java.lang.Integer |
getLineCount(ComponentContext c,
java.lang.String key)
Deprecated.
Use
getLineCount(ComponentContext, Handle) instead. |
static java.lang.Integer |
getLineCount(EventTrigger trigger)
Deprecated.
Use
getLineCount(ComponentContext, Handle) instead. |
static EventTrigger<GetLineCountEvent> |
getLineCountTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
getLineCount(ComponentContext, Handle). |
Component.MountType |
getMountType()
This indicates the type of the
Object that will be returned by com.facebook.litho.Component#mount. |
static EventHandler<SelectionChangedEvent> |
getSelectionChangedEventHandler(ComponentContext context) |
static EventHandler<SetTextEvent> |
getSetTextEventHandler(ComponentContext context) |
static java.lang.CharSequence |
getText(ComponentContext c,
Handle handle)
This will send the getText trigger to the component with the given handle.
|
static java.lang.CharSequence |
getText(ComponentContext c,
java.lang.String key)
Deprecated.
Use
getText(ComponentContext, Handle) instead. |
static java.lang.CharSequence |
getText(EventTrigger trigger)
Deprecated.
Use
getText(ComponentContext, Handle) instead. |
static EventHandler<TextChangedEvent> |
getTextChangedEventHandler(ComponentContext context) |
static EventTrigger<GetTextEvent> |
getTextTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
getText(ComponentContext, Handle). |
protected boolean |
hasState() |
boolean |
implementsShouldUpdate() |
boolean |
isEquivalentProps(Component other,
boolean shouldCompareCommonProps)
Determine if this component has equivalent props to a given component.
|
boolean |
isPureRender() |
TextInput |
makeShallowCopy() |
protected void |
onBind(ComponentContext c,
java.lang.Object editText,
InterStagePropsContainer _2) |
protected java.lang.Object |
onCreateMountContent(Context c)
Create the object that will be mounted in the
LithoView. |
protected void |
onLoadStyle(ComponentContext c) |
protected void |
onMeasure(ComponentContext c,
ComponentLayout layout,
int widthSpec,
int heightSpec,
Size size,
InterStagePropsContainer _5) |
protected void |
onMount(ComponentContext c,
java.lang.Object editText,
InterStagePropsContainer _2)
Deploy all UI elements representing the final bounds defined in the given
ComponentLayout. |
protected void |
onUnbind(ComponentContext c,
java.lang.Object editText,
InterStagePropsContainer _2) |
protected void |
onUnmount(ComponentContext c,
java.lang.Object editText,
InterStagePropsContainer _2)
Unload UI elements associated with this component.
|
int |
poolSize()
This API informs the framework about the size of the content pool.
|
void |
recordEventTrigger(ComponentContext c,
EventTriggersContainer container) |
protected static void |
remeasureForUpdatedText(ComponentContext c) |
protected static void |
remeasureForUpdatedTextAsync(ComponentContext c) |
protected static void |
remeasureForUpdatedTextSync(ComponentContext c) |
static void |
replaceText(ComponentContext c,
Handle handle,
java.lang.CharSequence text,
int startIndex,
int endIndex)
This will send the replaceText trigger to the component with the given handle.
|
static void |
replaceText(ComponentContext c,
java.lang.String key,
java.lang.CharSequence text,
int startIndex,
int endIndex)
Deprecated.
Use
#replaceText(ComponentContext, Handle) instead. |
static void |
replaceText(EventTrigger trigger,
java.lang.CharSequence text,
int startIndex,
int endIndex)
Deprecated.
Use
#replaceText(ComponentContext, Handle) instead. |
static EventTrigger<ReplaceTextEvent> |
replaceTextTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
#replaceText(ComponentContext, Handle). |
static void |
requestFocus(ComponentContext c,
Handle handle)
This will send the requestFocus trigger to the component with the given handle.
|
static void |
requestFocus(ComponentContext c,
java.lang.String key)
Deprecated.
Use
requestFocus(ComponentContext, Handle) instead. |
static void |
requestFocus(EventTrigger trigger)
Deprecated.
Use
requestFocus(ComponentContext, Handle) instead. |
static EventTrigger<RequestFocusEvent> |
requestFocusTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
requestFocus(ComponentContext, Handle). |
static void |
setSelection(ComponentContext c,
Handle handle,
int start,
int end)
This will send the setSelection trigger to the component with the given handle.
|
static void |
setSelection(ComponentContext c,
java.lang.String key,
int start,
int end)
Deprecated.
Use
#setSelection(ComponentContext, Handle) instead. |
static void |
setSelection(EventTrigger trigger,
int start,
int end)
Deprecated.
Use
#setSelection(ComponentContext, Handle) instead. |
static EventTrigger<SetSelectionEvent> |
setSelectionTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
#setSelection(ComponentContext, Handle). |
static void |
setText(ComponentContext c,
Handle handle,
java.lang.CharSequence text)
This will send the setText trigger to the component with the given handle.
|
static void |
setText(ComponentContext c,
java.lang.String key,
java.lang.CharSequence text)
Deprecated.
Use
#setText(ComponentContext, Handle) instead. |
static void |
setText(EventTrigger trigger,
java.lang.CharSequence text)
Deprecated.
Use
#setText(ComponentContext, Handle) instead. |
static EventTrigger<SetTextEvent> |
setTextTrigger(ComponentContext c,
java.lang.String key)
Deprecated.
Do not use this method to get a EventTrigger to use later. Instead give the component a Handle and use
#setText(ComponentContext, Handle). |
protected boolean |
shouldUpdate(Component _prevAbstractImpl,
StateContainer _prevStateContainer,
Component _nextAbstractImpl,
StateContainer _nextStateContainer)
Whether the component needs updating.
|
protected void |
transferState(StateContainer _prevStateContainer,
StateContainer _nextStateContainer)
|
acceptTriggerEvent, applyPreviousRenderData, bindDynamicProp, copyInterStageImpl, copyPrepareInterStageImpl, createContent, createInterStagePropsContainer, createPoolableContent, createPrepareInterStagePropsContainer, createRecyclingPool, dispatchOnEnteredRange, dispatchOnExitedRange, getExtraAccessibilityNodeAt, getExtraAccessibilityNodesCount, getInterStagePropsContainer, getPoolableContentType, getPrepareInterStagePropsContainer, getSimpleName, getSimpleNameDelegate, getTreePropsForChildren, hasAttachDetachCallback, hasOwnErrorHandler, implementsAccessibility, implementsExtraAccessibilityNodes, isMountSizeDependent, isRecyclingDisabled, needsPreviousRenderData, onAttached, onBoundsDefined, onCreateLayout, onCreateLayoutWithSizeSpec, onCreateMountContentPool, onDetached, onError, onMeasureBaseline, onPrepare, populateTreeProps, prepare, recordRenderData, render, shouldAlwaysRemeasure, usesLocalStateContainerclone, createMountContent, dispatchErrorEvent, dispatchOnEvent, dispatchOnEventImpl, equals, excludeFromIncrementalMount, getCommonProps, getDynamicProps, getErrorHandler, getEventDispatcher, getEventTrigger, getEventTrigger, getHandle, getTreePropFromParent, getTypeId, hasChildLithoViews, hasClickHandlerSet, hashCode, isEqualivalentTreeProps, isEquivalentCommonProps, isEquivalentTo, isEquivalentTo, isLayoutSpecWithSizeSpec, isPureRender, measure, measure, measureMightNotCacheInternalNode, newEventHandler, newEventTrigger, newEventTrigger, onCreateTransition, onPopulateAccessibilityNode, onPopulateExtraAccessibilityNode, registerWorkingRange, resolve, retrieveValue, toString, willRenderprotected com.facebook.litho.widget.TextInput.TextInputStateContainer createStateContainer()
createStateContainer in class SpecGeneratedComponentpublic boolean isEquivalentProps(Component other, boolean shouldCompareCommonProps)
ComponentisEquivalentProps in class Componentother - the component to compare topublic TextInput makeShallowCopy()
makeShallowCopy in class Componentprotected void createInitialState(ComponentContext _0)
createInitialState in class SpecGeneratedComponentprotected void onLoadStyle(ComponentContext c)
onLoadStyle in class Componentprotected void onMeasure(ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, InterStagePropsContainer _5)
onMeasure in class SpecGeneratedComponentprotected boolean canMeasure()
ComponentComponent is able to measure itself according to
specific size constraints.canMeasure in class Componentprotected boolean shouldUpdate(Component _prevAbstractImpl, StateContainer _prevStateContainer, Component _nextAbstractImpl, StateContainer _nextStateContainer)
ComponentFor layout components, the framework will verify that none of the children of the component need updating, and that both components have the same number of children. Therefore this method just needs to determine any changes to the top-level component that would cause it to need to be updated (for example, a click handler was added).
For mount specs, the framework does nothing extra and this method alone determines whether the component is updated or not.
shouldUpdate in class Component_prevAbstractImpl - the previous component to compare against._nextAbstractImpl - the component that is now in use.public boolean implementsShouldUpdate()
implementsShouldUpdate in class Componentprotected java.lang.Object onCreateMountContent(Context c)
ComponentLithoView.onCreateMountContent in class Componentc - The Context to be used to create the content.protected void onMount(ComponentContext c, java.lang.Object editText, InterStagePropsContainer _2)
SpecGeneratedComponentComponentLayout. Return either a Drawable or a View or null to be
mounted.onMount in class SpecGeneratedComponentc - The ComponentContext to mount the component into.protected void onBind(ComponentContext c, java.lang.Object editText, InterStagePropsContainer _2)
onBind in class SpecGeneratedComponentprotected void onUnmount(ComponentContext c, java.lang.Object editText, InterStagePropsContainer _2)
SpecGeneratedComponentonUnmount in class SpecGeneratedComponentc - The Context for this mount operation.editText - The Drawable or View mounted by this component.protected void onUnbind(ComponentContext c, java.lang.Object editText, InterStagePropsContainer _2)
onUnbind in class SpecGeneratedComponentpublic Component.MountType getMountType()
ComponentObject that will be returned by com.facebook.litho.Component#mount.getMountType in class ComponentComponent.MountTypepublic int poolSize()
ContentAllocatorExperimental. Currently for Litho team internal use only.
poolSize in interface ContentAllocatorpoolSize in class SpecGeneratedComponentpublic boolean canPreallocate()
ContentAllocatorfalse, i.e. content is not pre-allocated. Pre-allocation of the
content can improve performance in some circumstances where creating the content is expensive.canPreallocate in interface ContentAllocatorcanPreallocate in class SpecGeneratedComponentpublic boolean isPureRender()
isPureRender in class Componentpublic static EventHandler<TextChangedEvent> getTextChangedEventHandler(ComponentContext context)
public static EventHandler<SelectionChangedEvent> getSelectionChangedEventHandler(ComponentContext context)
public static EventHandler<InputFocusChangedEvent> getInputFocusChangedEventHandler(ComponentContext context)
public static EventHandler<KeyUpEvent> getKeyUpEventHandler(ComponentContext context)
public static EventHandler<KeyPreImeEvent> getKeyPreImeEventHandler(ComponentContext context)
public static EventHandler<EditorActionEvent> getEditorActionEventHandler(ComponentContext context)
public static EventHandler<SetTextEvent> getSetTextEventHandler(ComponentContext context)
public static EventHandler<InputConnectionEvent> getInputConnectionEventHandler(ComponentContext context)
@Deprecated public static EventTrigger<RequestFocusEvent> requestFocusTrigger(ComponentContext c, java.lang.String key)
requestFocus(ComponentContext, Handle).@Deprecated public static EventTrigger<ClearFocusEvent> clearFocusTrigger(ComponentContext c, java.lang.String key)
clearFocus(ComponentContext, Handle).@Deprecated public static EventTrigger<GetTextEvent> getTextTrigger(ComponentContext c, java.lang.String key)
getText(ComponentContext, Handle).@Deprecated public static EventTrigger<GetLineCountEvent> getLineCountTrigger(ComponentContext c, java.lang.String key)
getLineCount(ComponentContext, Handle).@Deprecated public static EventTrigger<SetTextEvent> setTextTrigger(ComponentContext c, java.lang.String key)
#setText(ComponentContext, Handle).@Deprecated public static EventTrigger<ReplaceTextEvent> replaceTextTrigger(ComponentContext c, java.lang.String key)
#replaceText(ComponentContext, Handle).@Deprecated public static EventTrigger<DispatchKeyEvent> dispatchKeyTrigger(ComponentContext c, java.lang.String key)
#dispatchKey(ComponentContext, Handle).@Deprecated public static EventTrigger<SetSelectionEvent> setSelectionTrigger(ComponentContext c, java.lang.String key)
#setSelection(ComponentContext, Handle).public static void requestFocus(ComponentContext c, Handle handle)
@Deprecated public static void requestFocus(ComponentContext c, java.lang.String key)
requestFocus(ComponentContext, Handle) instead.@Deprecated public static void requestFocus(EventTrigger trigger)
requestFocus(ComponentContext, Handle) instead.public static void clearFocus(ComponentContext c, Handle handle)
@Deprecated public static void clearFocus(ComponentContext c, java.lang.String key)
clearFocus(ComponentContext, Handle) instead.@Deprecated public static void clearFocus(EventTrigger trigger)
clearFocus(ComponentContext, Handle) instead.public static java.lang.CharSequence getText(ComponentContext c, Handle handle)
@Deprecated public static java.lang.CharSequence getText(ComponentContext c, java.lang.String key)
getText(ComponentContext, Handle) instead.@Deprecated public static java.lang.CharSequence getText(EventTrigger trigger)
getText(ComponentContext, Handle) instead.public static java.lang.Integer getLineCount(ComponentContext c, Handle handle)
@Deprecated public static java.lang.Integer getLineCount(ComponentContext c, java.lang.String key)
getLineCount(ComponentContext, Handle) instead.@Deprecated public static java.lang.Integer getLineCount(EventTrigger trigger)
getLineCount(ComponentContext, Handle) instead.public static void setText(ComponentContext c, Handle handle, java.lang.CharSequence text)
@Deprecated public static void setText(ComponentContext c, java.lang.String key, java.lang.CharSequence text)
#setText(ComponentContext, Handle) instead.@Deprecated public static void setText(EventTrigger trigger, java.lang.CharSequence text)
#setText(ComponentContext, Handle) instead.public static void replaceText(ComponentContext c, Handle handle, java.lang.CharSequence text, int startIndex, int endIndex)
@Deprecated public static void replaceText(ComponentContext c, java.lang.String key, java.lang.CharSequence text, int startIndex, int endIndex)
#replaceText(ComponentContext, Handle) instead.@Deprecated public static void replaceText(EventTrigger trigger, java.lang.CharSequence text, int startIndex, int endIndex)
#replaceText(ComponentContext, Handle) instead.public static void dispatchKey(ComponentContext c, Handle handle, KeyEvent keyEvent)
@Deprecated public static void dispatchKey(ComponentContext c, java.lang.String key, KeyEvent keyEvent)
#dispatchKey(ComponentContext, Handle) instead.@Deprecated public static void dispatchKey(EventTrigger trigger, KeyEvent keyEvent)
#dispatchKey(ComponentContext, Handle) instead.public static void setSelection(ComponentContext c, Handle handle, int start, int end)
@Deprecated public static void setSelection(ComponentContext c, java.lang.String key, int start, int end)
#setSelection(ComponentContext, Handle) instead.@Deprecated public static void setSelection(EventTrigger trigger, int start, int end)
#setSelection(ComponentContext, Handle) instead.protected java.lang.Object acceptTriggerEventImpl(EventTrigger eventTrigger, java.lang.Object eventState, java.lang.Object[] params)
acceptTriggerEventImpl in class SpecGeneratedComponentpublic void recordEventTrigger(ComponentContext c, EventTriggersContainer container)
recordEventTrigger in interface HasEventTriggerrecordEventTrigger in class SpecGeneratedComponentprotected boolean hasState()
hasState in class SpecGeneratedComponentprotected void transferState(StateContainer _prevStateContainer, StateContainer _nextStateContainer)
ComponenttransferState in class Componentprotected static void remeasureForUpdatedText(ComponentContext c)
protected static void remeasureForUpdatedTextAsync(ComponentContext c)
protected static void remeasureForUpdatedTextSync(ComponentContext c)
public static TextInput.Builder create(ComponentContext context)
public static TextInput.Builder create(ComponentContext context, int defStyleAttr, int defStyleRes)