public final class TextInput extends Component
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 |
Component.ContainerBuilder<T extends Component.ContainerBuilder<T>>
ComponentLifecycle.MountType, ComponentLifecycle.RenderData, ComponentLifecycle.TransitionContainer
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
ComponentLifecycle is able to measure itself according to specific size
constraints. |
protected boolean |
canPreallocate() |
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 |
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 |
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<KeyPreImeEvent> |
getKeyPreImeEventHandler(ComponentContext context) |
static EventHandler<KeyUpEvent> |
getKeyUpEventHandler(ComponentContext context) |
ComponentLifecycle.MountType |
getMountType()
This indicates the type of the
Object that will be returned by ComponentLifecycle.mount(com.facebook.litho.ComponentContext, java.lang.Object) . |
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 |
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 |
isEquivalentTo(Component other)
Compares this component to a different one to check if they are the same
|
boolean |
isPureRender() |
TextInput |
makeShallowCopy() |
protected void |
onBind(ComponentContext c,
java.lang.Object editText) |
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) |
protected void |
onMount(ComponentContext c,
java.lang.Object editText)
Deploy all UI elements representing the final bounds defined in the given
ComponentLayout . |
protected void |
onUnbind(ComponentContext c,
java.lang.Object editText) |
protected void |
onUnmount(ComponentContext c,
java.lang.Object editText)
Unload UI elements associated with this component.
|
protected int |
poolSize() |
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 |
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 |
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 |
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 |
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)
|
bindDynamicProp, canResolve, clearCachedLayout, copyInterStageImpl, createInterStagePropsContainer, getCommonProps, getDynamicProps, getErrorHandler, getEventDispatcher, getInterStagePropsContainer, getScopedContext, getSimpleName, getSimpleNameDelegate, getStateContainer, hasClickHandlerSet, markLayoutStarted, measure, measureMightNotCacheInternalNode, registerWorkingRange, retrieveValue, setInterStagePropsContainer, setScopedContext, setStateContainer, toString, updateInternalChildState, willRender
acceptTriggerEvent, applyPreviousRenderData, callsShouldUpdateOnMount, createMountContent, dispatchErrorEvent, dispatchErrorEvent, dispatchOnEnteredRange, dispatchOnEvent, dispatchOnEventImpl, dispatchOnExitedRange, getEventTrigger, getEventTrigger, getExtraAccessibilityNodeAt, getExtraAccessibilityNodesCount, getTreePropsForChildren, hasAttachDetachCallback, hasChildLithoViews, hasOwnErrorHandler, implementsAccessibility, implementsExtraAccessibilityNodes, isLayoutSpecWithSizeSpecCheck, isMountSizeDependent, needsPreviousRenderData, newEventHandler, newEventTrigger, newEventTrigger, onAttached, onBoundsDefined, onCreateLayout, onCreateLayoutWithSizeSpec, onCreateMountContentPool, onCreateTransition, onDetached, onError, onMeasureBaseline, onPopulateAccessibilityNode, onPopulateExtraAccessibilityNode, onPrepare, onShouldCreateLayoutWithNewSizeSpec, populateTreeProps, recordRenderData, resolve, shouldAlwaysRemeasure
protected com.facebook.litho.widget.TextInput.TextInputStateContainer createStateContainer()
createStateContainer
in class Component
public boolean isEquivalentTo(Component other)
Component
This is used to be able to skip rendering a component again. We avoid using the Object.equals(Object)
so we can optimize the code better over time since we don't have to
adhere to the contract required for a equals method.
isEquivalentTo
in interface Equivalence<Component>
isEquivalentTo
in class Component
other
- the component to compare topublic TextInput makeShallowCopy()
makeShallowCopy
in class Component
protected void createInitialState(ComponentContext _0)
createInitialState
in class ComponentLifecycle
protected void onLoadStyle(ComponentContext c)
onLoadStyle
in class ComponentLifecycle
protected void onMeasure(ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size)
onMeasure
in class ComponentLifecycle
protected boolean canMeasure()
ComponentLifecycle
ComponentLifecycle
is able to measure itself according to specific size
constraints.canMeasure
in class ComponentLifecycle
protected boolean shouldUpdate(Component _prevAbstractImpl, StateContainer _prevStateContainer, Component _nextAbstractImpl, StateContainer _nextStateContainer)
ComponentLifecycle
For 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 ComponentLifecycle
_prevAbstractImpl
- the previous component to compare against._nextAbstractImpl
- the component that is now in use.protected java.lang.Object onCreateMountContent(Context c)
ComponentLifecycle
LithoView
.onCreateMountContent
in class ComponentLifecycle
c
- The Context
to be used to create the content.protected void onMount(ComponentContext c, java.lang.Object editText)
ComponentLifecycle
ComponentLayout
. Return either a Drawable
or a View
or null
to be
mounted.onMount
in class ComponentLifecycle
c
- The ComponentContext
to mount the component into.protected void onBind(ComponentContext c, java.lang.Object editText)
onBind
in class ComponentLifecycle
protected void onUnmount(ComponentContext c, java.lang.Object editText)
ComponentLifecycle
onUnmount
in class ComponentLifecycle
c
- The Context
for this mount operation.editText
- The Drawable
or View
mounted by this component.protected void onUnbind(ComponentContext c, java.lang.Object editText)
onUnbind
in class ComponentLifecycle
public ComponentLifecycle.MountType getMountType()
ComponentLifecycle
Object
that will be returned by ComponentLifecycle.mount(com.facebook.litho.ComponentContext, java.lang.Object)
.getMountType
in class ComponentLifecycle
ComponentLifecycle.MountType
protected int poolSize()
poolSize
in class ComponentLifecycle
protected boolean canPreallocate()
canPreallocate
in class ComponentLifecycle
public boolean isPureRender()
isPureRender
in class ComponentLifecycle
public static EventHandler<TextChangedEvent> getTextChangedEventHandler(ComponentContext context)
public static EventHandler<SelectionChangedEvent> getSelectionChangedEventHandler(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 requestFocusTrigger(ComponentContext c, java.lang.String key)
requestFocus(ComponentContext, Handle)
.@Deprecated public static EventTrigger clearFocusTrigger(ComponentContext c, java.lang.String key)
clearFocus(ComponentContext, Handle)
.@Deprecated public static EventTrigger getTextTrigger(ComponentContext c, java.lang.String key)
getText(ComponentContext, Handle)
.@Deprecated public static EventTrigger setTextTrigger(ComponentContext c, java.lang.String key)
#setText(ComponentContext, Handle)
.@Deprecated public static EventTrigger dispatchKeyTrigger(ComponentContext c, java.lang.String key)
#dispatchKey(ComponentContext, Handle)
.@Deprecated public static EventTrigger 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 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 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 ComponentLifecycle
public void recordEventTrigger(ComponentContext c, EventTriggersContainer container)
recordEventTrigger
in interface HasEventTrigger
recordEventTrigger
in class Component
protected boolean hasState()
hasState
in class ComponentLifecycle
protected void transferState(StateContainer _prevStateContainer, StateContainer _nextStateContainer)
ComponentLifecycle
transferState
in class ComponentLifecycle
protected 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)