julioromano
01/26/2022, 8:04 PMlifecycle-viewmodel:2.5.0-alpha01
I’m getting compile errors on classes that inherit from `ViewModelProvider.Factory`:
Inheritance from an interface with ‘@JvmDefault’ members is only allowed with -Xjvm-default optionI’ve tried fiddling all
-Xjvm-default=xxxxx
options but the error does not go away.
Anyone had the same trouble?Slackbot
01/26/2022, 9:08 PMOlivier Patry
01/26/2022, 10:21 PMMaterialTheme
open properties but if I want to customize more, I'm stuck.
For instance, I'd like to tweak the width of the `OutlinedButton`'s border and potentially its color.
The only thing I can think of so far is to redefine my own MyAppButton
tweaking what's needed (by calling built-in button composable or not, impl detail here).
Can't we have ways to override ButtonDefaults
? (using opened var
instead of val
or LocalButtonDefaults
or something like that).
I have the feeling that redefining custom buttons make composable less reusable and tightly coupled to custom composable rather than provided theming.Lilly
01/27/2022, 1:28 AMAbhishek Dewan
01/27/2022, 6:58 AMMikael Alfredsson
01/27/2022, 8:26 AMLokik Soni
01/27/2022, 8:42 AMAshu
01/27/2022, 10:17 AMFanilog
01/27/2022, 12:13 PMON_DESTROY
state however if I’m doing the classic back the lifecycle stop at ON_STOP
and never reach the ON_DESTROY
natario1
01/27/2022, 12:27 PMLazyListState.isScrollInProgress
was triggered by user or not?
Documentation says "Whether this ScrollableState is currently scrolling by gesture, fling or programmatically". I think I can use InteractionSource
to catch drags, but it would not cover flinging and maybe some other user-initiated scrolls.Gerardo Ernesto Rodriguez Navar
01/27/2022, 1:05 PMCasey Brooks
01/27/2022, 4:56 PMNick
01/27/2022, 5:06 PMFlowRow
that contains the `Chip`s for each user, with a TextField
that will fill remaining width?
How would I get the TextField
to fill the remaining width in the row while also having a minWidth?Simon Stahl
01/27/2022, 7:35 PMbrabo-hi
01/27/2022, 11:27 PM<https://developer.android.com/guide/navigation/navigation-pass-data#supported_argument_types>
navigation can accept a nullable string as parameter. Should we ignore the null argument ?Andrew Hughes
01/28/2022, 12:45 AMTash
01/28/2022, 2:11 AMhas no zero argument constructor
runtime error when using androidx.lifecycle.viewmodel.compose.viewModel()
🧵Oleksandr Balan
01/28/2022, 9:49 AMalorma
01/28/2022, 11:45 AMSurface
and Text
inside it, text is in a Row
, centered both horizontal and vertical.
We see a small pixel.. difference, as it should be on the center, and we see here that text is a bit under the center..
Any idea?rudolf.hladik
01/28/2022, 1:08 PMstickyHeader
not to top of LazyColumn
but to top with some offset?ninadmg
01/28/2022, 1:29 PMiamthevoid
01/28/2022, 2:26 PMColton Idle
01/28/2022, 2:26 PMLazyColumn
, LazyRow
, Modifier.verticalScroll
and other containers that use Modifier.scrollable
now support mouse wheel scrolling.
• Added excludeFromSystemGesture
Modifiers for easy access to Android's setSystemGestureExclusionRects
• Fix continuous backspace on CJK keyboards (I think this is the fix for continuous backspace not working in password fields 🤞)
• Preserve scroll when items are added in lazy grid
• Fix TextFieldKeyInput onValueChange (this seems to fix an issue of typing with your keyboard on an emulator)
• Compose Material - Add support for action chip (not sure if this is a new chip component, but I want to check it out)
• Added Material 3 divider
• Added support for Material 3 progress indicators
• Add experimental View.createLifecycleAwareRecomposer extension (idk what this is but it sounds interesting...)
• Wear OS - Add support for Rotary Events modifiersJustin Breitfeller
01/28/2022, 2:39 PMalorma
01/28/2022, 3:07 PMGeorgeS-Litesoft
01/28/2022, 3:17 PMgpaligot
01/28/2022, 4:02 PMPHondogo
01/28/2022, 5:19 PMLaura Kelly
01/28/2022, 6:51 PMRobert Menke
01/28/2022, 9:41 PMAuthenticationViewModel
which is a @HiltViewModel
that keeps track of the authenticated User
entity as follows:
private var authenticatedUser: LiveData<User?> = userRepository.observeAuthenticatedUser().asLiveData()
After I’ve verified that a user is authenticated I want to be able to observe authenticatedUser
and ideally receive the latest`User` instance without having to retrieve it from the database again. I have a component called ProfileScreen
that tries to access that data as follows:
val authViewModel: AuthenticationViewModel = hiltViewModel()
val user by authViewModel.getAuthenticatedUser().observeAsState()
val firstName by viewModel.firstName.observeAsState(user?.firstName ?: "")
When I set a breakpoint on firstName
the variable user
is always null
initially. What is the right way to keep my User
instance in memory without having to re-fetch from the DB whenever I ask for it?Robert Menke
01/28/2022, 9:41 PMAuthenticationViewModel
which is a @HiltViewModel
that keeps track of the authenticated User
entity as follows:
private var authenticatedUser: LiveData<User?> = userRepository.observeAuthenticatedUser().asLiveData()
After I’ve verified that a user is authenticated I want to be able to observe authenticatedUser
and ideally receive the latest`User` instance without having to retrieve it from the database again. I have a component called ProfileScreen
that tries to access that data as follows:
val authViewModel: AuthenticationViewModel = hiltViewModel()
val user by authViewModel.getAuthenticatedUser().observeAsState()
val firstName by viewModel.firstName.observeAsState(user?.firstName ?: "")
When I set a breakpoint on firstName
the variable user
is always null
initially. What is the right way to keep my User
instance in memory without having to re-fetch from the DB whenever I ask for it?Ian Lake
01/28/2022, 11:29 PMcollect
on the Flow
, which is inherently an async operation. Now if your UserRepository
was driven by Room and returned a LiveData
itself, then you'd gain the natural caching that LiveData
has where it always remembers any previously returned value just like how StateFlow
worksprivate var authenticatedUser: StateFlow<User?> = userRepository.observeAuthenticatedUser().stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
Which would give you a StateFlow
(which also always remembers its current value), that is Lifecycle aware (the WhileSubscribed
prevents it from doing any work while your UI isn't collecting the StateFlow), and that still lets your Composable code call collectAsState()
to easily gather the latest valueRobert Menke
01/28/2022, 11:58 PM@Composable
@PublishedApi
internal fun createHiltViewModelFactory(
viewModelStoreOwner: ViewModelStoreOwner
): ViewModelProvider.Factory? = if (viewModelStoreOwner is NavBackStackEntry) {
HiltViewModelFactory(
context = LocalContext.current,
navBackStackEntry = viewModelStoreOwner
)
} else {
// Use the default factory provided by the ViewModelStoreOwner
// and assume it is an @AndroidEntryPoint annotated fragment or activity
null
}
I had a NavBackStackEntry
for my SplashScreen
and a separate one for my ProfileScreen
and yet another that didn’t have any associated NavBackStackEntry
, so of course I was re-fetching user state after the initial authentication check.
Seems like the right solution for something like authenticated user state is to create 1 instance of the view model outside of the navigation graph and then pass that instance into each Composable
that needs it since being scoped to @AndroidEntryPoint
I believe makes more sense here. I think I’ll move forward with that for now.