Refactor(Preview): Change all preview to OxygenPreviews

Change all preview to OxygenPreviews. Fix can not preview OxygenTopAppBar bug.
This commit is contained in:
2024-04-24 17:20:55 +08:00
parent b2e7ecc92c
commit b11ae055c3
8 changed files with 56 additions and 50 deletions

View File

@@ -23,9 +23,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import top.fatweb.oxygen.toolbox.R
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
import top.fatweb.oxygen.toolbox.ui.component.ApiLevelPreviews
import top.fatweb.oxygen.toolbox.ui.component.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.component.ThemePreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
import top.fatweb.oxygen.toolbox.ui.util.ResourcesUtils
@@ -137,7 +135,7 @@ private fun AboutFooter(
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun AboutToolBarPreview() {
OxygenTheme {
@@ -145,7 +143,7 @@ fun AboutToolBarPreview() {
}
}
@ApiLevelPreviews
@OxygenPreviews
@Composable
fun AboutAppInfoPreview() {
OxygenTheme {

View File

@@ -1,6 +1,5 @@
package top.fatweb.oxygen.toolbox.ui.component
import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
@@ -15,12 +14,12 @@ import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import top.fatweb.oxygen.toolbox.ui.theme.GradientColors
import top.fatweb.oxygen.toolbox.ui.theme.LocalBackgroundTheme
import top.fatweb.oxygen.toolbox.ui.theme.LocalGradientColors
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
import kotlin.math.tan
@@ -92,21 +91,7 @@ fun OxygenGradientBackground(
}
}
@Preview(name = "Light theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "Dark theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(name = "Api 21", group = "ApiLevelPreviews", apiLevel = 21)
annotation class OxygenPreviews
@Preview(name = "Light theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "Dark theme", group = "ThemePreviews", uiMode = Configuration.UI_MODE_NIGHT_YES)
annotation class ThemePreviews
@Preview(name = "Api 21", group = "ApiLevelPreviews", apiLevel = 21)
@Preview(name = "Api Default", group = "ApiLevelPreviews")
annotation class ApiLevelPreviews
@ThemePreviews
@OxygenPreviews
@Composable
fun BackgroundDefault() {
OxygenTheme(dynamicColor = false) {
@@ -114,7 +99,7 @@ fun BackgroundDefault() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun BackgroundDynamic() {
OxygenTheme(dynamicColor = true) {
@@ -122,7 +107,7 @@ fun BackgroundDynamic() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun BackgroundAndroid() {
OxygenTheme(androidTheme = true) {
@@ -130,7 +115,7 @@ fun BackgroundAndroid() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun GradientBackgroundDefault() {
OxygenTheme(dynamicColor = false) {
@@ -138,7 +123,7 @@ fun GradientBackgroundDefault() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun GradientBackgroundDynamic() {
OxygenTheme(dynamicColor = true) {
@@ -146,7 +131,7 @@ fun GradientBackgroundDynamic() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun GradientBackgroundAndroid() {
OxygenTheme(androidTheme = true) {

View File

@@ -17,6 +17,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import top.fatweb.oxygen.toolbox.navigation.TopLevelDestination
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
@Composable
@@ -116,7 +117,7 @@ object OxygenNavigationDefaults {
fun navigationIndicatorColor() = MaterialTheme.colorScheme.primaryContainer
}
@ThemePreviews
@OxygenPreviews
@Composable
fun OxygenNavigationBarPreview() {
val items = TopLevelDestination.entries
@@ -147,7 +148,7 @@ fun OxygenNavigationBarPreview() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun OxygenNavigationRailPreview() {
val items = TopLevelDestination.entries

View File

@@ -18,9 +18,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
import android.R as androidR
@@ -39,7 +39,7 @@ fun OxygenTopAppBar(
onActionClick: () -> Unit = {}
) {
val topInset by animateIntAsState(
if (-scrollBehavior?.state?.heightOffset!! >= with(LocalDensity.current) { 64.0.dp.toPx() }) 0
if (scrollBehavior != null && -scrollBehavior.state.heightOffset >= with(LocalDensity.current) { 64.0.dp.toPx() }) 0
else TopAppBarDefaults.windowInsets.getTop(LocalDensity.current), label = ""
)
CenterAlignedTopAppBar(
@@ -70,7 +70,7 @@ fun OxygenTopAppBar(
}
@OptIn(ExperimentalMaterial3Api::class)
@Preview
@OxygenPreviews
@Composable
private fun OxygenTopAppBarPreview() {
OxygenTheme {

View File

@@ -38,6 +38,7 @@ import top.fatweb.oxygen.toolbox.data.tool.ToolDataSource
import top.fatweb.oxygen.toolbox.icon.OxygenIcons
import top.fatweb.oxygen.toolbox.model.tool.Tool
import top.fatweb.oxygen.toolbox.model.tool.ToolGroup
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
@Composable
@@ -152,7 +153,7 @@ fun SwitchableIcon(
)
}
@ThemePreviews
@OxygenPreviews
@Composable
private fun ToolGroupCardPreview() {
val groups = runBlocking { ToolDataSource().tool.first() }
@@ -171,7 +172,7 @@ private fun ToolGroupCardPreview() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun SwitchableIconPreview() {
var switched by remember { mutableStateOf(false) }
@@ -185,7 +186,7 @@ fun SwitchableIconPreview() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun ToolGroupItemPreview() {
OxygenTheme {
@@ -193,7 +194,7 @@ fun ToolGroupItemPreview() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
fun ToolGroupContentPreview() {
OxygenTheme {

View File

@@ -39,7 +39,7 @@ import top.fatweb.oxygen.toolbox.model.userdata.LanguageConfig
import top.fatweb.oxygen.toolbox.model.userdata.LaunchPageConfig
import top.fatweb.oxygen.toolbox.model.userdata.ThemeBrandConfig
import top.fatweb.oxygen.toolbox.model.userdata.UserData
import top.fatweb.oxygen.toolbox.ui.component.ThemePreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
import top.fatweb.oxygen.toolbox.ui.theme.supportsDynamicTheming
@@ -316,7 +316,7 @@ private fun SettingsDialogClickerRow(
}
}
@ThemePreviews
@OxygenPreviews
@Composable
private fun SettingsDialogLoadingPreview() {
OxygenTheme {
@@ -334,7 +334,7 @@ private fun SettingsDialogLoadingPreview() {
}
}
@ThemePreviews
@OxygenPreviews
@Composable
private fun SettingDialogPreview() {
OxygenTheme {

View File

@@ -1,5 +1,6 @@
package top.fatweb.oxygen.toolbox.ui.theme
import android.content.res.Configuration
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.compose.foundation.isSystemInDarkTheme
@@ -13,6 +14,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
val LightDefaultColorScheme = lightColorScheme(
@@ -191,4 +193,18 @@ fun OxygenTheme(
}
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
fun supportsDynamicTheming() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
fun supportsDynamicTheming() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
@Preview(
name = "Light theme", group = "ThemePreviews",
uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL
)
@Preview(
name = "Dark theme", group = "ThemePreviews",
uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL
)
@Preview(
name = "Api 21 Light", group = "ApiLevelPreviews", apiLevel = 21,
uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL
)
annotation class OxygenPreviews

View File

@@ -25,7 +25,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -36,6 +35,8 @@ import top.fatweb.oxygen.toolbox.data.tool.ToolDataSource
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.DraggableScrollbar
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.rememberDraggableScroller
import top.fatweb.oxygen.toolbox.ui.component.scrollbar.scrollbarState
import top.fatweb.oxygen.toolbox.ui.theme.OxygenPreviews
import top.fatweb.oxygen.toolbox.ui.theme.OxygenTheme
@Composable
internal fun ToolsRoute(
@@ -110,19 +111,23 @@ fun howManyItems(toolScreenUiState: ToolsScreenUiState) =
is ToolsScreenUiState.Success -> toolScreenUiState.toolGroups.size
}
@Preview("Loading")
@OxygenPreviews
@Composable
fun ToolsScreenLoadingPreview() {
ToolsScreen(toolsScreenUiState = ToolsScreenUiState.Loading)
OxygenTheme {
ToolsScreen(toolsScreenUiState = ToolsScreenUiState.Loading)
}
}
@Preview("ToolsPage")
@OxygenPreviews
@Composable
fun ToolsScreenPreview() {
ToolsScreen(
toolsScreenUiState = ToolsScreenUiState.Success(
runBlocking {
ToolDataSource().tool.first()
})
)
OxygenTheme {
ToolsScreen(
toolsScreenUiState = ToolsScreenUiState.Success(
runBlocking {
ToolDataSource().tool.first()
})
)
}
}