Migrate Theme & Type to CompositionLocalProvider
Load fonts
This commit is contained in:
parent
94de7c1428
commit
0f61eb136b
@ -7,6 +7,8 @@ import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.nto.presentation.theme.NTOTheme
|
||||
import com.nto.presentation.theme.OnomatopoeiafrontTheme
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@ -17,9 +19,9 @@ class MainActivity : ComponentActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
OnomatopoeiafrontTheme {
|
||||
NTOTheme {
|
||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,52 @@
|
||||
package com.nto.presentation.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
val TextGray = Color(0xFFC4BBC7)
|
||||
val BoxGray = Color(0xFFF8F0FB)
|
||||
val Green = Color(0xFF738D73)
|
||||
val GreenDisabled = Color(0xFFCAD5CA)
|
||||
|
||||
val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
@Immutable
|
||||
data class AppColors(
|
||||
val primaryBackground: Color,
|
||||
val secondaryBackground: Color,
|
||||
val inputFieldBackground: Color,
|
||||
val disabledText: Color,
|
||||
val primaryText: Color,
|
||||
val secondaryText: Color,
|
||||
val button: Color,
|
||||
val buttonDisabled: Color,
|
||||
val tint: Color,
|
||||
|
||||
)
|
||||
|
||||
@SuppressLint("ComposeCompositionLocalUsage")
|
||||
val LocalAppColors = staticCompositionLocalOf {
|
||||
AppColors(
|
||||
primaryBackground = Color.Unspecified,
|
||||
secondaryBackground = Color.Unspecified,
|
||||
inputFieldBackground = Color.Unspecified,
|
||||
disabledText = Color.Unspecified,
|
||||
primaryText = Color.Unspecified,
|
||||
secondaryText = Color.Unspecified,
|
||||
button = Color.Unspecified,
|
||||
buttonDisabled = Color.Unspecified,
|
||||
tint = Color.Unspecified
|
||||
)
|
||||
}
|
||||
|
||||
val extendedColor = AppColors(
|
||||
primaryBackground = Color.White,
|
||||
secondaryBackground = Color.Black,
|
||||
inputFieldBackground = BoxGray,
|
||||
disabledText = TextGray,
|
||||
primaryText = Color.Black,
|
||||
secondaryText = Color.White,
|
||||
button = Green,
|
||||
buttonDisabled = GreenDisabled,
|
||||
tint = Color.Black
|
||||
)
|
@ -1,57 +1,27 @@
|
||||
package com.nto.presentation.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
private val DarkColorScheme = darkColorScheme(
|
||||
primary = Purple80,
|
||||
secondary = PurpleGrey80,
|
||||
tertiary = Pink80
|
||||
)
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40
|
||||
|
||||
/* Other default colors to override
|
||||
background = Color(0xFFFFFBFE),
|
||||
surface = Color(0xFFFFFBFE),
|
||||
onPrimary = Color.White,
|
||||
onSecondary = Color.White,
|
||||
onTertiary = Color.White,
|
||||
onBackground = Color(0xFF1C1B1F),
|
||||
onSurface = Color(0xFF1C1B1F),
|
||||
*/
|
||||
)
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
|
||||
@Composable
|
||||
fun OnomatopoeiafrontTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
// Dynamic color is available on Android 12+
|
||||
dynamicColor: Boolean = true,
|
||||
fun NTOTheme(
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
val context = LocalContext.current
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
darkTheme -> DarkColorScheme
|
||||
else -> LightColorScheme
|
||||
CompositionLocalProvider(
|
||||
LocalAppColors provides extendedColor,
|
||||
LocalAppTypography provides extendedTypography
|
||||
) {
|
||||
MaterialTheme(
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
object NTOTheme {
|
||||
val colors: AppColors
|
||||
@Composable get() = LocalAppColors.current
|
||||
|
||||
val typography: AppTypography
|
||||
@Composable get() = LocalAppTypography.current
|
||||
}
|
@ -1,34 +1,51 @@
|
||||
package com.nto.presentation.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.nto.presentation.R
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
/* Other default text styles to override
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 22.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
labelSmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
*/
|
||||
private val RalewayFontFamily = FontFamily(
|
||||
Font(R.font.raleway)
|
||||
)
|
||||
|
||||
private val PlayfairFontFamily = FontFamily(
|
||||
Font(R.font.playfair)
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class AppTypography(
|
||||
val titleLarge: TextStyle,
|
||||
val displaySmall: TextStyle,
|
||||
val placeholder: TextStyle
|
||||
)
|
||||
|
||||
@SuppressLint("ComposeCompositionLocalUsage")
|
||||
val LocalAppTypography = staticCompositionLocalOf {
|
||||
AppTypography(
|
||||
titleLarge = TextStyle.Default,
|
||||
displaySmall = TextStyle.Default,
|
||||
placeholder = TextStyle.Default
|
||||
)
|
||||
}
|
||||
|
||||
val extendedTypography = AppTypography(
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = PlayfairFontFamily,
|
||||
fontSize = 48.sp,
|
||||
),
|
||||
displaySmall = TextStyle(
|
||||
fontFamily = RalewayFontFamily,
|
||||
fontSize = 16.sp,
|
||||
),
|
||||
placeholder = TextStyle(
|
||||
fontFamily = RalewayFontFamily,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
)
|
BIN
presentation/src/main/res/font/playfair.ttf
Normal file
BIN
presentation/src/main/res/font/playfair.ttf
Normal file
Binary file not shown.
BIN
presentation/src/main/res/font/raleway.ttf
Normal file
BIN
presentation/src/main/res/font/raleway.ttf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user