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.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.nto.presentation.theme.NTOTheme
|
||||||
import com.nto.presentation.theme.OnomatopoeiafrontTheme
|
import com.nto.presentation.theme.OnomatopoeiafrontTheme
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
@ -17,9 +19,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
OnomatopoeiafrontTheme {
|
NTOTheme {
|
||||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||||
|
//TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,52 @@
|
|||||||
package com.nto.presentation.theme
|
package com.nto.presentation.theme
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
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 TextGray = Color(0xFFC4BBC7)
|
||||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
val BoxGray = Color(0xFFF8F0FB)
|
||||||
val Pink80 = Color(0xFFEFB8C8)
|
val Green = Color(0xFF738D73)
|
||||||
|
val GreenDisabled = Color(0xFFCAD5CA)
|
||||||
|
|
||||||
val Purple40 = Color(0xFF6650a4)
|
@Immutable
|
||||||
val PurpleGrey40 = Color(0xFF625b71)
|
data class AppColors(
|
||||||
val Pink40 = Color(0xFF7D5260)
|
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
|
package com.nto.presentation.theme
|
||||||
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
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.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
|
||||||
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),
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OnomatopoeiafrontTheme(
|
fun NTOTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
|
||||||
// Dynamic color is available on Android 12+
|
|
||||||
dynamicColor: Boolean = true,
|
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
val colorScheme = when {
|
CompositionLocalProvider(
|
||||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
LocalAppColors provides extendedColor,
|
||||||
val context = LocalContext.current
|
LocalAppTypography provides extendedTypography
|
||||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
) {
|
||||||
}
|
MaterialTheme(
|
||||||
|
content = content
|
||||||
darkTheme -> DarkColorScheme
|
)
|
||||||
else -> LightColorScheme
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
MaterialTheme(
|
|
||||||
colorScheme = colorScheme,
|
object NTOTheme {
|
||||||
typography = Typography,
|
val colors: AppColors
|
||||||
content = content
|
@Composable get() = LocalAppColors.current
|
||||||
)
|
|
||||||
|
val typography: AppTypography
|
||||||
|
@Composable get() = LocalAppTypography.current
|
||||||
}
|
}
|
@ -1,34 +1,51 @@
|
|||||||
package com.nto.presentation.theme
|
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.TextStyle
|
||||||
|
import androidx.compose.ui.text.font.Font
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.nto.presentation.R
|
||||||
|
|
||||||
// Set of Material typography styles to start with
|
private val RalewayFontFamily = FontFamily(
|
||||||
val Typography = Typography(
|
Font(R.font.raleway)
|
||||||
bodyLarge = TextStyle(
|
)
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Normal,
|
private val PlayfairFontFamily = FontFamily(
|
||||||
fontSize = 16.sp,
|
Font(R.font.playfair)
|
||||||
lineHeight = 24.sp,
|
)
|
||||||
letterSpacing = 0.5.sp
|
|
||||||
)
|
@Immutable
|
||||||
/* Other default text styles to override
|
data class AppTypography(
|
||||||
titleLarge = TextStyle(
|
val titleLarge: TextStyle,
|
||||||
fontFamily = FontFamily.Default,
|
val displaySmall: TextStyle,
|
||||||
fontWeight = FontWeight.Normal,
|
val placeholder: TextStyle
|
||||||
fontSize = 22.sp,
|
)
|
||||||
lineHeight = 28.sp,
|
|
||||||
letterSpacing = 0.sp
|
@SuppressLint("ComposeCompositionLocalUsage")
|
||||||
),
|
val LocalAppTypography = staticCompositionLocalOf {
|
||||||
labelSmall = TextStyle(
|
AppTypography(
|
||||||
fontFamily = FontFamily.Default,
|
titleLarge = TextStyle.Default,
|
||||||
fontWeight = FontWeight.Medium,
|
displaySmall = TextStyle.Default,
|
||||||
fontSize = 11.sp,
|
placeholder = TextStyle.Default
|
||||||
lineHeight = 16.sp,
|
)
|
||||||
letterSpacing = 0.5.sp
|
}
|
||||||
)
|
|
||||||
*/
|
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