Tobias Gronbach
03/16/2022, 12:47 PMFilip Wiesner
03/16/2022, 12:51 PMTobias Gronbach
03/16/2022, 1:00 PMFilip Wiesner
03/16/2022, 1:03 PMSubScreen1
part of the MainScreenComposable
?Tobias Gronbach
03/16/2022, 1:03 PMFilip Wiesner
03/16/2022, 1:05 PMMainScreenComposable {
Surface {
Text() // Is black
SubScreen1 {
Text() // Is White
}
}
}
Tobias Gronbach
03/16/2022, 1:07 PMMainScreenComposable {
Surface {
Text() // Is white
SubScreen1 {
Text() // Is black
}
}
}
yeah the colors are the other way round, but yeahFilip Wiesner
03/16/2022, 1:10 PMSubScreen1
if it set's content color of some material component or if it sets LocalContentColor
composition local.
To explain, LocalContentColor
is used for the behavior you described. It informs the children of the component that sets it that the current content color is white or black or whatever. The Text
composable than uses this information to color itselfFilip Wiesner
03/16/2022, 1:12 PMSubScreen1
Tobias Gronbach
03/16/2022, 1:14 PM@Composable
fun AdviceCustomQuote(bait: AdviceBait) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Image(
modifier = Modifier.fillMaxSize(),
imageVector = ImageVector.vectorResource(R.drawable.ic_quote_background),
contentDescription = stringResource(R.string.cd_background_image)
)
Column {
Text(
modifier = Modifier.fillMaxWidth().padding(30.dp, 0.dp, 24.dp, 30.dp),
text = bait.content,
fontSize = 40.sp,
fontFamily = DancingScriptFont,
textAlign = TextAlign.Center
)
Text(
modifier = Modifier.fillMaxWidth().padding(30.dp, 0.dp, 24.dp, 0.dp),
text = bait.author,
textAlign = TextAlign.Center
)
}
}
}
Filip Wiesner
03/16/2022, 1:17 PMText
composables inside the column have different color than Text
outside of AdviceCustomQuote
, right?Tobias Gronbach
03/16/2022, 1:17 PMFilip Wiesner
03/16/2022, 1:17 PMTobias Gronbach
03/16/2022, 1:18 PMFilip Wiesner
03/16/2022, 1:19 PMLocalContentColor
. Like Scaffold
or Surface
or Card
or anyhting like that above this AdviceCustomQuote
componentTobias Gronbach
03/16/2022, 1:21 PMoverride fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return ComposeView(requireContext()).apply {
setContent {
val adviceBait = viewModel.adviceBait
AppTheme(theme = Theme.Standard) {
Surface(
color = colorResource(viewModel.adviceBait?.adviceType?.colorRes()
?: R.color.theme1_background_white1).copy(alpha = 0.7f)
) {
when (viewModel.adviceBait?.adviceType) {
AdviceType.Quote -> {
adviceBait?.let {
AdviceCustomQuote(bait = it)
}
}
else -> {
}
}
}
}
}
}
}
}
Tobias Gronbach
03/16/2022, 1:21 PMFilip Wiesner
03/16/2022, 1:23 PMText
composable right above the when
, it would be white but text inside AdviceCustomQuote
is black.Tobias Gronbach
03/16/2022, 1:23 PMTobias Gronbach
03/16/2022, 1:27 PMFilip Wiesner
03/16/2022, 1:27 PMCompositionLocalProvider
like this
val color = colorResource(viewModel.adviceBait?.adviceType?.colorRes()
?: R.color.theme1_background_white1).copy(alpha = 0.7f)
CompositionLocalProvider(LocalContentColor provides color) {
// AdviceCustomQuote content
}
But this seems really strange 😕Filip Wiesner
03/16/2022, 1:27 PMFilip Wiesner
03/16/2022, 1:28 PMTobias Gronbach
03/16/2022, 1:28 PM