1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-03-26 21:37:00 +00:00

Add scaffold preview, use container color in about screen and scaffold

This commit is contained in:
Isira Seneviratne 2024-09-16 17:24:31 +05:30
parent 4c4fe3f511
commit c00c6c460c
2 changed files with 23 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.ui.components.common package org.schabi.newpipe.ui.components.common
import android.content.res.Configuration
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -7,10 +8,13 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
@ -24,6 +28,9 @@ fun ScaffoldWithToolbar(
topBar = { topBar = {
TopAppBar( TopAppBar(
title = { Text(text = title) }, title = { Text(text = title) },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer
),
navigationIcon = { navigationIcon = {
IconButton(onClick = onBackClick) { IconButton(onClick = onBackClick) {
Icon( Icon(
@ -38,3 +45,14 @@ fun ScaffoldWithToolbar(
content = content content = content
) )
} }
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun ScaffoldWithToolbarPreview() {
ScaffoldWithToolbar(
title = "Example",
onBackClick = {},
content = {}
)
}

View File

@ -20,7 +20,6 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -45,10 +44,13 @@ fun AboutScreen(padding: PaddingValues) {
tabIndex = pagerState.currentPage tabIndex = pagerState.currentPage
} }
TabRow(selectedTabIndex = tabIndex) { TabRow(
selectedTabIndex = tabIndex,
containerColor = MaterialTheme.colorScheme.primaryContainer
) {
TITLES.forEachIndexed { index, titleId -> TITLES.forEachIndexed { index, titleId ->
Tab( Tab(
text = { Text(text = stringResource(titleId), color = Color.White) }, text = { Text(text = stringResource(titleId)) },
selected = tabIndex == index, selected = tabIndex == index,
onClick = { tabIndex = index } onClick = { tabIndex = index }
) )