@@ -39,16 +39,85 @@ public interface RevealScope {
39
39
shape : RevealShape = RevealShape .RoundRect (4.dp),
40
40
padding : PaddingValues = PaddingValues (8.dp),
41
41
): Modifier
42
+
43
+ /* *
44
+ * Registers the element as a revealable item.
45
+ *
46
+ * Each key in [keys] must be unique in the current scope and should be used for
47
+ * [RevealState.reveal]. Internally [Modifier.onGloballyPositioned] is used. Hence elements are
48
+ * only registered after they have been laid out.
49
+ *
50
+ * If the element that this modifier is applied to leaves the composition while the reveal
51
+ * effect is shown for the element, the effect is finished.
52
+ *
53
+ * @param keys Unique keys to identify the revealable content. Also see documentation of [Key].
54
+ * @param shape Shape of the reveal effect around the element. Defaults to a rounded rect
55
+ * with a corner size of 4 dp.
56
+ * @param padding Additional padding around the reveal area. Positive values increase area while
57
+ * negative values decrease it. Defaults to 8 dp on all sides.
58
+ *
59
+ * @see Key
60
+ */
61
+ public fun Modifier.revealable (
62
+ vararg keys : Key ,
63
+ shape : RevealShape = RevealShape .RoundRect (4.dp),
64
+ padding : PaddingValues = PaddingValues (8.dp),
65
+ ): Modifier
66
+
67
+ /* *
68
+ * Registers the element as a revealable item.
69
+ *
70
+ * Each key specified in [keys] must be unique in the current scope and should be used for
71
+ * [RevealState.reveal]. Internally [Modifier.onGloballyPositioned] is used. Hence elements are
72
+ * only registered after they have been laid out.
73
+ *
74
+ * If the element that this modifier is applied to leaves the composition while the reveal
75
+ * effect is shown for the element, the effect is finished.
76
+ *
77
+ * @param keys Unique keys to identify the revealable content. Also see documentation of [Key].
78
+ * @param shape Shape of the reveal effect around the element. Defaults to a rounded rect
79
+ * with a corner size of 4 dp.
80
+ * @param padding Additional padding around the reveal area. Positive values increase area while
81
+ * negative values decrease it. Defaults to 8 dp on all sides.
82
+ *
83
+ * @see Key
84
+ */
85
+ public fun Modifier.revealable (
86
+ keys : Iterable <Key >,
87
+ shape : RevealShape = RevealShape .RoundRect (4.dp),
88
+ padding : PaddingValues = PaddingValues (8.dp),
89
+ ): Modifier
42
90
}
43
91
44
92
internal class RevealScopeInstance (
45
93
private val revealState : RevealState ,
46
94
) : RevealScope {
47
95
48
96
override fun Modifier.revealable (key : Key , shape : RevealShape , padding : PaddingValues ): Modifier =
49
- this .then(
50
- Modifier
51
- .onGloballyPositioned { layoutCoordinates ->
97
+ revealable(
98
+ keys = listOf (key),
99
+ shape = shape,
100
+ padding = padding,
101
+ )
102
+
103
+ override fun Modifier.revealable (
104
+ vararg keys : Key ,
105
+ shape : RevealShape ,
106
+ padding : PaddingValues ,
107
+ ): Modifier = revealable(
108
+ keys = keys.toList(),
109
+ shape = shape,
110
+ padding = padding,
111
+ )
112
+
113
+ override fun Modifier.revealable (
114
+ keys : Iterable <Key >,
115
+ shape : RevealShape ,
116
+ padding : PaddingValues ,
117
+ ): Modifier = this .then(
118
+ Modifier
119
+ .onGloballyPositioned { layoutCoordinates ->
120
+ for (key in keys) {
52
121
revealState.putRevealable(
53
122
Revealable (
54
123
key = key,
@@ -61,13 +130,16 @@ internal class RevealScopeInstance(
61
130
),
62
131
)
63
132
}
64
- .composed {
65
- DisposableEffect (Unit ) {
66
- onDispose {
133
+ }
134
+ .composed {
135
+ DisposableEffect (Unit ) {
136
+ onDispose {
137
+ for (key in keys) {
67
138
revealState.removeRevealable(key)
68
139
}
69
140
}
70
- this
71
- },
72
- )
141
+ }
142
+ this
143
+ },
144
+ )
73
145
}
0 commit comments