Hat jemand eine Idee, was zu tun ist, bitte? Ich habe versucht, den Header auch in eine separate Datei zu wechseln.
Danke im Voraus.
Code: Select all
@Composable
fun MyApp() {
val tabs = listOf("Home", "Contact")
var selectedTab by remember { mutableStateOf(0) }
var headerVisible by remember { mutableStateOf(true) } // Control header visibility
val animatedAlpha by animateFloatAsState(if (headerVisible) 1f else 0f)
Column {
// ✅ Moved Header to a Separate Function (Prevents Refresh)
if (animatedAlpha > 0f) {
Header()
}
// Tabs
TabRow(
selectedTabIndex = selectedTab,
backgroundColor = Color.White, // ✅ Background color of TabRow
modifier = Modifier
.fillMaxWidth()
.offset(y = 0.dp) // ✅ Keeps it in place
.zIndex(1f) // ✅ Ensures tabs stay above other components if needed
) {
tabs.forEachIndexed { index, title ->
Tab(
selected = selectedTab == index,
onClick = { selectedTab = index },
selectedContentColor = Color(0xff1f68da), // ✅ Color when selected
unselectedContentColor = Color.Gray, // ✅ Color when not selected
text = {
Text(
text = title,
fontFamily = customFontFamily,
fontWeight = FontWeight.Normal,
color = if (selectedTab == index) Color(0xff1f68da) else Color.Gray
)
}
)
}
}
// WebView Content Based on Selected Tab
when (selectedTab) {
0 -> HomeView { scrollDiff -> headerVisible = scrollDiff ContactView { scrollDiff -> headerVisible = scrollDiff Unit) {
WebViewPage(url = "https://www.google.com”, onScroll = onScroll)
}