Scoop API

scoop:scoop.ui.component:0.1.0

src/drawer/values.scoop

Selected production source · src/drawer/values.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
5import scoop.ui.style.*
7public enum DrawerSnapPoint {
8 Fraction(Double), Length(Double)
9}
11public class DrawerSwipeHandleOptions public constructor(
12 public val visible: Boolean = false,
13 public val only: Boolean = false,
14 public val focus: FocusOptions = FocusOptions(),
15 public val style: StyleOverride = styleOverride(),
16 public val content: View? = None
17) {
18 init {
19 requireComponent(!only || visible, "handle-only drawers require a visible swipe handle")
20 }
23public struct DrawerSnapshot(
24 val snapIndex: Long = -1L,
25 val extent: Double = 0.0,
26 val visibleExtent: Double = 0.0,
27 val dragging: Boolean = false,
28 val nestedDepth: Long = 0L
31public class DrawerProps public constructor(
32 public val open: Binding<Boolean>,
33 public val content: View,
34 public val options: ModalOptions = ModalOptions(viewportPadding = 0.0),
35 public val side: SheetSide = SheetSide.Bottom,
36 public val width: Double? = None,
37 public val height: Double? = None,
38 public val footer: View? = None,
39 public val showCloseButton: Boolean = false,
40 public val close: PopupTriggerSpec? = None,
41 public val dismiss: OverlayDismiss = OverlayDismiss(true, OutsidePress.CloseAndConsume),
42 public val mode: OverlayMode = OverlayMode.Modal,
43 public val snapPoints: Array<DrawerSnapPoint> = [],
44 public val snap: Binding<Long>? = None,
45 public val initialSnap: Long = 0L,
46 public val swipeToClose: Boolean = true,
47 public val dragThreshold: Double = 4.0,
48 public val projectionSeconds: Double = 0.15,
49 public val swipeHandle: DrawerSwipeHandleOptions = DrawerSwipeHandleOptions(),
50 public val controller: DrawerHandle? = None,
51 public val parent: DrawerHandle? = None,
52 public val viewportGap: Double = 96.0,
53 public val viewportStyle: StyleOverride = styleOverride(),
54 public val onSnapChange: (Long) -> Unit = {},
55 public val onDragCancel: (DragCancelReason) -> Unit = {},
56 public val nativeSwipe: Boolean = true
57) {
58 init {
59 when (width) {
60 case Some(val value) -> nonnegative(value, "invalid drawer width");
61 case None -> {}
62 }
63 when (height) {
64 case Some(val value) -> nonnegative(value, "invalid drawer height");
65 case None -> {}
66 }
67 nonnegative(viewportGap, "invalid drawer viewport gap")
68 nonnegative(dragThreshold, "invalid drawer drag threshold")
69 nonnegative(projectionSeconds, "invalid drawer projection duration")
70 requireComponent(
71 snapPoints.size == 0L || side == SheetSide.Top || side == SheetSide.Bottom,
72 "drawer snap points require a vertical side"
73 )
74 requireComponent(
75 mode != OverlayMode.Modal || dismiss.outsidePress != OutsidePress.CloseAndContinue,
76 "modal outside presses cannot continue to the background"
77 )
78 for (point in snapPoints)
79 when (point) {
80 case Fraction(val value) -> requireComponent(
81 value.isFinite() && value > 0.0 && value <= 1.0,
82 "drawer snap fractions must be in (0, 1]"
83 )
84 case Length(val value) -> requireComponent(
85 value.isFinite() && value > 0.0,
86 "drawer snap lengths must be positive and finite"
87 )
88 }
89 }
90 internal fun input(owner: DrawerOwner): ModalInput =
91 ModalInput(
92 ModalKind.Drawer(this, owner),
93 open,
94 content,
95 options,
96 width,
97 height,
98 footer,
99 showCloseButton,
100 close,
101 dismiss
102 )
105internal class DrawerOwner(initialSnap: Long) {
106 val localSnap = state(initialSnap)
107 val scroll = ScrollState()
108 var control: DrawerControl? = None
109 var bodyArea: scoop.surface.InputArea? = None
110 var handleArea: scoop.surface.InputArea? = None
113internal class DrawerInput(
114 val props: DrawerProps,
115 val theme: Theme,
116 val owner: DrawerOwner,
117 val overlay: OverlayHandle
118) {
119 val density: Double get() = theme.tokens.typography.body.fontSize / 14.0
120 val scroll: ScrollState get() = props.options.scrollState ?: owner.scroll