Skip to content

Commit 4976aeb

Browse files
committed
More kdoc
1 parent 1d1d710 commit 4976aeb

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
lines changed

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/AndroidScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ package com.squareup.workflow1.ui
2727
* reason, you can use [ViewRegistry] to bind your renderings to [ScreenViewFactory]
2828
* implementations at runtime. Also note that a [ViewRegistry] entry will override
2929
* the [viewFactory] returned by an [AndroidScreen].
30+
*
31+
* @see com.squareup.workflow1.ui.container.AndroidOverlay
3032
*/
3133
@WorkflowUiExperimentalApi
3234
public interface AndroidScreen<S : AndroidScreen<S>> : Screen {

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/AndroidOverlay.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@ package com.squareup.workflow1.ui.container
22

33
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
44

5+
/**
6+
* Interface implemented by a rendering class to allow it to drive an Android UI
7+
* via an appropriate [OverlayDialogFactory] implementation.
8+
*
9+
* This is the simplest way to introduce a [Dialog][android.app.Dialog] workflow driven UI,
10+
* but using it requires your workflows code to reside in Android modules, instead
11+
* of pure Kotlin. If this is a problem, or you need more flexibility for any other
12+
* reason, you can use [ViewRegistry][com.squareup.workflow1.ui.ViewRegistry] to bind
13+
* your renderings to [OverlayDialogFactory] implementations at runtime.
14+
* Also note that a `ViewRegistry` entry will override the [dialogFactory] returned by
15+
* an [AndroidOverlay].
16+
*
17+
* @see com.squareup.workflow1.ui.AndroidScreen
18+
*/
519
@WorkflowUiExperimentalApi
6-
public interface AndroidOverlay<O: AndroidOverlay<O>> : Overlay {
20+
public interface AndroidOverlay<O : AndroidOverlay<O>> : Overlay {
721
public val dialogFactory: OverlayDialogFactory<O>
822
}

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/DialogStack.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,42 @@ import com.squareup.workflow1.ui.androidx.WorkflowLifecycleOwner
1212
import com.squareup.workflow1.ui.container.DialogRunner.KeyAndBundle
1313

1414
/**
15-
* Does the work of maintaining a set of [Dialog][android.app.Dialog]s
16-
* to reflect lists of [Overlay].
15+
* Does the bulk of the work of maintaining a set of [Dialog][android.app.Dialog]s
16+
* to reflect lists of [Overlay]. Can be used to create custom [Overlay]-based
17+
* layouts if [BodyAndModalsScreen] or the default [View] bound to it are too restrictive.
18+
* Provides a [LifecycleOwner] per managed dialog, and view persistence support.
1719
*/
1820
@WorkflowUiExperimentalApi
1921
public class DialogStack(
2022
private val context: Context,
2123
private val getParentLifecycleOwner: () -> LifecycleOwner?,
2224
private val createRectProvider: (Overlay) -> RectProvider
2325
) {
26+
/**
27+
* Builds a [DialogStack] whose overlays' [bounds][createRectProvider] track those
28+
* of [view], and which looks through [view] to find their
29+
* [LifecycleOwner][getParentLifecycleOwner].
30+
*/
2431
public constructor(
2532
view: View,
2633
createRectProvider: (Overlay) -> RectProvider = { ViewRectProvider(view) }
2734
) : this(view.context, { WorkflowLifecycleOwner.get(view) }, createRectProvider)
2835

2936
private var runners: List<DialogRunner<*>> = emptyList()
3037

38+
/** True when any dialogs are visible, or becoming visible. */
3139
public val hasDialogs: Boolean = runners.isNotEmpty()
3240

41+
/**
42+
* Updates the managed set of [Dialog][android.app.Dialog] instances to reflect
43+
* [overlays]. Opens new dialogs, updates existing ones, and dismisses those
44+
* that match no member of that list.
45+
*
46+
* Each dialog has its own [WorkflowLifecycleOwner], which starts when the dialog
47+
* is shown, and is destroyed when it is dismissed. Views nested in a managed dialog
48+
* can use [ViewTreeLifecycleOwner][androidx.lifecycle.ViewTreeLifecycleOwner] as
49+
* usual.
50+
*/
3351
public fun update(
3452
overlays: List<Overlay>,
3553
viewEnvironment: ViewEnvironment,
@@ -62,10 +80,12 @@ public class DialogStack(
6280
// TODO Smarter diffing, and Z order. Maybe just hide and show everything on every update?
6381
}
6482

83+
/** To be called from a container view's [View.onSaveInstanceState]. */
6584
public fun onSaveInstanceState(): SavedState {
6685
return SavedState(runners.mapNotNull { it.save() })
6786
}
6887

88+
/** To be called from a container view's [View.onRestoreInstanceState]. */
6989
public fun onRestoreInstanceState(state: SavedState) {
7090
if (state.dialogBundles.size == runners.size) {
7191
state.dialogBundles.zip(runners) { viewState, runner -> runner.restore(viewState) }

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/OverlayDialogFactory.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ import com.squareup.workflow1.ui.ViewEnvironment
66
import com.squareup.workflow1.ui.ViewRegistry
77
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
88

9+
/**
10+
* Factory for [Dialog] instances that can show renderings of type [RenderingT] : [Overlay].
11+
*
12+
* It's simplest to have your rendering classes implement [AndroidOverlay] to associate
13+
* them with appropriate an appropriate [OverlayDialogFactory]. For more flexibility, and to
14+
* avoid coupling your workflow directly to the Android runtime, see [ViewRegistry].
15+
*/
916
@WorkflowUiExperimentalApi
10-
public interface OverlayDialogFactory<T : Overlay> : ViewRegistry.Entry<T> {
17+
public interface OverlayDialogFactory<RenderingT : Overlay> : ViewRegistry.Entry<RenderingT> {
1118
/**
1219
* Build a [Dialog], typically using [bounds] to set and maintain its bounds.
1320
* Do not show it.
1421
*/
1522
public fun buildDialog(
16-
initialRendering: T,
23+
initialRendering: RenderingT,
1724
initialEnvironment: ViewEnvironment,
1825
bounds: RectProvider,
1926
context: Context
@@ -26,7 +33,7 @@ public interface OverlayDialogFactory<T : Overlay> : ViewRegistry.Entry<T> {
2633
*/
2734
public fun updateDialog(
2835
dialog: Dialog,
29-
rendering: T,
36+
rendering: RenderingT,
3037
environment: ViewEnvironment
3138
)
3239
}

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/RectProvider.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,26 @@ package com.squareup.workflow1.ui.container
33
import android.graphics.Rect
44
import android.view.View
55

6+
/**
7+
* Defines the desired bounds for a [Dialog][android.app.Dialog] built by
8+
* [OverlayDialogFactory.buildDialog]. Custom containers can define their
9+
* bounds policy via [DialogStack.createRectProvider].
10+
*
11+
* Use [ViewRectProvider] to monitor the bounds of a [View].
12+
*/
613
public interface RectProvider {
14+
/**
15+
* Called once the bounds are known, and each time they change.
16+
* May be called immediately.
17+
*/
718
public var onChange: ((Rect) -> Unit)?
819
}
920

21+
/**
22+
* A [RectProvider] that reports the bounds of the given [view], starting when it is
23+
* first attached, and ceasing when it is first detached. [RectProvider.onChange] is
24+
* called immediately if [view] is already attached.
25+
*/
1026
public class ViewRectProvider(
1127
public val view: View
1228
) : RectProvider {

0 commit comments

Comments
 (0)