Kevin Hester
02/15/2020, 8:16 PMmbonnin
02/15/2020, 8:20 PM@Composable
components ?Bruno_
02/15/2020, 8:41 PMKevin Hester
02/15/2020, 10:04 PMTim Strehlow
02/16/2020, 9:56 PMKevin Hester
02/17/2020, 3:00 AM/**
* A layout modifier that forces a target component to fill all available width.
*
* Example usage:
* @sample androidx.ui.layout.samples.SimpleExpandedWidthModifier
*/
val ExpandedWidth: LayoutModifier = object : LayoutModifier
this is a lot of fun.Kevin Hester
02/17/2020, 3:53 AMitnoles
02/17/2020, 4:37 AMamar_1995
02/17/2020, 10:36 AMERROR: Failed to resolve: androidx.ui:ui-android-view:0.1.0-dev04
Kevin Hester
02/17/2020, 5:49 PMTextField(
value = message.value,
onValueChange = { message.value = it },
textStyle = TextStyle(
color = colors.onSecondary.copy(alpha = 0.8f)
),
imeAction = ImeAction.Send,
onImeActionPerformed = {
<http://MessagesState.info|MessagesState.info>("did IME action")
},
modifier = LayoutPadding(4.dp)
)
Kevin Hester
02/17/2020, 6:33 PMModifier elements may be combined using `+` Order is significant; modifier elements to the left
* are applied before modifier elements to the right.
Does the last applied operator override previous modifers of the same type? i.e.
if I have something like
lA = LayoutSize(...)
lB = LayoutSize(...)
modifer = lA + lB
Is this doc saying that lB will be the layout size for the modifier?Kevin Hester
02/17/2020, 6:49 PMText(
text = "9:49 AM",
modifier = LayoutPadding(left = 8.dp),
style = MaterialTheme.typography().caption.merge(
TextStyle(
color = palette.onSecondary.copy(
alpha = 0.2f
)
)
)
)
If so, what about letting TextStyles have an + operator to make their usage more similar to Modifiers?Kevin Hester
02/17/2020, 8:43 PMfun MessagesContent() {
Column(modifier = LayoutSize.Fill) { // want to fill entire screen
Column(modifier = LayoutSize.Fill) {
messages.value.forEach { // I want this list of messages to fill most of the view
MessageCard(
it, modifier = LayoutPadding(
left = sidePad,
right = sidePad,
top = topPad,
bottom = topPad
)
)
}
}
Surface(
modifier = LayoutPadding(8.dp) + LayoutSize.Min(40.dp, 40.dp),
color = backgroundColor,
shape = RoundedCornerShape(4.dp)
) {
TextField(
...
)
}
}
}
Klaas Kabini
02/18/2020, 5:54 AMkyleg
02/18/2020, 8:54 PM…, style=+textThemeStyle
but cannot for the life of me figure out what textThemeStyle
is. There’s a Github project I found that suggests it’s in androidx.ui.material
but I don’t see it there for me. Probably something that was removed/deprecated-and-removed. What is it replaced by?
I have one of my Composable
functions wrapping a Scaffold
with CustomTheme
, and inside there I want to style a Text
with a Typography
defined inside the CustomTheme
.Rodrigo Fonseca
02/18/2020, 9:28 PMspierce7
02/18/2020, 10:56 PMSrSouza
02/18/2020, 11:42 PMkyleg
02/19/2020, 6:04 AMFlex.kt
, part of androidx.ui.layout
the doc comment block above fun Column
says @sample androidx.ui.layout.samples.SimpleColumn
, but I cannot locate that in the package or the source or anywhere googling that string.ahulyk
02/19/2020, 10:01 AMamar_1995
02/19/2020, 11:32 AMjava.lang.IllegalStateException: Current layout is not an ancestor of the provided child layout
Note: It is occuring only sometime and most of time it is working with no issueVitor Prado
02/19/2020, 7:45 PMtcracknell
02/19/2020, 9:22 PMKlaas Kabini
02/20/2020, 12:30 PMahulyk
02/20/2020, 4:02 PMKlaas Kabini
02/20/2020, 7:12 PM@Model
annotation will make the count property inside the LabelState
data class observable which in turn gives it the ability to trigger recompositions on subsequent mutations.
@Model
data class LabelState(var count:Int)
Sample 1:
Composable functions are positionally memoized meaning the inputs to composable functions, and their corresponding outcome resulting from composable functions calls are cached to avoid unneccessary recompositions when a composable function is called with the same inputs multiple times. In case where a composable function is called with the same inputs multiple times, compose runtime will check against the Slot table whether the same inputs have corresponding outputs that were previously cached. If yes, then the compose runtime will retrieve the previously cached results otherwise insert new inputs and their corresponding results to the Slot Table.
Given that understanding, it means that the LabelState
passed as input parameter to a composable in the following code snippet will be positionally memoized despite that is is not wrapped inside remember
composable. Did I understood this correctly? If yes, then is this only applicable to situations where the state is hoisted? - in other words passed down the composable hierarchy from the owner to called composable functions?
@Composable
fun LabelThatPassStateAsParameter(labelState: LabelState){
Text(text = "$labelState.count",
style = MaterialTheme.typography().body1)
}
Sample 2
Alternatively, when the state is not passed as input to composable function, it can be obtained by a keeping a local variable that references the state by calling composable function such as state
or a combination of @Model
class wrapped inside remember
composable as in code snippet below. val labelState = state {0}
is equivalent to val labelState = remember { mutableStateOf(0) }
where both does referential equality between old and new value to prior to mutation of state.
@Composable
fun LabelWithStateComposableThatDoesReferentialEquality(){
val labelState = state {0}
Text(text = "$labelState.count",
style = MaterialTheme.typography().body1)
}
Otherwise if you want to do structural equality on state mutations, you can possible achieve by through the following.
val labelState2 = remember { LabelState(0) }
is equivalent to val labelState2 = remember { mutableStateOf(value = 0, areEquivalent = StructurallyEqual) }
where both does structural equality between old and new value to prior to mutation of old state value.Klaas Kabini
02/20/2020, 7:46 PMKevin Hester
02/20/2020, 10:29 PMpula
02/20/2020, 11:31 PME/TestRunner: java.lang.RuntimeException: Could not launch activity
when I attempt to use createComposeRule()
. or am I trying to use something that isn’t ready?
@RunWith(JUnit4::class)
class SampleTests {
@get:Rule
val composeTestRule = createComposeRule(disableTransitions = true)
@Test
fun twoComponents_areChecked() {
composeTestRule.setContent {
MaterialTheme {
Surface {
Column {
Checkbox(checked = true, onCheckedChange = null)
Checkbox(checked = true, onCheckedChange = null)
}
}
}
}
findAll(isOn())
.assertCountEquals(2)
.forEach {
it.assertIsOn()
}
}
}
Thierry
02/21/2020, 12:10 AM