Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Aug 12, 2024
1 parent 834eea7 commit 4a29b23
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.NavigationItem
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet

@Composable
fun MainScaffold(
Expand All @@ -65,25 +66,15 @@ fun MainScaffold(
}
}

MainScaffold(navType, currentDestination, navController, content)
MainScaffold(navType, currentDestination, navController::navigateToSelectedItem, content)
}

@Composable
private fun MainScaffold(
navType: NavigationSuiteType,
currentDestination: MainNavigation,
navController: NavHostController,
content: @Composable () -> Unit,
) {
Navigation(currentDestination, navController::navigateToSelectedItem, navType, content)
}

@Composable
private fun Navigation(
currentDestination: MainNavigation,
navigateToSelectedItem: (MainNavigation) -> Unit,
navType: NavigationSuiteType,
content: @Composable () -> Unit
content: @Composable () -> Unit,
) {
val isNavigationBar = navType == NavigationSuiteType.NavigationBar

Expand Down Expand Up @@ -148,13 +139,26 @@ private fun NavHostController.navigateToSelectedItem(destination: MainNavigation

@PreviewMobile
@Composable
private fun NavigationPreview() {
private fun NavigationPreviewMobile() {
SwissTransferTheme {
Navigation(
MainScaffold(
currentDestination = MainNavigation.SentDestination,
navigateToSelectedItem = {},
navType = NavigationSuiteType.NavigationBar,
content = {},
)
}
}

@PreviewTablet
@Composable
private fun NavigationPreviewTablet() {
SwissTransferTheme {
MainScaffold(
currentDestination = MainNavigation.SentDestination,
navigateToSelectedItem = {},
navType = NavigationSuiteType.NavigationRail,
content = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,3 @@ val LightColors = CustomColors(
navigationItemBackground = light_background,
divider = Color(mouse),
)

@Immutable
data class CustomColors(
val primaryTextColor: Color,
val secondaryTextColor: Color,
val navigationItemBackground: Color,
val divider: Color,
)
26 changes: 16 additions & 10 deletions app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
package com.infomaniak.swisstransfer.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color

private val DarkColorScheme = darkColorScheme(
primary = dark_primary,
Expand Down Expand Up @@ -57,7 +52,7 @@ private val LightColorScheme = lightColorScheme(
)

val LocalCustomTypography = staticCompositionLocalOf { Typography }
val LocalCustomColors: ProvidableCompositionLocal<CustomColors?> = staticCompositionLocalOf { null }
val LocalCustomColors: ProvidableCompositionLocal<CustomColors> = staticCompositionLocalOf { CustomColors() }

@Composable
fun SwissTransferTheme(
Expand All @@ -84,5 +79,16 @@ object SwissTransferTheme {
get() = LocalCustomTypography.current
val colors: CustomColors
@Composable
get() = LocalCustomColors.current ?: error("Cannot access uninitialized LocalCustomColors")
get() = LocalCustomColors.current
val materialColors: ColorScheme
@Composable
get() = MaterialTheme.colorScheme
}

@Immutable
data class CustomColors(
val primaryTextColor: Color = Color.Unspecified,
val secondaryTextColor: Color = Color.Unspecified,
val navigationItemBackground: Color = Color.Unspecified,
val divider: Color = Color.Unspecified,
)

0 comments on commit 4a29b23

Please sign in to comment.