feat: Enhance MessageInputBar with emoji picker and smooth send button animation
This commit is contained in:
@@ -29,6 +29,9 @@ import androidx.compose.ui.graphics.Brush
|
|||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.imePadding
|
import androidx.compose.foundation.layout.imePadding
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import com.rosetta.messenger.network.ProtocolManager
|
import com.rosetta.messenger.network.ProtocolManager
|
||||||
import com.rosetta.messenger.network.SearchUser
|
import com.rosetta.messenger.network.SearchUser
|
||||||
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
|
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
|
||||||
@@ -385,6 +388,8 @@ private fun MessageBubble(
|
|||||||
/**
|
/**
|
||||||
* Панель ввода сообщения со стеклянным эффектом (Glass Morphism)
|
* Панель ввода сообщения со стеклянным эффектом (Glass Morphism)
|
||||||
* Все иконки внутри одного стеклянного инпута
|
* Все иконки внутри одного стеклянного инпута
|
||||||
|
* + Плавная анимация самолетика
|
||||||
|
* + Эмодзи пикер
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun MessageInputBar(
|
private fun MessageInputBar(
|
||||||
@@ -396,6 +401,9 @@ private fun MessageInputBar(
|
|||||||
textColor: Color,
|
textColor: Color,
|
||||||
placeholderColor: Color
|
placeholderColor: Color
|
||||||
) {
|
) {
|
||||||
|
// Состояние эмодзи пикера
|
||||||
|
var showEmojiPicker by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// Цвета для glass morphism эффекта
|
// Цвета для glass morphism эффекта
|
||||||
val glassBackground = if (isDarkTheme)
|
val glassBackground = if (isDarkTheme)
|
||||||
Color(0xFF1A1A1A).copy(alpha = 0.85f)
|
Color(0xFF1A1A1A).copy(alpha = 0.85f)
|
||||||
@@ -414,6 +422,57 @@ private fun MessageInputBar(
|
|||||||
|
|
||||||
val iconColor = if (isDarkTheme) Color(0xFF8E8E93) else Color(0xFF666666)
|
val iconColor = if (isDarkTheme) Color(0xFF8E8E93) else Color(0xFF666666)
|
||||||
|
|
||||||
|
// Анимация для кнопки отправки
|
||||||
|
val sendButtonVisible = value.isNotBlank()
|
||||||
|
val sendButtonScale by animateFloatAsState(
|
||||||
|
targetValue = if (sendButtonVisible) 1f else 0f,
|
||||||
|
animationSpec = spring(
|
||||||
|
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||||
|
stiffness = Spring.StiffnessMedium
|
||||||
|
),
|
||||||
|
label = "sendScale"
|
||||||
|
)
|
||||||
|
val sendButtonRotation by animateFloatAsState(
|
||||||
|
targetValue = if (sendButtonVisible) 0f else -90f,
|
||||||
|
animationSpec = spring(
|
||||||
|
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||||
|
stiffness = Spring.StiffnessLow
|
||||||
|
),
|
||||||
|
label = "sendRotation"
|
||||||
|
)
|
||||||
|
val sendButtonAlpha by animateFloatAsState(
|
||||||
|
targetValue = if (sendButtonVisible) 1f else 0f,
|
||||||
|
animationSpec = tween(200),
|
||||||
|
label = "sendAlpha"
|
||||||
|
)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
// Эмодзи пикер (показывается над инпутом)
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = showEmojiPicker,
|
||||||
|
enter = slideInVertically(
|
||||||
|
initialOffsetY = { it },
|
||||||
|
animationSpec = spring(
|
||||||
|
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||||
|
stiffness = Spring.StiffnessMediumLow
|
||||||
|
)
|
||||||
|
) + fadeIn(),
|
||||||
|
exit = slideOutVertically(
|
||||||
|
targetOffsetY = { it },
|
||||||
|
animationSpec = tween(200)
|
||||||
|
) + fadeOut()
|
||||||
|
) {
|
||||||
|
EmojiPickerPanel(
|
||||||
|
isDarkTheme = isDarkTheme,
|
||||||
|
onEmojiSelected = { emoji ->
|
||||||
|
onValueChange(value + emoji)
|
||||||
|
},
|
||||||
|
onClose = { showEmojiPicker = false }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Основной контейнер
|
// Основной контейнер
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -462,13 +521,13 @@ private fun MessageInputBar(
|
|||||||
) {
|
) {
|
||||||
// Кнопка смайликов (слева внутри инпута)
|
// Кнопка смайликов (слева внутри инпута)
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { /* TODO: Emoji picker */ },
|
onClick = { showEmojiPicker = !showEmojiPicker },
|
||||||
modifier = Modifier.size(36.dp)
|
modifier = Modifier.size(36.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.EmojiEmotions,
|
if (showEmojiPicker) Icons.Default.Keyboard else Icons.Default.EmojiEmotions,
|
||||||
contentDescription = "Emoji",
|
contentDescription = "Emoji",
|
||||||
tint = iconColor,
|
tint = if (showEmojiPicker) PrimaryBlue else iconColor,
|
||||||
modifier = Modifier.size(22.dp)
|
modifier = Modifier.size(22.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -538,31 +597,137 @@ private fun MessageInputBar(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
// Кнопка отправки (появляется только когда есть текст)
|
// Кнопка отправки с плавной анимацией
|
||||||
AnimatedVisibility(
|
Box(
|
||||||
visible = value.isNotBlank(),
|
|
||||||
enter = scaleIn(animationSpec = tween(150)) + fadeIn(animationSpec = tween(150)),
|
|
||||||
exit = scaleOut(animationSpec = tween(150)) + fadeOut(animationSpec = tween(150))
|
|
||||||
) {
|
|
||||||
IconButton(
|
|
||||||
onClick = onSend,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(44.dp)
|
.size(44.dp)
|
||||||
|
.graphicsLayer {
|
||||||
|
scaleX = sendButtonScale
|
||||||
|
scaleY = sendButtonScale
|
||||||
|
rotationZ = sendButtonRotation
|
||||||
|
alpha = sendButtonAlpha
|
||||||
|
}
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(
|
.background(
|
||||||
brush = Brush.linearGradient(
|
brush = Brush.linearGradient(
|
||||||
colors = listOf(
|
colors = listOf(
|
||||||
PrimaryBlue,
|
PrimaryBlue,
|
||||||
PrimaryBlue.copy(alpha = 0.85f)
|
Color(0xFF5B8DEF)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.clickable(enabled = sendButtonVisible) { onSend() },
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Send,
|
Icons.Default.Send,
|
||||||
contentDescription = "Send",
|
contentDescription = "Send",
|
||||||
tint = Color.White,
|
tint = Color.White,
|
||||||
modifier = Modifier.size(20.dp)
|
modifier = Modifier
|
||||||
|
.size(20.dp)
|
||||||
|
.graphicsLayer {
|
||||||
|
// Дополнительная микроанимация иконки
|
||||||
|
translationX = 2.dp.toPx()
|
||||||
|
translationY = -1.dp.toPx()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Панель выбора эмодзи с Apple-стиль эмодзи
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun EmojiPickerPanel(
|
||||||
|
isDarkTheme: Boolean,
|
||||||
|
onEmojiSelected: (String) -> Unit,
|
||||||
|
onClose: () -> Unit
|
||||||
|
) {
|
||||||
|
val panelBackground = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFF2F2F7)
|
||||||
|
val categoryBackground = if (isDarkTheme) Color(0xFF2C2C2E) else Color(0xFFFFFFFF)
|
||||||
|
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||||
|
|
||||||
|
// Категории эмодзи
|
||||||
|
val emojiCategories = remember {
|
||||||
|
listOf(
|
||||||
|
"😀" to listOf("😀", "😃", "😄", "😁", "😆", "😅", "🤣", "😂", "🙂", "🙃", "😉", "😊", "😇", "🥰", "😍", "🤩", "😘", "😗", "☺️", "😚", "😙", "🥲", "😋", "😛", "😜", "🤪", "😝", "🤑", "🤗", "🤭", "🤫", "🤔", "🤐", "🤨", "😐", "😑", "😶", "😏", "😒", "🙄", "😬", "🤥", "😌", "😔", "😪", "🤤", "😴", "😷"),
|
||||||
|
"❤️" to listOf("❤️", "🧡", "💛", "💚", "💙", "💜", "🖤", "🤍", "🤎", "💔", "❤️🔥", "❤️🩹", "💕", "💞", "💓", "💗", "💖", "💘", "💝", "💟", "♥️", "💌", "💋", "👄", "👅", "🫦"),
|
||||||
|
"👋" to listOf("👋", "🤚", "🖐️", "✋", "🖖", "👌", "🤌", "🤏", "✌️", "🤞", "🤟", "🤘", "🤙", "👈", "👉", "👆", "🖕", "👇", "☝️", "👍", "👎", "✊", "👊", "🤛", "🤜", "👏", "🙌", "👐", "🤲", "🤝", "🙏", "✍️", "💅", "🤳", "💪"),
|
||||||
|
"🔥" to listOf("🔥", "⭐", "🌟", "✨", "⚡", "💥", "💫", "🎉", "🎊", "🎈", "🎁", "🏆", "🥇", "🥈", "🥉", "🎯", "🎪", "🎭", "🎨", "🎬", "🎤", "🎧", "🎵", "🎶", "🎹", "🎸", "🎺", "🎷", "🪘", "🥁"),
|
||||||
|
"🐱" to listOf("🐱", "🐶", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🙈", "🙉", "🙊", "🐔", "🐧", "🐦", "🐤", "🦆", "🦅", "🦉", "🦇", "🐺", "🐗", "🐴", "🦄"),
|
||||||
|
"🍎" to listOf("🍎", "🍐", "🍊", "🍋", "🍌", "🍉", "🍇", "🍓", "🫐", "🍈", "🍒", "🍑", "🥭", "🍍", "🥥", "🥝", "🍅", "🍆", "🥑", "🥦", "🥬", "🥒", "🌶️", "🫑", "🌽", "🥕", "🫒", "🧄", "🧅", "🥔"),
|
||||||
|
"⚽" to listOf("⚽", "🏀", "🏈", "⚾", "🥎", "🎾", "🏐", "🏉", "🥏", "🎱", "🪀", "🏓", "🏸", "🏒", "🏑", "🥍", "🏏", "🪃", "🥅", "⛳", "🪁", "🏹", "🎣", "🤿", "🥊", "🥋", "🎽", "🛹", "🛼", "🛷"),
|
||||||
|
"🚗" to listOf("🚗", "🚕", "🚙", "🚌", "🚎", "🏎️", "🚓", "🚑", "🚒", "🚐", "🛻", "🚚", "🚛", "🚜", "🏍️", "🛵", "🚲", "🛴", "🚨", "🚔", "🚍", "🚘", "🚖", "✈️", "🛫", "🛬", "🚀", "🛸", "🚁", "⛵")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedCategory by remember { mutableStateOf(0) }
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(280.dp)
|
||||||
|
.background(panelBackground)
|
||||||
|
) {
|
||||||
|
// Категории вверху
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(categoryBackground)
|
||||||
|
.padding(horizontal = 8.dp, vertical = 4.dp),
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
|
) {
|
||||||
|
emojiCategories.forEachIndexed { index, (emoji, _) ->
|
||||||
|
val isSelected = selectedCategory == index
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(36.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(
|
||||||
|
if (isSelected) PrimaryBlue.copy(alpha = 0.2f) else Color.Transparent
|
||||||
|
)
|
||||||
|
.clickable { selectedCategory = index },
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = emoji,
|
||||||
|
fontSize = 20.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalDivider(
|
||||||
|
color = if (isDarkTheme) Color(0xFF3A3A3C) else Color(0xFFE5E5EA),
|
||||||
|
thickness = 0.5.dp
|
||||||
|
)
|
||||||
|
|
||||||
|
// Сетка эмодзи
|
||||||
|
val emojis = emojiCategories[selectedCategory].second
|
||||||
|
|
||||||
|
LazyVerticalGrid(
|
||||||
|
columns = GridCells.Fixed(8),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.weight(1f)
|
||||||
|
.padding(8.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
|
) {
|
||||||
|
items(emojis.size) { index ->
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.aspectRatio(1f)
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.clickable { onEmojiSelected(emojis[index]) },
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = emojis[index],
|
||||||
|
fontSize = 28.sp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user