feat: add Popup

This commit is contained in:
2023-11-16 02:42:19 +08:00
parent 1020735b0c
commit 8e09ae9a1a
5 changed files with 204 additions and 28 deletions

View File

@@ -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
)
}

View File

@@ -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

View File

@@ -21,6 +21,23 @@
*/
@file:Suppress("unused")
package com.highcapable.flexiui.interaction
package com.highcapable.flexiui.component
// TODO: To be implemented
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
)

View File

@@ -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
)
}

View File

@@ -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
)
}