Compose - GUI

aNew Application with defined application composable

@Composable
fun SomeGuiApplication(){
    ComposeWorkshopsTheme {
            UserList()
        }
    }
}

@Composable
fun UserList(){
//at this point user repository is hardcoded
    val users=UsersRepository.select() 
    users.forEach{
        Text("User ${it.name} ")
    }
}

change background with surface

ComposeWorkshopsTheme {
        Surface(color = Color.Yellow) {
            UserList()
        }
    }

format user list with column

make text clickable

modifiers order

show difference between

and:

Scaffold

First attempt

Better composition structure

Top Bar

Top Bar Compsable - first variant

Top Bar Composable - Second variant

  • There is a second variant of TopAppBar function and you can not use function syntax with it!

  • to make code more readable you may want to extract some function definitions

    • remember about @Composable annotation before function definitions

    • (to me: during workshops explain topBarActions syntax)

Floating Button

Users List

Extract layout for single user

Bonus : FP and currying

Change data source in "our very sophisticated DI framework"

Lazy Column - First attempt

Lazy Column - Second attempt

Add state to View

(but it doesnt match theory)

in theory scroll state should be stored

Refactor state

Puzzler - when state is created?

still working

so compose actually saves stores default parameters outside "particular method compose"!

Following will not work:

Survive Rotation

First add saver

  • saver doesnt play well with null values!!!!!

then use it in Composable function

  • remember that param name is stateSaver!!!!

Fixing Width

but following is ok:

User "Animation"

This is an example of "a state" which can be stored in composable - view state!

Column manual navigation

To make it work we need to have control over lazy list scroll state

Application theme

Lets return to this one:

at the top of this file you have color pallete definitionns:

and aprticular colors are defined in Color.kt

now using site such like this one : https://www.w3schools.com/colors/colors_palettes.asp

we can define here some general colors

now you can define second "preview annotation" and define colors inside pallette

and use those colors directly in the composables

Last updated

Was this helpful?