Skip to content

Instantly share code, notes, and snippets.

@BrianGardnerAtl
BrianGardnerAtl / MainActivity.kt
Created May 22, 2020 14:18
Set background color for FAB and correctly set the content color
@Composable
fun AddTweetButton() {
val icon = vectorResource(id = R.drawable.ic_add)
val context = ContextAmbient.current
val color = MaterialTheme.colors.primary
FloatingActionButton(
backgroundColor = color,
contentColor = MaterialTheme.colors.contentColorFor(color),
onClick = {
Toast.makeText(context, "Clicked on FAB", Toast.LENGTH_SHORT).show()
@BrianGardnerAtl
BrianGardnerAtl / Typography.kt
Created May 22, 2020 14:09
Typography class properties
@Immutable
data class Typography internal constructor(
val h1: TextStyle,
val h2: TextStyle,
val h3: TextStyle,
val h4: TextStyle,
val h5: TextStyle,
val h6: TextStyle,
val subtitle1: TextStyle,
val subtitle2: TextStyle,
@BrianGardnerAtl
BrianGardnerAtl / colors.xml
Last active May 22, 2020 14:01
Updated color resources
<resources>
<color name="colorPrimary">#FF5C6BC0</color>
<color name="colorPrimaryDark">#FF5C6BC0</color>
<color name="colorAccent">#FFF06292</color>
</resources>
@BrianGardnerAtl
BrianGardnerAtl / TweetTheme.kt
Created May 22, 2020 13:49
Create custom color palette
@Composable
fun TweetTheme(content: @Composable() () -> Unit) {
val colors = lightColorPalette(
primary = Color(0xFF5C6BC0),
onPrimary = Color(0xFFFFFFFF),
primaryVariant = Color(0xFF8e99f3),
secondary = Color(0xFFF06292),
onSecondary = Color(0xFF000000),
secondaryVariant = Color(0xFFFF94C2),
surface = Color(0xFFFFFFFF),
@BrianGardnerAtl
BrianGardnerAtl / MainActivity.kt
Created May 22, 2020 13:38
Use custom theme in MainActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val tweetList = generateFakeTweetList()
val state = mutableStateOf(tweetList, StructurallyEqual)
setContent {
TweetTheme {
ListScreen(state = state)
}
}
}
@BrianGardnerAtl
BrianGardnerAtl / TweetTheme.kt
Created May 22, 2020 13:36
Create a wrapper around the MaterialTheme
@Composable
fun TweetTheme(content: @Composable() () -> Unit) {
MaterialTheme(content = content)
}
@BrianGardnerAtl
BrianGardnerAtl / TweetTheme.kt
Created May 22, 2020 13:35
Empty custom composable theme
@Composable
fun TweetTheme(content: @Composable() () -> Unit) {
}
@BrianGardnerAtl
BrianGardnerAtl / MainActivity.kt
Created May 22, 2020 13:30
Initial, default theme for my sample app
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val tweetList = generateFakeTweetList()
val state = mutableStateOf(tweetList, StructurallyEqual)
setContent {
MaterialTheme {
ListScreen(state = state)
}
}
}
@BrianGardnerAtl
BrianGardnerAtl / MainActivity.kt
Created May 14, 2020 13:47
Add box to avoid clipping icons with FAB
@Composable
fun TweetBottomBar(
fabConfiguration: BottomAppBar.FabConfiguration?,
homeListener: () -> Unit,
searchListener: () -> Unit,
notificationListener: () -> Unit,
messageListener: () -> Unit
) {
BottomAppBar(
fabConfiguration = fabConfiguration,
@BrianGardnerAtl
BrianGardnerAtl / MainActivity.kt
Created May 14, 2020 13:41
Pass FabConfiguration to TweetBottomBar from Scaffold
@Composable
fun ListScreen(state: MutableState<MutableList<Tweet>>) {
val (scaffoldState, onScaffoldStateChange) = state {
// state contents collapsed
}
Scaffold(
scaffoldState = scaffoldState,
topAppBar = {
// top app bar contents collapsed