Tuba Kesten
01/28/2021, 6:26 PMLoginViewModel() {
private val _sessionUser = MutableLiveData<SessionUser>()
val sessionUser: LiveData<SessionUser>
get() = _sessionUser
fun changeSessionUserValue() {
_sessionUser.value = ....
}
}
@composable
OuterComposable(){
val currentSessionUser: SessionUser? by loginViewModel.sessionUser.observeAsState()
Timber.d("Heyyooo!")
NavHost(...) {
....,
composable(route) { InnerComposable(loginViewModel) }
}
....
}
@composable
InnerComposable(loginViewModel) {
....
NavHost(...) {
....,
composable(rt) { InnerInnerComposable(loginViewModel) }
}
}
@composable
InnerInnerComposable(loginViewModel) {
Button(onClick = loginViewModel.changeSessionUserValue())
}
Hi guys, I have a question related to observing mutable live data. When the activity created, outerComposable is called and "Heyyooo!"
is logged. After, the user clicks to the button in InnerInnerComposable, changeSessionUserValue is called. However the observed sessionUser in OuterComposable is not triggered so that Heyyooo!
is not logged on screen again after button click. Any idea why I can't trigger observeAsState
? Thanks🤗rsktash
01/28/2021, 7:22 PMalorma
01/28/2021, 7:48 PMDuplicate class androidx.compose.animation.AlignmentBasedSizeAnimation found in modules animation-1.0.0-alpha11-runtime (androidx.compose.animation:animation:1.0.0-alpha11) and animation-debug-runtime (org.jetbrains.compose.animation:animation-android-debug:0.3.0-build141)
????rsktash
01/28/2021, 8:28 PMDaniele B
01/28/2021, 9:37 PMDoris Liu
01/29/2021, 12:57 AMtransitionDefinition
based transitions have been deprecated in alpha 11. The replacements are: updateTransition and rememberInfiniteTransition for the finite and infinite use cases, respectively. I know it's a large amount of API change. 😅 Hopefully, the new API is more straightforward to use. If you have any questions about them, or any issue with your migration, please let me know. I'm happy to help. 🙂Jason Ankers
01/29/2021, 3:52 AM1.0.0-alpha11
? Previously was doing:
vectorResource(R.drawable.ic_target).copy(defaultHeight = 18.dp, defaultWidth = 18.dp)
Alexa_Gal
01/29/2021, 4:04 AMorg.jetbrains.kotlin.ir.expressions.impl.IrCallImpl@1240ed89: No such type argument slot: 1
?Arkadii Ivanov
01/29/2021, 11:28 AMonCommit(Unit) {}
and onActive {}
.Marko Novakovic
01/29/2021, 1:14 PMViewModel
as it is, for surviving configuration change isn’t really needed in Compose
. Right? Compose
has it’s own by saveInstanceState
. do we still use ViewModel
as we have been using it until now?Daniele B
01/29/2021, 1:37 PMScrollableColumn
(which is now deprecated) with
Column(modifier = Modifier.verticalScroll(rememberScrollState())
but Column
doesn’t have the contentPadding
parameter, so when using Scaffold
with a BottomBar
, the bottom part of the column gets covered by the bottombar.
Any solution?julioromano
01/29/2021, 2:09 PMBasicTextField
and an IconButton
, I’d like to give focus to the text field (and therefore have the on screen keyboard appear) at the press of the button.
Which API should I use?Vitor Prado
01/29/2021, 5:41 PMAlexa_Gal
01/29/2021, 6:33 PMauthMethod
)
viewModel.authMethod.onEach {
Log.e("i'm here", "yes im here ${it}")
}.collect()
this will be trigger the first time and every time after i change the value on the viewModel.
my issue is that when i push new view (using Navigation alpha06
) and i pop back the onEach
will be triggered again. How could i only tell authMethod
to be triggered only on changes and not every-time the compose is rendering ?🌈
With liveData i had the observable that only triggers on changes, but i can not find the equivalent on StateFlow :/Jordi Saumell
01/29/2021, 6:36 PMZach Klippenstein (he/him) [MOD]
01/29/2021, 7:20 PMdata class
from {list of types}” in alpha11 – what’s the reason for this purge? I know data classes are bad for library binary compatibility, is that it?Neal Sanche
01/29/2021, 7:36 PMBottomNavigation
with a height that also includes the navigation bar height, so that the BottomNavigation
paints all the way to the bottom of the screen. I have tried all sorts of things, and just end up with a space underneath the bottom nav. I sort of want this effect without having to resort to making a column with a spacer at the bottom. Here's the code I have so far within my Scaffold
bottomBar = {
Column(Modifier.background(MaterialTheme.colors.primary)) {
BottomNavigation(
elevation = 0.dp,
backgroundColor = MaterialTheme.colors.primary,
contentColor = contentColorFor(MaterialTheme.colors.primary),
) {
bottomNavItems.forEach { screen ->
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute =
navBackStackEntry?.arguments?.getString(KEY_ROUTE)
?: Screen.Profile.route
BottomNavigationItem(
icon = { Icon(imageVector = screen.icon, contentDescription = null) },
label = { Text(stringResource(screen.resourceId)) },
selected = currentRoute == screen.route,
onClick = {
navController.navigate(screen.route) {
popUpTo = navController.graph.startDestination
launchSingleTop = true
}
}
)
}
}
Spacer(Modifier.navigationBarsHeight())
}
}
Tony Kazanjian
01/29/2021, 9:46 PMScrollableColumn
to display a list of a set number of items, i.e.:
ScrollableColumn(modifier.padding(bottom = 56.dp)) {
collections.forEach {
ProductCollection(collection = it)
}
}
The ProductCollection
essentially contains a composable that is a LazyRow
for showing LazyPagingItems
@Composable
fun ProductItemListWithId(
collectionId: Int,
modifier: Modifier = Modifier,
content: @Composable LazyItemScope.(ProductItem) -> Unit){
val viewModel: ProductListViewModel = getViewModel()
val products = viewModel.getPagingFlowForCollection(collectionId).collectAsLazyPagingItems()
LazyRow{
items(products){
product -> product?.let { content(it) }
}
}
}
ScrollableColumn
has been deprecated now, but it's only the row items that I want lazy loaded. Trying to use a LazyColumn
a la :
LazyColumn(
modifier = modifier.padding(bottom = 56.dp)) {
item {
collections.forEach {
ProductCollection(it)
}
}
}
Results in the row items not always getting loaded since they are coming from a Flow<PagingData>
that is fired lazily. What can I do to work around this, or to just simply make a normal Column
scrollable again in Alpha 11?Jordi Saumell
01/29/2021, 9:55 PMJan Skrasek
01/29/2021, 11:45 PMerror: @Composable (() -> Unit)? = null
i.e. a rendering lambda of the error or a null.
I want to animate that rendering, so I need to postpone "nulling" the error until the hide animation finishes. How can I remember the composable result?
Box(
modifier = Modifier
.alpha(errorAlpha.value)
) {
if (error != null) {
error()
}
}
Alexa_Gal
01/30/2021, 1:55 AMHello word
Compose A navigates to Component B
Component B popsBack to Component A
Component A should not print again “Hello word” since this was already on the stack
@Composable
fun ComponentA() {
LaunchedEffect(Unit) {
Log.e("=======", "I need to run only once and not when other Component PopsBack")
}
Button("Continue", onClick = {
navController.navigate("ComponentB")
})
}
carbaj0
01/30/2021, 6:52 AMfun Icon(
imageVector: ImageVector,
contentDescription: String? = null,
modifier: Modifier = Modifier,
tint: Color = AmbientContentColor.current.copy(alpha = AmbientContentAlpha.current)
) { ... }
Manuel Lorenzo
01/30/2021, 9:48 AMRafs
01/30/2021, 10:56 AMfitSystemWindows
in composeShakil Karim
01/30/2021, 11:48 AMDenis
01/30/2021, 12:18 PMTextDelegate
? There was a similar question before [1]. I want to render some text matching a particular width. I used code from [2], but can't make it work.
@Preview
@Composable
fun TextAutoSize() {
class TestFontResourceLoader(val context: Context) : Font.ResourceLoader {
override fun load(font: Font): android.graphics.Typeface {
return when (font) {
is ResourceFont -> ResourcesCompat.getFont(context, font.resId)!!
else -> throw IllegalArgumentException("Unknown font type: $font")
}
}
}
val textDelegate = TextDelegate(
text = AnnotatedString("Hello, World"),
style = TextStyle.Default,
maxLines = 1,
density = Density(density = 1f),
resourceLoader = TestFontResourceLoader(AmbientContext.current),
)
val layoutResult = textDelegate.layout(Constraints.fixedWidth(1000), LayoutDirection.Ltr)
Canvas(Modifier.fillMaxWidth().height(50.dp)) { // CanvasScope
drawIntoCanvas {
TextDelegate.paint(canvas = it, layoutResult)
}
}
}
[1] https://kotlinlang.slack.com/archives/CJLTWPH7S/p1611055679272900
[2] https://github.com/androidx/androidx/blob/androidx-main/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/TextFieldDelegateIntegrationTest.ktorangy
Ayomide
01/30/2021, 2:50 PMFile
composables that are created as "children" of a FilePane
composable. Which means I have to hoist the same onClick
callback to all of them. But how would I get a name like Hello.java
from the onClick
function that is given to all the buttons in the image when the Hello.java
button is clicked? I feel like I am modelling this wrong, since composables should largely be stateless, except for the top level composableKshitij Patil
01/30/2021, 4:40 PMval fieldFocus = remember { FocusRequester() }
LaunchedEffect(key1 = Unit) {
addressFocus.requestFocus()
}
Nat Strangerweather
01/30/2021, 7:21 PMScaffold(
scaffoldState = scaffoldState,
drawerContent = {
HomePageDrawer()
},
For HomePageDrawer() I get : "No value passed for parameter 'navController'". What am I supposed to put for parameter navController? Whatever I try gives me a nullpointer... Basically I have some items in my drawer and I want to navigate to other screens from them...