Rosen Dimov
08/17/2020, 8:12 AMLazyColumnFor
, because I wanted to migrate an adapter which has two view types (both written in constraint layout). I migrated the XML definition of the CL to the equivalent ConstraintLayout
composable, using createRefs
for describing constraints, and start.linkTo
, top.linkTo
, etc. (part of 0.1.0-dev16 version). Scrolling was very slow, compared to the adapter approach where things are smooth. Here's a gist of the composable.
Here's some relevant code:
The activity which sets the root composable (the list) - grabs first a bunch of data from a Firestore and calls setContent
The list, based on LazyColumnFor
The repeating item - with ConstraintLayout, and with Row and Column
RoundedImage composable - a simple card view with circle shape
The customized button
2 - Have you considered taking an approach similar to JSX in React, something like files with both Kotlin code and some sort of markup for definition of the view itself. Seems like the main drawback of the composables is the nesting of objects that happens in code, and to me at least, it seems more natural to express certain hierarchy of components through a markup language (don't get me wrong, moving to composables in their current state is already a big step, just my thoughts as React dev 😉 )
3 - For beginners like me, is it worth diving deep into things like activities, fragments, navigation in its stable state, lifecycles of fragments/activities, different kind of layouts, etc.? I'll probably not be working on professional Android projects (if I decide to take up mobile dev in my work) by the time stable version of compose is released (in the beginning of 2021, from what I know).
Thanks and have a great day! 🙂Yamila Gammeri
08/17/2020, 8:47 AMJulius Marozas
08/17/2020, 9:49 AMLazyColumnFor
composable?Philip Blandford
08/17/2020, 11:10 AMmattinger
08/17/2020, 6:08 PMmattinger
08/17/2020, 7:55 PMColton Idle
08/17/2020, 7:55 PMamar_1995
08/17/2020, 8:07 PMvar expanded by state { sieveData.first }
var expanded by remember { state { sieveData.first } }
I have seen in some project using the later oneGuy Bieber
08/17/2020, 8:45 PMclass LoginView(
private var dataModel : LoginDataModel
) : Component ()
...
@Composable
override fun view () {
BottomDrawerLayout(
drawerState = dataModel.drawerState,
gesturesEnabled = true,
drawerContent = {
drawerView()
},
bodyContent = {
baseView()
}
)
}
My application model was all defined in one library with @Model.
Now I am trying to move to the recommended porting described in dev12:
class Position(x: Int, y: Int) {
var x by mutableStateOf(x)
var y by mutableStateOf(y)
}
// source of Example is identical to original
@Composable fun Example() {
var p = remember { Position(0, 0) }
PositionChanger(
position=p,
onXChange={ p.x = it }
onYChange={ p.y = it }
)
}
However, if you look at mutableStateOf it says you should use state and stateOf instead.
Then there is a bunch of talk of snapshots. This all leaves me scratching my head wondering how I create a reusable view that can be injected with state. Any good examples, explanations, or other help out there?Daniele B
08/17/2020, 10:22 PMmattinger
08/17/2020, 11:42 PMHalil Ozercan
08/18/2020, 5:20 PMRicardo C.
08/18/2020, 8:33 PMGuy Bieber
08/18/2020, 10:58 PMMarcin Środa
08/19/2020, 7:21 AMMarcin Środa
08/19/2020, 7:24 AMtcracknell
08/19/2020, 5:25 PMchris
08/19/2020, 6:36 PMGuy Bieber
08/19/2020, 6:58 PMGuy Bieber
08/19/2020, 7:49 PM@Composable
override fun GradiantScreen() {
var colors = listOf<Color>(nikolaColors.color2,
nikolaColors.color1)
var gradientBrush = RadialGradient(
colors = colors,
centerX = getScreenWidth().toFloat() / 2.0f,
centerY = getScreenHeight().toFloat() / 2.0f,
radius = getScreenHeight().toFloat() / 2.0f,
tileMode = TileMode.Clamp
)
Box(
Modifier
.drawBackground(brush = gradientBrush)
.fillMaxSize()
)
}
Unfortunately, drawBackground has been deprecated. What is the recommended way to do this with dev17?popalay
08/20/2020, 5:53 AMWilliam Barbosa
08/20/2020, 9:24 AMhttps://user-images.githubusercontent.com/535613/90730646-c2566580-e2c8-11ea-8af1-7aeb1556a860.gif▾
Theo
08/20/2020, 10:42 AMDaniele B
08/20/2020, 3:15 PMGuy Bieber
08/20/2020, 5:52 PMamar_1995
08/20/2020, 6:45 PMcannot be saved using the current UiSavedInstanceStateRegistry. The default implementation only supports types which can be stored inside the Bundle. Please consider implementing a custom Saver for this class and pass it to savedInstanceState() or rememberSavedInstanceState()
farzad
08/20/2020, 8:21 PMMohamed Elfiky
08/21/2020, 9:00 AMLazyColumn(modifier = Modifier.fillMaxWidth()) {
items((0..30).toList()) {
var isExpanded by remember { mutableStateOf(false) }
Surface(
color = MaterialTheme.colors.primary,
shape = CircleShape
) {
Row(modifier = Modifier.animateContentSize()) {
IconButton(onClick = { isExpanded = !isExpanded }) {
Icon(asset = Icons.Default.AccessTime, tint = Color.White)
}
if (isExpanded) {
Text(
modifier = Modifier.gravity(Alignment.CenterVertically)
.padding(end = 16.dp),
text = "some text",
style = MaterialTheme.typography.caption,
color = Color.White
)
}
}
}
Spacer(modifier = Modifier.height(8.dp))
}
}
this code make the icons disappear on scrolling and is very lag, but when i put the animateContentSize on the surface it works but the animation is not like the above one. this code is put in another compose but i extract it to see the problem.Halil Ozercan
08/21/2020, 12:36 PMMehdi Haghgoo
08/21/2020, 1:00 PMvar count = remember {mutableStateOf(0)}
and var count by state {0}
?