Stylianos Gakis
08/10/2022, 7:47 AMTin Tran
08/10/2022, 8:44 AM@Stable
class Foo {
var fieldA: Boolean by mutableStateOf(false)
}
nlindberg
08/10/2022, 11:07 AMAmrJyniat
08/10/2022, 1:07 PMKotlinLeaner
08/10/2022, 2:56 PMdimsuz
08/10/2022, 3:08 PMval state = rememberNiceState(itemPositions: Positions.Stage0)
NiceContainer(
itemCount = 3,
state: NiceState = state,
itemContent = { index -> MyItem(index) }
)
LaunchedEffect(Unit) {
state.animateItems(Positions.Stage1)
}
The problem is that to calculate an (x,y) of each item given the "stage" I need to know the itemsCount
: both in State consctructor and in animateItems
.
I could make itemCount
private val in State, but I do not want to require user to pass itemsCount
both to NiceContainer
composable and to State constructor, this feels weird. Similarly passing itemCount
only to State constructor and removing it from NiceContainer
argument list feels not like something you do in other composable container layouts... Any suggestions?Alejandro Rios
08/10/2022, 3:52 PM@Preview
does not work in libraries, I am creating a library of components for my project, but the previews do not load, one of the proposed "solutions" was to include androidx.appcompat:appcompat
in the library, I did it but it still does not work, do you know anything about it?Emmanuel
08/10/2022, 6:30 PMMyComponent(
input1...,
inputN,
event1...,
eventN
)
Jaime
08/10/2022, 6:34 PMColton Idle
08/10/2022, 7:02 PM@Stable
in any of my codebases. 🙈
Am I missing something basic here? Should I be marking classes as stable?aoriani
08/10/2022, 7:47 PMBasicTextField
and its onValueChanged
parameter to filter out any non-digit character. However, reading the documentation I found this :
Please keep in mind thatDoes that mean that something likeis useful to be informed about the latest state of the text input by users, however it is generally not recommended to modify the value that you get viaonValueChange
callback. Any change to this value may result in a context reset and end up with input session restart. Such a scenario would cause glitches in the UI or text input experience for users.onValueChange
var text by rememberSaveable { mutableStateOf("") }
BasicTextField(
value = text,
onValueChange = { input ->
text = input.filter { it.isDigit() }.take(5)
}
)
could be a problem because I am not passing input
as is to value
?Jaime
08/10/2022, 10:18 PMisSystemInDarkTheme()
I am adding it to the theme but sometimes it returns true after false
2022-08-10 17:12:22.215 6489-6489/ E/isSystemInDarkTheme: true darkMode
2022-08-10 17:12:23.338 6489-6489/ E/isSystemInDarkTheme: true darkMode
2022-08-10 17:12:24.478 6489-6489/ E/isSystemInDarkTheme: false darkMode
2022-08-10 17:12:30.008 6489-6489/ E/isSystemInDarkTheme: false darkMode
2022-08-10 17:12:30.697 6489-6489/ E/isSystemInDarkTheme: false darkMode
@Composable
fun Theme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}
ProvideHapiColors(colors) {
MaterialTheme(
colors = if (darkTheme) darkColors() else lightColors(),
typography = Typography,
shapes = Shapes,
content = content
)
}
}
Colton Idle
08/11/2022, 2:47 AMCrossfade
, animateAsState
and Animatable
for tooling label
• Added atFraction
function for defining keyframes at a fraction instead of at a specific duration.
• Resource Fonts now support setting font variation settings (API 26+).
• Variable font support in DeviceFontFamilyNameFont
• Text fields will now throw more detailed exceptions when the OffsetMapping
provided by a VisualTransformation
returns invalid indices.
• Introduce experimental APIs to share item provider logic between Lazy layouts. 🤔
• Deprecate TextInputService.show|hideSoftwareKeyboard
. Please use SoftwareKeyboardController
instead in app code and TextInputSession
in IME-management code
• LayoutCoordinates.findRootCoordinates()
is now public
• Added experimental API to get the LayoutCoordinates
in the PlacementScope
. This lets developers know where the current layout is to place children relative to its position
• Paragraph is now expect|actual and defined for Android and Desktop.
• Added @RequiresPermission
to APIs that require granting the POST_NOTIFICATIONS
permission on SDK 33 and above.
material 3
• 1.0.0-alpha16
• Support specifying a custom width on a navigation drawer
• Removes Divider
from MenuDefaults
and TabDefaults
vide
08/11/2022, 7:30 AMYou should defer reading state variables as long as possible. Deferring state reads can help ensure that Compose re-runs the minimum possible code on recomposition. For example, if your UI has state that is hoisted high up in the composable tree and you read the state in a child composable, you can wrap the state read in a lambda function. Doing this makes the read occur only when it is actually needed.All other documentation and examples seem to prefer passing only immutable data classes for state -- is this deferring technique recommended only for the most intensive cases (for example animations with values changing every frame)? To my understanding, when a value changes, the whole scope that read it is recomposed, including all child composables (unless the inputs are @Stable in which case all of the inputs will be diffed and recomposed only if the inputs are different). What is the downside of doing deferred reads and passing
State
, how much overhead does it add compared to diffing all parameters of invalidated child composables in a large invalidated scope?
Also, does it matter how the state read is deferred? I have preferred not to use the delegate syntax for mutableStateOf so I can easily pass State<T>
objects directly to child composables. Is there some reason why the provided example uses a callback and not something like this: @Composable fun Child(state: State<T>) { state.value }
?Napa Ram
08/11/2022, 7:41 AMAmrJyniat
08/11/2022, 7:52 AMViewCompositionStrategy
to the ComposeView from the XML?Asad Mukhtar
08/11/2022, 8:21 AMColumn(
modifier = Modifier
.fillMaxSize(1f)
.background(color = Color.White)
.verticalScroll(state = rememberScrollState(),
) {
HeaderSection("Welcome!", "It's great to have you here") {
viewModel.events.postValue(AuthModuleClickEventsObject.BACK_CLICK)
}
ContentSection(
modifier = Modifier
.background(
color = Color(0xFFF3F6F9),
shape = RoundedCornerShape(topStart = 34.dp, topEnd = 34.dp)
)
.fillMaxWidth()
.fillMaxHeight()
.padding(horizontal = 17.5.dp),
{}, {
viewModel.events.postValue(AuthModuleClickEventsObject.FORGOT_PASSWORD_CLICK_EVENT)
})
}
natario1
08/11/2022, 10:12 AMAsad Mukhtar
08/11/2022, 10:40 AMZoltan Demant
08/11/2022, 11:06 AMrestartable skippable scheme("[androidx.compose.ui.UiComposable]") fun BottomBar(
unstable pages: List<ExplorePage>
stable currentPage: ExplorePage
)
harry.singh
08/11/2022, 2:07 PMColumn
overlapped by a LazyList
(trying to implement a nested scroll) and I was wondering if there's a way to pass click events to the Column
beneath and scroll events be handled by the LazyList
itself. I want to preferably do this only for the first item in the list. Is something could be done in Compose today?Lukasz Kalnik
08/11/2022, 2:19 PMnavigate()
2. Pass navigation arguments (like item IDs) in a typesafe manner
3. Automatically generate the route URIs with argument placeholders
4. Easily extract the navigation arguments without additional boilerplate
I'm writing extension functions and sealed class hierarchies/enums for this, but this is such a common use case that maybe someone already came up with a library (or at least someone of you has good suggestions).Richard Steventon
08/11/2022, 3:00 PMArrangement.spacedBy
and Arrangement.SpaceBetween
?John Nichol
08/11/2022, 3:39 PMRick Regan
08/11/2022, 5:20 PMNavHost
where each composable {}
contains a Composable function that is passed State representing the app’s settings (the State’s value actually, originating as by mutableStateOf
above NavHost
). I decided to separate out all the settings screens into a subgraph (same module) using an extension function called NavGraphBuilder.settingsNavGraph
. In order to get the state to continue to track in the screens now moved into the subgraph, I pass a lambda to settingsNavGraph
that reads the .value
of the settings. (Locally, just above the NavHost
call, I declared val settingsAsState = rememberUpdatedState(settings)
in order to set this up.)
This seems to work well, but I wanted to know if it was OK to do so, or if there is a better way. (The Compose Owl sample app does something similar, passing a State<>
to the extension function – but it looks like it is the only sample app that does this.)Tiago Nunes
08/11/2022, 5:50 PMnavigation-animation
:
When I interrupt the transition to another screen by pressing the back button, the animation gets bugged (List screen moves up a bit).
I found this issue tracker link, which is probably the cause: AnimatedContent sets incorrect target animation on interrupt
Has this ever happen to any of you, and is there a solution?
In the video, you can see the expected behaviour happening in the second attempt, and the bug happens in the first and third attempts.Jose Carlos Hernandez
08/11/2022, 6:21 PMval isButtonEnabled: StateFlow<Boolean> =
combine(isLoading, login, password) { isLoading, login, password ->
isLoading.not() && login.isNotBlank() && password.isNotBlank()
}.stateIn(viewModelScope, SharingStarted.Eagerly, false)
But I only have 1 field instead to validate so I try to put it like this
val isContinueEnable: StateFlow<Boolean> = MutableStateFlow(login.value.isNotBlank())
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
but when I start typing on the TextField it doesn’t change de value to true
so is there a method similar to combine
to get Flow
but just with one element?zsperske
08/11/2022, 9:14 PMLocale
make sense as a composition local? How do y’all handle things like uppercase()
which accepts a locale argument?Mohan manu
08/12/2022, 4:18 AMChristoph Wiesner
08/12/2022, 8:12 AMNavHost(navController, startDestination = "home") {
composable("home") {
Home(/* uses viewModel by hiltViewModel() */)
}
subGraph()
}
fun NavGraphBuilder.subGraph() {
composable("subDestination") {
MyComposable()
}
}
fun MyComposable(
viewModel by hiltViewModel(/* Home backstackEntry ?*/)
)
I want to share VM between the “Home” and the nested destination in the subgraph.
I’m not passing down the navController to nested graphs to avoid dependencies to navigation in there.
Is there a way I get the home backStackEntry for my nested destination still without quering it in place?
Passing the entry down from top level does not work as when building the graph intially there is not yet a backStackEntry to queryChristoph Wiesner
08/12/2022, 8:12 AMNavHost(navController, startDestination = "home") {
composable("home") {
Home(/* uses viewModel by hiltViewModel() */)
}
subGraph()
}
fun NavGraphBuilder.subGraph() {
composable("subDestination") {
MyComposable()
}
}
fun MyComposable(
viewModel by hiltViewModel(/* Home backstackEntry ?*/)
)
I want to share VM between the “Home” and the nested destination in the subgraph.
I’m not passing down the navController to nested graphs to avoid dependencies to navigation in there.
Is there a way I get the home backStackEntry for my nested destination still without quering it in place?
Passing the entry down from top level does not work as when building the graph intially there is not yet a backStackEntry to query@Composable
fun NestedDestinationComposable(
backStackEntry: NavBackStackEntry,
vm: MyViewModel = hiltViewModel(backStackEntry))
the nested navgraph has a callback to get the actual backStackEntry
NavGraphBuilder.goalNavGraph(
getSharedBackStackEntry: () -> NavBackStackEntry,) {
composable() {
NestedNavComposable(
remember { getSharedBackStackEntry()}
)
}
}
the top level navgraph
NavHost(
navController,
startDestination = "Home"
) {
composable("Home") {
HomeScreen()
}
subGraph(
getSharedBackStackEntry = { navController.getBackStackEntry("Home") },
...
)
}