mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Update emoji menu popup
This commit is contained in:
parent
5b42876fc9
commit
b4f198944f
@ -1,13 +1,13 @@
|
||||
package org.futo.inputmethod.latin.uix.actions
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@ -44,6 +44,7 @@ import androidx.compose.ui.draw.clipToBounds
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.translate
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.input.pointer.PointerEventPass
|
||||
import androidx.compose.ui.input.pointer.PointerEventType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
@ -216,6 +217,7 @@ fun Emojis(
|
||||
}
|
||||
|
||||
var activePopup: PopupInfo? by rememberSaveable { mutableStateOf(null) }
|
||||
var popupIsActive by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val color = LocalContentColor.current
|
||||
|
||||
@ -223,7 +225,10 @@ fun Emojis(
|
||||
EmojiGridAdapter(
|
||||
emojis,
|
||||
onClick,
|
||||
onSelectSkinTone = { activePopup = it },
|
||||
onSelectSkinTone = {
|
||||
activePopup = it
|
||||
popupIsActive = true
|
||||
},
|
||||
emojiWidth,
|
||||
color
|
||||
)
|
||||
@ -255,26 +260,30 @@ fun Emojis(
|
||||
(it.layoutManager as GridLayoutManager).spanCount = viewWidth / emojiWidth
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxSize()
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clipToBounds()
|
||||
.onSizeChanged {
|
||||
viewWidth = it.width
|
||||
viewHeight = it.height
|
||||
}.pointerInput(Unit) {
|
||||
}
|
||||
.pointerInput(Unit) {
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent()
|
||||
if(event.type == PointerEventType.Press) {
|
||||
activePopup = null
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
if (event.type == PointerEventType.Press && popupIsActive) {
|
||||
popupIsActive = false
|
||||
event.changes.firstOrNull()?.consume()
|
||||
} else if(event.type == PointerEventType.Move && popupIsActive) {
|
||||
event.changes.firstOrNull()?.consume()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
activePopup?.let { popupInfo ->
|
||||
val posX = popupInfo.x - popupSize.width / 2
|
||||
val posY = popupInfo.y - popupSize.height
|
||||
val posX = (activePopup?.x ?: 0) - popupSize.width / 2
|
||||
val posY = (activePopup?.y ?: 0) - popupSize.height
|
||||
|
||||
// Calculate the maximum possible x and y values
|
||||
val maxX = viewWidth - popupSize.width
|
||||
@ -284,11 +293,15 @@ fun Emojis(
|
||||
val x = min(maxX, max(0, posX))
|
||||
val y = min(maxY, max(0, posY))
|
||||
|
||||
Box(modifier = Modifier.onSizeChanged {
|
||||
AnimatedVisibility(visible = popupIsActive, modifier = Modifier
|
||||
.onSizeChanged {
|
||||
popupSize = it
|
||||
}.absoluteOffset {
|
||||
}
|
||||
.absoluteOffset {
|
||||
IntOffset(x, y)
|
||||
}) {
|
||||
activePopup?.let { popupInfo ->
|
||||
Box {
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.primaryContainer,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
@ -307,7 +320,7 @@ fun Emojis(
|
||||
tags = listOf()
|
||||
)
|
||||
)
|
||||
activePopup = null
|
||||
popupIsActive = false
|
||||
}, modifier = Modifier
|
||||
.width(42.dp)
|
||||
.height(42.dp)
|
||||
@ -323,6 +336,7 @@ fun Emojis(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BottomRowKeyboardNavigation(onExit: () -> Unit, onBackspace: () -> Unit, onSpace: () -> Unit) {
|
||||
|
Loading…
Reference in New Issue
Block a user