dm-81
This commit is contained in:
parent
ef75829e4d
commit
96944ca6b9
3 changed files with 46 additions and 35 deletions
|
|
@ -89,4 +89,10 @@ dependencies {
|
||||||
|
|
||||||
implementation("androidx.datastore:datastore-preferences:1.2.1")
|
implementation("androidx.datastore:datastore-preferences:1.2.1")
|
||||||
|
|
||||||
|
|
||||||
|
//emoji pack
|
||||||
|
val emoji2Version = "1.5.0" // 請根據你當前環境選擇最新穩定版
|
||||||
|
implementation("androidx.emoji2:emoji2:$emoji2Version")
|
||||||
|
implementation("androidx.emoji2:emoji2-bundled:$emoji2Version") // 自帶字型包
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,6 +13,8 @@ import com.example.login_v3.ui.theme.AppTheme
|
||||||
import com.example.login_v3.ui.theme.Login_V3Theme
|
import com.example.login_v3.ui.theme.Login_V3Theme
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.emoji2.bundled.BundledEmojiCompatConfig
|
||||||
|
import androidx.emoji2.text.EmojiCompat
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
|
|
@ -22,6 +24,10 @@ class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
// emoji pack
|
||||||
|
val config = BundledEmojiCompatConfig(this)
|
||||||
|
EmojiCompat.init(config)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
installSplashScreen()
|
installSplashScreen()
|
||||||
|
|
|
||||||
|
|
@ -28,82 +28,81 @@ import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
object EmojiProvider {
|
||||||
|
fun getSmileysAndPeople(): List<String> {
|
||||||
|
val emojis = mutableListOf<String>()
|
||||||
|
|
||||||
|
// 1. 經典表情區間 (Smiley Faces): 😀 到 🪟
|
||||||
|
for (i in 0x1F600..0x1F64F) {
|
||||||
|
if (Character.isValidCodePoint(i)) {
|
||||||
|
emojis.add(String(Character.toChars(i)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 常用手勢與身體部位 (Body & Gestures): 👍 👏 等
|
||||||
|
for (i in 0x1F440..0x1F49F) {
|
||||||
|
if (Character.isValidCodePoint(i)) {
|
||||||
|
emojis.add(String(Character.toChars(i)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return emojis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MessageEmojiBar(
|
fun MessageEmojiBar(
|
||||||
onEmojiClick: (String) -> Unit,
|
onEmojiClick: (String) -> Unit,
|
||||||
onCancel: () -> Unit,
|
onCancel: () -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
// 這裡可以無限塞入幾百個 Emoji 都沒問題了!
|
// emoji pack
|
||||||
val emojiList = remember {
|
val emojiList = remember { EmojiProvider.getSmileysAndPeople() }
|
||||||
listOf(
|
|
||||||
"👍", "❤️", "😂", "😮", "😢", "🙏",
|
|
||||||
"🔥", "🎉", "👏", "👀", "✨", "💯",
|
|
||||||
"🤔", "🥳", "😎", "🚀", "💔", "💩",
|
|
||||||
"🤩", "🤯", "🙄", "🤫", "😴", "🤤",
|
|
||||||
"😭", "😡", "🤡", "👻", "👽", "🤖",
|
|
||||||
"👑", "🦄", "🐾", "🍕", "🍺", "☕️"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(300.dp), // 保持你設定的 300.dp 固定高度
|
.height(300.dp),
|
||||||
color = Color(0xFFF5F5F5),
|
color = Color(0xFFF5F5F5),
|
||||||
tonalElevation = 4.dp
|
tonalElevation = 4.dp
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.navigationBarsPadding() // 確保不被系統海苔條遮擋
|
.navigationBarsPadding()
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp)
|
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||||
) {
|
) {
|
||||||
// 【頂部功能列】:左邊放個小提示,右邊放關閉按鈕
|
// 頂部功能列 (標題與叉叉)
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp),
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(bottom = 8.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(text = "傳送回應", fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Color.Gray)
|
||||||
text = "傳送回應",
|
|
||||||
fontSize = 14.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = Color.Gray
|
|
||||||
)
|
|
||||||
|
|
||||||
// 關閉按鈕
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier.clip(CircleShape).clickable { onCancel() }.padding(8.dp)
|
||||||
.clip(CircleShape)
|
|
||||||
.clickable { onCancel() }
|
|
||||||
.padding(8.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
) {
|
||||||
Text(text = "✕", color = Color.Gray, fontSize = 16.sp)
|
Text(text = "✕", color = Color.Gray, fontSize = 16.sp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 【核心改動】:使用網格佈局,塞再多都不怕!
|
// 網格滾動區:塞了幾百個也能流暢滑動
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Fixed(6),
|
columns = GridCells.Fixed(6),
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
contentPadding = PaddingValues(bottom = 8.dp)
|
|
||||||
) {
|
) {
|
||||||
items(emojiList) { emoji ->
|
items(emojiList) { emoji ->
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.aspectRatio(1f) // 讓每個格子都是正方形,比較好對齊
|
.aspectRatio(1f)
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.clickable { onEmojiClick(emoji) },
|
.clickable { onEmojiClick(emoji) },
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = emoji,
|
text = emoji,
|
||||||
fontSize = 28.sp // 稍微放大一點點,比較好點擊
|
fontSize = 28.sp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue