This commit is contained in:
Eric85710 2026-06-19 15:01:18 +08:00
parent c6aad75658
commit f7a5db99a0
2 changed files with 94 additions and 35 deletions

View file

@ -22,38 +22,37 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.example.login_v3.home.Tg_MarketPlace
import com.example.login_v3.home.Message.UI.Tg_Message
import com.example.login_v3.home.Tg_Server
import com.example.login_v3.home.setting.Tg_Setting
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel
import androidx.hilt.navigation.compose.hiltViewModel // 確保有引入 hiltViewModel
import com.example.login_v3.navigation.components.AppWallpaperBackground
@Composable
fun MainScreen_tab() {
fun MainScreen_tab(
// 注入 Theme_ViewModel 來讀取壁紙狀態
themeViewModel: Theme_ViewModel = hiltViewModel()
) {
val screensViewModel: ScreensViewModel = viewModel()
val bottomBarViewModel: BottomBarViewModel = viewModel()
//show bottom bar or not
// show bottom bar or not
val showBottomBar by bottomBarViewModel.showBottomBar.collectAsState()
val navHeight = 64.dp
val gap = 40.dp
val bottomBarHeight = navHeight + gap
// 使用剛剛做好的壁紙元件包在最外層
AppWallpaperBackground(viewModel = themeViewModel) {
Scaffold(
containerColor = Color.Transparent,
modifier = Modifier
.fillMaxSize()
.background(brush = Brush.verticalGradient(
colors = listOf(
Color(0xFFDA7029),
Color(0xFF777777),
Color(0xFFB34800)
)
)),
containerColor = Color.Transparent, // 必須保持透明,底層的壁紙才看得到
modifier = Modifier.fillMaxSize(),
bottomBar = {
BottomBarAnimated(
visible = showBottomBar,
@ -67,7 +66,7 @@ fun MainScreen_tab() {
) {
nav_Wheel_display_block(screensViewModel = screensViewModel)
}
Spacer(modifier = Modifier.height(gap)) // 真正的底下空白
Spacer(modifier = Modifier.height(gap))
}
}
)
@ -79,6 +78,7 @@ fun MainScreen_tab() {
bottomBarViewModel = bottomBarViewModel
)
}
}
}
@Composable

View file

@ -0,0 +1,59 @@
package com.example.login_v3.navigation.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import coil.compose.AsyncImage
import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel
import java.io.File
@Composable
fun AppWallpaperBackground(
viewModel: Theme_ViewModel,
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
// 監聽來自 DataStore 的壁紙路徑
val wallpaperPath by viewModel.customWallpaperPath.collectAsState()
// 檢查檔案是否真的存在
val wallpaperFile = wallpaperPath?.let { File(it) }
val hasCustomWallpaper = wallpaperFile != null && wallpaperFile.exists()
Box(modifier = modifier.fillMaxSize()) {
if (hasCustomWallpaper) {
// 1. 如果有自訂壁紙,使用 Coil 填滿背景
AsyncImage(
model = wallpaperFile,
contentDescription = "App Custom Wallpaper",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop // 裁切填滿
)
} else {
// 2. 如果沒有,使用你原本的三色漸層
Box(
modifier = Modifier
.fillMaxSize()
.background(
brush = Brush.verticalGradient(
colors = listOf(
Color(0xFFDA7029),
Color(0xFF777777),
Color(0xFFB34800)
)
)
)
)
}
// 3. 將原本的 Scaffold 或內容蓋在背景上方
content()
}
}