diff --git a/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Popup.android.kt b/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Popup.android.kt new file mode 100644 index 0000000..6b4f2ea --- /dev/null +++ b/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/component/Popup.android.kt @@ -0,0 +1,59 @@ +/* + * Flexi UI - A flexible and useful UI component library. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/BetterAndroid/FlexiUI + * + * Apache License Version 2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is created by fankes on 2023/11/16. + */ +@file:Suppress("unused") + +package com.highcapable.flexiui.component + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.input.key.KeyEvent +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.window.PopupPositionProvider +import androidx.compose.ui.window.PopupProperties +import androidx.compose.ui.window.Popup as ComposePopup + +@Composable +actual fun Popup( + alignment: Alignment, + offset: IntOffset, + popupPositionProvider: PopupPositionProvider?, + onDismissRequest: (() -> Unit)?, + properties: PopupProperties, + onPreviewKeyEvent: ((KeyEvent) -> Boolean)?, + onKeyEvent: ((KeyEvent) -> Boolean)?, + content: @Composable () -> Unit +) { + popupPositionProvider?.also { + ComposePopup( + popupPositionProvider = it, + onDismissRequest = onDismissRequest, + properties = properties, + content = content + ) + } ?: ComposePopup( + alignment = alignment, + offset = offset, + onDismissRequest = onDismissRequest, + properties = properties, + content = content + ) +} \ No newline at end of file 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 deleted file mode 100644 index 2cfbfd9..0000000 --- a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Dropdown.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Flexi UI - A flexible and useful UI component library. - * Copyright (C) 2019-2023 HighCapable - * https://github.com/BetterAndroid/FlexiUI - * - * Apache License Version 2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is created by fankes on 2023/11/9. - */ -@file:Suppress("unused") - -package com.highcapable.flexiui.component - -// TODO: To be implemented \ No newline at end of file diff --git a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/interaction/Popup.kt b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Popup.kt similarity index 52% rename from flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/interaction/Popup.kt rename to flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Popup.kt index bb6716f..0d913b3 100644 --- a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/interaction/Popup.kt +++ b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/Popup.kt @@ -21,6 +21,23 @@ */ @file:Suppress("unused") -package com.highcapable.flexiui.interaction +package com.highcapable.flexiui.component -// TODO: To be implemented \ No newline at end of file +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.input.key.KeyEvent +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.window.PopupPositionProvider +import androidx.compose.ui.window.PopupProperties + +@Composable +expect fun Popup( + alignment: Alignment = Alignment.TopStart, + offset: IntOffset = IntOffset(0, 0), + popupPositionProvider: PopupPositionProvider? = null, + onDismissRequest: (() -> Unit)? = null, + properties: PopupProperties = PopupProperties(), + onPreviewKeyEvent: ((KeyEvent) -> Boolean)? = null, + onKeyEvent: ((KeyEvent) -> Boolean)? = null, + content: @Composable () -> Unit +) \ No newline at end of file diff --git a/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Popup.desktop.kt b/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Popup.desktop.kt new file mode 100644 index 0000000..35d88a9 --- /dev/null +++ b/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/component/Popup.desktop.kt @@ -0,0 +1,63 @@ +/* + * Flexi UI - A flexible and useful UI component library. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/BetterAndroid/FlexiUI + * + * Apache License Version 2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is created by fankes on 2023/11/16. + */ +@file:Suppress("unused") + +package com.highcapable.flexiui.component + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.input.key.KeyEvent +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.window.PopupPositionProvider +import androidx.compose.ui.window.PopupProperties +import androidx.compose.ui.window.Popup as ComposePopup + +@Composable +actual fun Popup( + alignment: Alignment, + offset: IntOffset, + popupPositionProvider: PopupPositionProvider?, + onDismissRequest: (() -> Unit)?, + properties: PopupProperties, + onPreviewKeyEvent: ((KeyEvent) -> Boolean)?, + onKeyEvent: ((KeyEvent) -> Boolean)?, + content: @Composable () -> Unit +) { + popupPositionProvider?.also { + ComposePopup( + popupPositionProvider = it, + onDismissRequest = onDismissRequest, + properties = properties, + onPreviewKeyEvent = onPreviewKeyEvent, + onKeyEvent = onKeyEvent, + content = content + ) + } ?: ComposePopup( + alignment = alignment, + offset = offset, + onDismissRequest = onDismissRequest, + properties = properties, + onPreviewKeyEvent = onPreviewKeyEvent, + onKeyEvent = onKeyEvent, + content = content + ) +} \ No newline at end of file diff --git a/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Popup.ios.kt b/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Popup.ios.kt new file mode 100644 index 0000000..35d88a9 --- /dev/null +++ b/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/component/Popup.ios.kt @@ -0,0 +1,63 @@ +/* + * Flexi UI - A flexible and useful UI component library. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/BetterAndroid/FlexiUI + * + * Apache License Version 2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is created by fankes on 2023/11/16. + */ +@file:Suppress("unused") + +package com.highcapable.flexiui.component + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.input.key.KeyEvent +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.window.PopupPositionProvider +import androidx.compose.ui.window.PopupProperties +import androidx.compose.ui.window.Popup as ComposePopup + +@Composable +actual fun Popup( + alignment: Alignment, + offset: IntOffset, + popupPositionProvider: PopupPositionProvider?, + onDismissRequest: (() -> Unit)?, + properties: PopupProperties, + onPreviewKeyEvent: ((KeyEvent) -> Boolean)?, + onKeyEvent: ((KeyEvent) -> Boolean)?, + content: @Composable () -> Unit +) { + popupPositionProvider?.also { + ComposePopup( + popupPositionProvider = it, + onDismissRequest = onDismissRequest, + properties = properties, + onPreviewKeyEvent = onPreviewKeyEvent, + onKeyEvent = onKeyEvent, + content = content + ) + } ?: ComposePopup( + alignment = alignment, + offset = offset, + onDismissRequest = onDismissRequest, + properties = properties, + onPreviewKeyEvent = onPreviewKeyEvent, + onKeyEvent = onKeyEvent, + content = content + ) +} \ No newline at end of file