diff --git a/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Dropdown.android.kt b/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Dropdown.android.kt index 375a21e..fdf9252 100644 --- a/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Dropdown.android.kt +++ b/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Dropdown.android.kt @@ -26,8 +26,6 @@ package com.highcapable.flexiui.component import android.graphics.Rect import android.view.View import android.view.ViewTreeObserver -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.BoxWithConstraintsScope import androidx.compose.runtime.Composable @@ -40,41 +38,21 @@ import androidx.compose.ui.layout.boundsInWindow import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.node.Ref import androidx.compose.ui.platform.LocalView -import androidx.compose.ui.semantics.Role -import com.highcapable.flexiui.interaction.rippleClickable import kotlin.math.max @Composable internal actual fun DropdownListBox( - expanded: Boolean, - onExpandedChange: (Boolean) -> Unit, modifier: Modifier, - colors: DropdownListColors, - style: DropdownListStyle, - border: BorderStroke, - enabled: Boolean, - interactionSource: MutableInteractionSource, menuHeightPx: (Int) -> Unit, content: @Composable @UiComposable BoxWithConstraintsScope.() -> Unit ) { val view = LocalView.current val coordinates = remember { Ref() } BoxWithConstraints( - modifier = modifier.dropdownList( - colors = colors, - style = style, - border = border, - enabled = enabled, - interactionSource = interactionSource, - modifier = modifier.rippleClickable( - enabled = enabled, - role = Role.DropdownList, - interactionSource = interactionSource - ) { onExpandedChange(!expanded) }.onGloballyPositioned { - coordinates.value = it - updateHeight(view.rootView, coordinates.value) { newHeight -> menuHeightPx(newHeight) } - } - ), + modifier = modifier.onGloballyPositioned { + coordinates.value = it + updateHeight(view.rootView, coordinates.value) { newHeight -> menuHeightPx(newHeight) } + }, content = content ) DisposableEffect(view) { diff --git a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Dropdown.kt b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Dropdown.kt index a925714..21baeb3 100644 --- a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Dropdown.kt +++ b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Dropdown.kt @@ -180,14 +180,18 @@ fun DropdownList( else -> style.borderInactive }.copy(animatedBorderWidth, SolidColor(animatedBorderColor)) DropdownListBox( - expanded = expanded, - onExpandedChange = onExpandedChange, - modifier = modifier, - colors = colors, - style = style, - border = border, - enabled = enabled, - interactionSource = interactionSource, + modifier = modifier.dropdownList( + colors = colors, + style = style, + border = border, + enabled = enabled, + interactionSource = interactionSource, + modifier = modifier.rippleClickable( + enabled = enabled, + role = Role.DropdownList, + interactionSource = interactionSource + ) { onExpandedChange(!expanded) } + ), menuHeightPx = { menuHeightPx = it } ) { val menuWidth = maxWidth + startPadding + endPadding @@ -352,19 +356,12 @@ private fun DropdownMenuContent( @Composable internal expect fun DropdownListBox( - expanded: Boolean, - onExpandedChange: (Boolean) -> Unit, modifier: Modifier, - colors: DropdownListColors, - style: DropdownListStyle, - border: BorderStroke, - enabled: Boolean, - interactionSource: MutableInteractionSource, menuHeightPx: (Int) -> Unit, content: @Composable @UiComposable BoxWithConstraintsScope.() -> Unit ) -internal fun Modifier.dropdownList( +private fun Modifier.dropdownList( colors: DropdownListColors, style: DropdownListStyle, border: BorderStroke, diff --git a/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Dropdown.desktop.kt b/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Dropdown.desktop.kt index 26492ed..5cdd9d4 100644 --- a/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Dropdown.desktop.kt +++ b/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Dropdown.desktop.kt @@ -23,8 +23,6 @@ package com.highcapable.flexiui.component -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.BoxWithConstraintsScope import androidx.compose.runtime.Composable @@ -33,44 +31,24 @@ import androidx.compose.ui.UiComposable import androidx.compose.ui.layout.boundsInWindow import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalWindowInfo -import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.toIntRect -import com.highcapable.flexiui.interaction.rippleClickable import kotlin.math.max @Composable internal actual fun DropdownListBox( - expanded: Boolean, - onExpandedChange: (Boolean) -> Unit, modifier: Modifier, - colors: DropdownListColors, - style: DropdownListStyle, - border: BorderStroke, - enabled: Boolean, - interactionSource: MutableInteractionSource, menuHeightPx: (Int) -> Unit, content: @Composable @UiComposable BoxWithConstraintsScope.() -> Unit ) { val windowInfo = LocalWindowInfo.current BoxWithConstraints( - modifier = modifier.dropdownList( - colors = colors, - style = style, - border = border, - enabled = enabled, - interactionSource = interactionSource, - modifier = modifier.rippleClickable( - enabled = enabled, - role = Role.DropdownList, - interactionSource = interactionSource - ) { onExpandedChange(!expanded) }.onGloballyPositioned { - val boundsInWindow = it.boundsInWindow() - val visibleWindowBounds = windowInfo.containerSize.toIntRect() - val heightAbove = boundsInWindow.top - visibleWindowBounds.top - val heightBelow = visibleWindowBounds.height - boundsInWindow.bottom - menuHeightPx(max(heightAbove, heightBelow).toInt()) - } - ), + modifier = modifier.onGloballyPositioned { + val boundsInWindow = it.boundsInWindow() + val visibleWindowBounds = windowInfo.containerSize.toIntRect() + val heightAbove = boundsInWindow.top - visibleWindowBounds.top + val heightBelow = visibleWindowBounds.height - boundsInWindow.bottom + menuHeightPx(max(heightAbove, heightBelow).toInt()) + }, content = content ) } \ No newline at end of file diff --git a/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Dropdown.ios.kt b/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Dropdown.ios.kt index 26492ed..5cdd9d4 100644 --- a/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Dropdown.ios.kt +++ b/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Dropdown.ios.kt @@ -23,8 +23,6 @@ package com.highcapable.flexiui.component -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.BoxWithConstraintsScope import androidx.compose.runtime.Composable @@ -33,44 +31,24 @@ import androidx.compose.ui.UiComposable import androidx.compose.ui.layout.boundsInWindow import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalWindowInfo -import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.toIntRect -import com.highcapable.flexiui.interaction.rippleClickable import kotlin.math.max @Composable internal actual fun DropdownListBox( - expanded: Boolean, - onExpandedChange: (Boolean) -> Unit, modifier: Modifier, - colors: DropdownListColors, - style: DropdownListStyle, - border: BorderStroke, - enabled: Boolean, - interactionSource: MutableInteractionSource, menuHeightPx: (Int) -> Unit, content: @Composable @UiComposable BoxWithConstraintsScope.() -> Unit ) { val windowInfo = LocalWindowInfo.current BoxWithConstraints( - modifier = modifier.dropdownList( - colors = colors, - style = style, - border = border, - enabled = enabled, - interactionSource = interactionSource, - modifier = modifier.rippleClickable( - enabled = enabled, - role = Role.DropdownList, - interactionSource = interactionSource - ) { onExpandedChange(!expanded) }.onGloballyPositioned { - val boundsInWindow = it.boundsInWindow() - val visibleWindowBounds = windowInfo.containerSize.toIntRect() - val heightAbove = boundsInWindow.top - visibleWindowBounds.top - val heightBelow = visibleWindowBounds.height - boundsInWindow.bottom - menuHeightPx(max(heightAbove, heightBelow).toInt()) - } - ), + modifier = modifier.onGloballyPositioned { + val boundsInWindow = it.boundsInWindow() + val visibleWindowBounds = windowInfo.containerSize.toIntRect() + val heightAbove = boundsInWindow.top - visibleWindowBounds.top + val heightBelow = visibleWindowBounds.height - boundsInWindow.bottom + menuHeightPx(max(heightAbove, heightBelow).toInt()) + }, content = content ) } \ No newline at end of file