@@ -6,22 +6,16 @@ import androidx.compose.foundation.Indication
66import androidx.compose.foundation.IndicationNodeFactory
77import androidx.compose.foundation.interaction.FocusInteraction
88import androidx.compose.foundation.interaction.HoverInteraction
9- import androidx.compose.foundation.interaction.Interaction
109import androidx.compose.foundation.interaction.InteractionSource
11- import androidx.compose.foundation.interaction.MutableInteractionSource
1210import androidx.compose.foundation.interaction.PressInteraction
13- import androidx.compose.runtime.Composable
14- import androidx.compose.runtime.LaunchedEffect
15- import androidx.compose.runtime.State
16- import androidx.compose.runtime.mutableStateOf
17- import androidx.compose.runtime.remember
1811import androidx.compose.ui.Modifier
1912import androidx.compose.ui.graphics.Color
2013import androidx.compose.ui.graphics.drawscope.ContentDrawScope
2114import androidx.compose.ui.node.DelegatableNode
2215import androidx.compose.ui.node.DrawModifierNode
2316import kotlinx.coroutines.Job
2417import kotlinx.coroutines.launch
18+ import top.yukonga.miuix.kmp.interfaces.HoldDownInteraction
2519
2620/* *
2721 * Miuix default [Indication] that draws a rectangular overlay when pressed.
@@ -112,49 +106,3 @@ class MiuixIndication(
112106 }
113107 }
114108}
115-
116- /* *
117- * An interaction related to hold down events.
118- *
119- * @see Hold
120- * @see Release
121- */
122- interface HoldDownInteraction : Interaction {
123- /* *
124- * An interaction representing a hold down event on a component.
125- *
126- * @see Release
127- */
128- class Hold : HoldDownInteraction
129-
130- /* *
131- * An interaction representing a [Hold] event being released on a component.
132- *
133- * @property hold the source [Hold] interaction that is being released
134- *
135- * @see Hold
136- */
137- class Release (val hold : Hold ) : HoldDownInteraction
138- }
139-
140- /* *
141- * Subscribes to this [MutableInteractionSource] and returns a [State] representing whether this
142- * component is selected or not.
143- *
144- * @return [State] representing whether this component is being focused or not
145- */
146- @Composable
147- fun InteractionSource.collectIsHeldDownAsState (): State <Boolean > {
148- val isHeldDown = remember { mutableStateOf(false ) }
149- LaunchedEffect (this ) {
150- val holdInteraction = mutableListOf<HoldDownInteraction .Hold >()
151- interactions.collect { interaction ->
152- when (interaction) {
153- is HoldDownInteraction .Hold -> holdInteraction.add(interaction)
154- is HoldDownInteraction .Release -> holdInteraction.remove(interaction.hold)
155- }
156- isHeldDown.value = holdInteraction.isNotEmpty()
157- }
158- }
159- return isHeldDown
160- }
0 commit comments