WorkflowViewStub
A placeholder View that can replace itself with ones driven by workflow renderings, similar to android.view.ViewStub.
Usage
In the XML layout for a container view, place a WorkflowViewStub where you want child renderings to be displayed. E.g.:
…
Then in your LayoutRunner,
pull the view out with findViewById like any other view
and update it in your LayoutRunner.showRendering method:
class YourLayoutRunner(view: View) {
private val childStub = view.findViewById<WorkflowViewStub>(R.id.child_stub)
// Totally optional, since this view is also accessible as [childStub.actual].
// Note that R.id.child was set in XML via the square:inflatedId parameter.
private val child: View by lazy {
view.findViewById<View>(R.id.child)
}
override fun showRendering(
rendering: YourRendering,
viewEnvironment: ViewEnvironment
) {
childStub.update(rendering.childRendering, viewEnvironment)
}
}
NB: If you're using a stub in a RelativeLayout
or ConstraintLayout
, relationships should be tied to the stub's app:inflatedId
, not its android:id
.
Use updatesVisibility and setBackground for more control of how update effects the visibility and backgrounds of created views.
Use replaceOldViewInParent to customize replacing actual with a new view, e.g. for animated transitions.
Constructors
Properties
On-demand access to the view created by the last call to update, or this WorkflowViewStub instance if none has yet been made.
Returns the most recent ViewEnvironment applied to this view, or null if the receiver was not initialized via ScreenViewHolder.startShowing.
The id to be assigned to new views created by update. If the inflated id is View.NO_ID (its default value), new views keep their original ids.
If true, the layoutParams of this stub will be applied to new views as they are added to the stub's original parent. Specifically, the third parameter passed to replaceOldViewInParent will be non-null.
Function called from update to replace this stub, or the current actual, with a new view. Can be updated to provide custom transition effects. The default implementation simply calls ViewGroup.addView, including the layoutParams
parameter if it is non-null.
Returns the most recent Screen rendering shown in this view, or throws a NullPointerException if the receiver was not created via ScreenViewFactory.startShowing.
Returns the most recent Screen rendering shown in this view, or null
if the receiver was not initialized via ScreenViewHolder.startShowing.
Functions
Returns the bounds of this View in the coordinate space of the device screen, based on View.getLocationOnScreen and its reported width and height.
Looks for a View's OnBackPressedDispatcherOwner via the usual findViewTreeOnBackPressedDispatcherOwner method, and if that fails checks its Context.
Sets the background of this stub as usual, and also that of actual if the given background is not null. Any new views created by update will be assigned this background, again if it is not null.
Wrapper for the two arg variant of setBackHandler, a convenience for the common pattern of using a nullable function as the back handler to indicate that back handling should be disabled.
A function to be called if the device back button is pressed while this view is active, as determined by its ViewTreeLifecycleOwner, via an OnBackPressedCallback. On succeeding calls, the previously created OnBackPressedCallback will be updated, and will maintain its position in the OnBackPressedDispatcher priority queue.