public class LithoView extends ComponentHost implements RootHost, AnimatedRootHost
ViewGroup
that can host the mounted state of a Component
.Modifier and Type | Class and Description |
---|---|
static interface |
LithoView.LayoutManagerOverrideParams
LayoutParams that override the LayoutManager.
|
static interface |
LithoView.OnDirtyMountListener |
static interface |
LithoView.OnPostDrawListener |
Modifier and Type | Field and Description |
---|---|
int |
mViewAttributeFlags |
static java.lang.String |
SET_ALREADY_ATTACHED_COMPONENT_TREE |
static java.lang.String |
ZERO_HEIGHT_LOG |
PARTIAL_ALPHA_TEXTURE_TOO_BIG, TEXTURE_TOO_BIG, TEXTURE_ZERO_DIM
Constructor and Description |
---|
LithoView(ComponentContext context,
AttributeSet attrs) |
LithoView(Context context) |
LithoView(Context context,
AttributeSet attrs) |
Modifier and Type | Method and Description |
---|---|
boolean |
componentTreeHasLifecycleProvider() |
static LithoView |
create(Context context,
Component component)
|
static LithoView |
create(Context context,
Component component,
LithoLifecycleProvider lifecycleProvider) |
static LithoView |
create(Context context,
ComponentTree componentTree)
Create a new
LithoView instance and initialize it with a custom ComponentTree . |
void |
dispatchVisibilityEvent(java.lang.Class<?> visibilityEventType)
Deprecated.
|
void |
draw(Canvas canvas) |
protected void |
forceRelayout() |
java.util.List<LithoView> |
getChildLithoViewsFromCurrentlyMountedItems() |
ComponentContext |
getComponentContext() |
ComponentTree |
getComponentTree() |
DynamicPropsManager |
getDynamicPropsManager() |
protected java.util.Map<java.lang.String,java.lang.Object> |
getLayoutErrorMetadata(int width,
int height) |
MountDelegateTarget |
getMountDelegateTarget() |
Rect |
getPreviousMountBounds() |
boolean |
isIncrementalMountEnabled() |
void |
notifyLithoViewGlobalPositionChanged()
Call this method when the LithoView's global position on screen has changed via manual offset.
|
void |
notifyVisibleBoundsChanged()
Notifies the host the its visible bounds may have potentially changed.
|
void |
notifyVisibleBoundsChanged(Rect visibleRect,
boolean processVisibilityOutputs)
This allows inner RootHosts to trigger a mount on a custom visibleRect.
|
void |
offsetLeftAndRight(int offset) |
void |
offsetTopAndBottom(int offset) |
protected void |
onAttachedToWindow() |
void |
onAttachedToWindowForTest()
Along with
onDetachedFromWindowForTest() below, makes the LithoView think it's attached/
detached in a unit test environment. |
protected void |
onDetachedFromWindow() |
void |
onDetachedFromWindowForTest() |
void |
onFinishTemporaryDetach() |
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec) |
void |
onStartTemporaryDetach() |
protected void |
performLayout(boolean changed,
int left,
int top,
int right,
int bottom) |
void |
rebind() |
void |
registerUIDebugger(MountExtension extension) |
void |
release()
Deprecated.
|
void |
rerenderForAccessibility(boolean enabled) |
void |
resetMountStartupLoggingInfo() |
void |
setAnimatedHeight(int height)
Sets the height that the LithoView should take on the next measure pass and then requests a
layout.
|
void |
setAnimatedWidth(int width)
Sets the width that the LithoView should take on the next measure pass and then requests a
layout.
|
void |
setComponent(Component component)
Change the root component synchronously.
|
void |
setComponentAsync(Component component)
Change the root component measuring it on a background thread before updating the UI.
|
void |
setComponentAsyncWithoutReconciliation(Component component)
Deprecated.
Use
setComponentAsync(Component) if reconciliation can be enabled. |
void |
setComponentTree(ComponentTree componentTree) |
void |
setComponentTree(ComponentTree componentTree,
boolean unmountAllWhenComponentTreeSetToNull) |
void |
setComponentWithoutReconciliation(Component component)
Deprecated.
Use
setComponent(Component) if reconciliation can be enabled. |
void |
setHasTransientState(boolean hasTransientState) |
void |
setInvalidStateLogParamsList(java.util.List<ComponentLogParams> logParamsList)
Register for particular invalid state logs.
|
void |
setMountStartupLoggingInfo(LithoStartupLogger startupLogger,
java.lang.String startupLoggerAttribution,
boolean[] firstMountCalled,
boolean[] lastMountCalled,
boolean isLastAdapterItem,
boolean isOrientationVertical) |
void |
setOnDirtyMountListener(LithoView.OnDirtyMountListener onDirtyMountListener) |
void |
setOnPostDrawListener(LithoView.OnPostDrawListener onPostDrawListener) |
void |
setRenderState(RenderState renderState) |
void |
setSkipMountingIfNotVisible(boolean skipMountingIfNotVisible)
If true, calling
setVisibilityHint(boolean, boolean) will delegate to setVisibilityHint(boolean) and skip mounting if the visibility hint was set to false. |
void |
setTranslationX(float translationX) |
void |
setTranslationY(float translationY) |
void |
setVisibilityHint(boolean isVisible)
Deprecated.
|
void |
setVisibilityHint(boolean isVisible,
boolean skipMountingIfNotVisible)
Deprecated.
|
protected boolean |
shouldAlwaysLayoutChildren()
Indicates if the children of this view should be laid regardless to a mount step being
triggered on layout.
|
protected boolean |
shouldRequestLayout() |
boolean |
skipNotifyVisibleBoundsChangedCalls() |
void |
startTemporaryDetach() |
boolean |
subscribeComponentTreeToLifecycleProvider(LithoLifecycleProvider lifecycleProvider)
If this LithoView has a ComponentTree attached to it, set a LithoLifecycleProvider if it
doesn't already have one.
|
void |
suppressMeasureComponentTree(boolean suppress)
If set to true, the onMeasure(..) call won't measure the ComponentTree with the given measure
specs, but it will just use them as measured dimensions.
|
java.lang.String |
toString() |
void |
unbind()
To be called this when the LithoView is about to become inactive.
|
void |
unmountAllItems()
Deprecated.
|
void |
unregisterUIDebugger() |
addView, addView, addView, addViewForTest, addViewInLayout, attachViewToParent, dispatchDraw, dispatchHoverEvent, drawableStateChanged, finaliseDisappearingItem, getChildDrawingOrder, getClipChildren, getComponentTouchListener, getContentDescription, getContentDescriptions, getContentNames, getDrawables, getImageContent, getLinkedDrawablesForAnimation, getMountItemAt, getMountItemCount, getTag, getTextContent, hasOverlappingRendering, jumpDrawablesToCurrentState, mount, mount, moveItem, onInterceptTouchEvent, onLayout, onTouchEvent, performAccessibilityAction, refreshAccessibilityDelegatesIfNeeded, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestLayout, setAccessibilityDelegate, setAlpha, setClipChildren, setContentDescription, setInLayout, setTag, setViewTags, setVisibility, shouldDelayChildPressedState, startDisappearingMountItem, unmount, unmount, unsetInLayout, verifyDrawable
getDescriptionOfMountedItems, safelyUnmountAll
public static final java.lang.String ZERO_HEIGHT_LOG
public static final java.lang.String SET_ALREADY_ATTACHED_COMPONENT_TREE
public final int mViewAttributeFlags
public LithoView(Context context)
public LithoView(Context context, AttributeSet attrs)
public LithoView(ComponentContext context, AttributeSet attrs)
public static LithoView create(Context context, Component component, LithoLifecycleProvider lifecycleProvider)
public static LithoView create(Context context, ComponentTree componentTree)
LithoView
instance and initialize it with a custom ComponentTree
.protected void forceRelayout()
public void startTemporaryDetach()
protected void onAttachedToWindow()
protected void onDetachedFromWindow()
public void onAttachedToWindowForTest()
onDetachedFromWindowForTest()
below, makes the LithoView think it's attached/
detached in a unit test environment. This also handles setting the same state for all LithoView
children.
Implementation Note: Ideally, we'd just attach the LithoView to a View hierarchy and let AOSP handle all this for us. The reason we haven't is because attaching to an Activity while also trying to make sure the full LithoView is always considered visible (for the purposes of visibility events and incremental mount) proved difficult - if interested, see summary on the blame diff for this comment for more info.
public void onDetachedFromWindowForTest()
public void onStartTemporaryDetach()
public void onFinishTemporaryDetach()
public void suppressMeasureComponentTree(boolean suppress)
public void setAnimatedWidth(int width)
setAnimatedWidth
in interface AnimatedRootHost
public void setAnimatedHeight(int height)
setAnimatedHeight
in interface AnimatedRootHost
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
protected void performLayout(boolean changed, int left, int top, int right, int bottom)
protected boolean shouldAlwaysLayoutChildren()
Since the framework doesn't expect its children to resize after being mounted, this should be used only for extreme cases where the underline views are complex and need this behavior.
public ComponentContext getComponentContext()
ComponentContext
associated with this LithoView. It's a wrapper on the Context
originally used to create this LithoView itself.protected boolean shouldRequestLayout()
shouldRequestLayout
in class ComponentHost
public ComponentTree getComponentTree()
public void setOnDirtyMountListener(LithoView.OnDirtyMountListener onDirtyMountListener)
public void setOnPostDrawListener(LithoView.OnPostDrawListener onPostDrawListener)
public void setComponentTree(ComponentTree componentTree)
public void setComponentTree(ComponentTree componentTree, boolean unmountAllWhenComponentTreeSetToNull)
public boolean skipNotifyVisibleBoundsChangedCalls()
public void registerUIDebugger(MountExtension extension)
public void unregisterUIDebugger()
public void setComponent(Component component)
@Deprecated public void setComponentWithoutReconciliation(Component component)
setComponent(Component)
if reconciliation can be enabled.setComponent(Component)
.
Use setComponent(Component)
if the component hierarchy does not rely on side
effects. For more details about reconciliation see the documentation @
https://fblitho.com/docs/codegen/state-for-specs/#updating-state-values
To disable reconciliation create a new ComponentTree
, and disable reconciliation
explicitly using ComponentTree.Builder.isReconciliationEnabled(boolean)
. Set this
ComponentTree
on the LithoView
using setComponentTree(ComponentTree)
.
public void setComponentAsync(Component component)
LithoView
doesn't have a ComponentTree initialized, the root will be computed
synchronously.@Deprecated public void setComponentAsyncWithoutReconciliation(Component component)
setComponentAsync(Component)
if reconciliation can be enabled.setComponentAsync(Component)
.
Use setComponentAsync(Component)
if the component hierarchy does not rely on side
effects. For more details about reconciliation see the documentation @
https://fblitho.com/docs/codegen/state-for-specs/#updating-state-values
To disable reconciliation create a new ComponentTree
, and disable reconciliation
explicitly using ComponentTree.Builder.isReconciliationEnabled(boolean)
. Set this
ComponentTree
on the LithoView
using setComponentTree(ComponentTree)
.
public void rebind()
public void unbind()
public void setSkipMountingIfNotVisible(boolean skipMountingIfNotVisible)
setVisibilityHint(boolean, boolean)
will delegate to setVisibilityHint(boolean)
and skip mounting if the visibility hint was set to false. You
should not need this unless you don't have control over calling setVisibilityHint on the
LithoView you own.public boolean componentTreeHasLifecycleProvider()
public boolean subscribeComponentTreeToLifecycleProvider(LithoLifecycleProvider lifecycleProvider)
@Deprecated public void setVisibilityHint(boolean isVisible)
Call this to tell the LithoView whether it is visible or not. In general, you shouldn't require this as the system will do this for you. However, when a new activity/fragment is added on top of the one hosting this view, the LithoView remains in the backstack but receives no callback to indicate that it is no longer visible.
While the LithoView has the visibility hint set to false, it will be treated by the framework as not in the viewport, so no new mounting events will be processed until the visibility hint is set back to true.
isVisible
- if true, this will find the current visible rect and process visibility
outputs using it. If false, any invisible and unfocused events will be called.@Deprecated public void setVisibilityHint(boolean isVisible, boolean skipMountingIfNotVisible)
setVisibilityHint(boolean)
should be used instead, which by
default does not process new mount events while the visibility hint is set to false
(skipMountingIfNotVisible should be set to true). This method should only be used to maintain
the contract with the usages of setVisibilityHint before `skipMountingIfNotVisible` was made to
default to true. All usages should be audited and migrated to setVisibilityHint(boolean)
.public void setHasTransientState(boolean hasTransientState)
public void offsetTopAndBottom(int offset)
public void offsetLeftAndRight(int offset)
public void setTranslationX(float translationX)
public void setTranslationY(float translationY)
public void draw(Canvas canvas)
public void notifyLithoViewGlobalPositionChanged()
Calls to this method are not needed if the LithoView's global position has changed due to layout, scroll or translation.
public void notifyVisibleBoundsChanged(Rect visibleRect, boolean processVisibilityOutputs)
AnimatedRootHost
notifyVisibleBoundsChanged
in interface AnimatedRootHost
public void notifyVisibleBoundsChanged()
RenderCoreExtensionHost
notifyVisibleBoundsChanged
in interface RenderCoreExtensionHost
public boolean isIncrementalMountEnabled()
@Deprecated public void release()
@Deprecated public void dispatchVisibilityEvent(java.lang.Class<?> visibilityEventType)
Marked as @Deprecated to indicate this method is experimental and should not be widely used.
NOTE: Can only be used when Incremental Mount is disabled! Call this method when the LithoView is considered eligible for the visibility event (i.e. only dispatch VisibleEvent when the LithoView is visible in its container).
visibilityEventType
- The class type of the visibility event to dispatch. Supported:
VisibleEvent.class, InvisibleEvent.class, FocusedVisibleEvent.class,
UnfocusedVisibleEvent.class, FullImpressionVisibleEvent.class.public java.util.List<LithoView> getChildLithoViewsFromCurrentlyMountedItems()
@Deprecated public void unmountAllItems()
public Rect getPreviousMountBounds()
public MountDelegateTarget getMountDelegateTarget()
public DynamicPropsManager getDynamicPropsManager()
public void setMountStartupLoggingInfo(LithoStartupLogger startupLogger, java.lang.String startupLoggerAttribution, boolean[] firstMountCalled, boolean[] lastMountCalled, boolean isLastAdapterItem, boolean isOrientationVertical)
public void resetMountStartupLoggingInfo()
public void setInvalidStateLogParamsList(java.util.List<ComponentLogParams> logParamsList)
public void rerenderForAccessibility(boolean enabled)
public java.lang.String toString()
public void setRenderState(RenderState renderState)
setRenderState
in interface RootHost
protected java.util.Map<java.lang.String,java.lang.Object> getLayoutErrorMetadata(int width, int height)
getLayoutErrorMetadata
in class ComponentHost