Sahruday
06/23/2022, 11:23 AMLazyLazyState
?
animateScrollToItem
for long distance scroll, it animates all the way to the index, which takes too long time.
Need to animate the scroll at initial, teleport to some nearest index and animate from there to the index.allan.conda
06/23/2022, 12:36 PMbaseline-prof.txt
file?kotlinforandroid
06/23/2022, 12:44 PMExposedDropdownMenuBox
? Code in thread.julioromano
06/23/2022, 1:24 PMPointerInputScope.detectTransformGestures()
docstring but I can’t make sense of what it means.Zoltan Demant
06/23/2022, 1:38 PMPaul Woitaschek
06/23/2022, 1:44 PMTolriq
06/23/2022, 3:01 PMBilly Newman
06/23/2022, 3:06 PMfarmerbb
06/23/2022, 4:02 PMzsperske
06/23/2022, 4:32 PM//I create a scroll state in my view model and pass it here to be used
val scrollState = rememberSaveable(saver = ScrollState.Saver) { viewModel.state.scrollState }
//Add to my column
Modifier.verticalScroll(scrollState)
//In on save instance state of an Android View I grab the state and save it to a bundle
savedState.scrollPosition = viewModel.state.scrollState.value
However, the scroll state’s value is always 0. Am I going about this all wrong?Ryan Simon
06/23/2022, 5:00 PMTolriq
06/23/2022, 8:05 PMDaniel Okanin
06/23/2022, 8:40 PMLaunchedEffect(shouldLoadMore) {
if (shouldLoadMore.value) {
lastTotalItems = state.layoutInfo.totalItemsCount
onEndReached()
}
}
=========================
LaunchedEffect(shouldLoadMore) {
snapshotFlow { shouldLoadMore.value }
.collect { shouldLoadMore ->
if (shouldLoadMore){
lastTotalItems = state.layoutInfo.totalItemsCount
onEndReached()
}
}
}
mattinger
06/23/2022, 11:22 PMzt
06/24/2022, 2:11 AM@Composable
fun Player(
modifier: Modifier = Modifier,
player: Player,
) = DisposableEffect(
AndroidView(
modifier = Modifier
.aspectRatio(16f / 9f)
.then(modifier),
factory = { context ->
PlayerView(context).apply {
this.player = player
useController = false
useArtwork = true
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
}
}
)
) {
onDispose(player::release)
}
Rafs
06/24/2022, 7:11 AM@Composable
fun App(){
fun someInnerComputationFunction(input: Int): Int{
//do some computation and return an integer
}
Box(modifier = Modifier.fillMaxSize()){
}
}
Christoph Wiesner
06/24/2022, 7:18 AMLazyColumn
Showing that content should behave like a bottom sheet (collapsing or expanding if too little/enough drag)
Using nestedScroll
and swipeable
seems the way to go but I’m struggling as the List also needs to be full-height and nesting vertically scrollable maxHeight layouts is disallowed. Any ideas?Ngọc Nguyên Nguyễn
06/24/2022, 7:36 AMallan.conda
06/24/2022, 8:45 AMval lifecycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_STOP) {
viewModel.onStop()
}
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
Loney Chou
06/24/2022, 10:45 AMabstract class Scene : JavaScene() { // JavaScene is a Java class
private var composition: Composition? = null
fun setContent(content: @Composable () -> Unit) {
composition = Composition(/* ... */).apply { setContent(content) }
}
}
and a subclass like this:
class MyScene : Scene() {
override fun init() { // From JavaScene
setContent { /* ... */ }
}
}
Nothing complains during the compile time, but at the runtime when init
gets called, Scene.setContent
throws an error: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0
. How to fix that?vide
06/24/2022, 11:13 AMval calculationResult by remember { derivedStateOf {
val primaryLocale = LocalConfiguration.current.locales.get(0) // error
// Some filtering, calculations, etc.
} }
Obviously this doesn't work, since CompositionLocal.current is @Composable and results in an error.
If I store the Configuration outside of the derivedStateOf block, it won't work either since it doesn't observe that State is being read and won't update.
val configuration = LocalConfiguration.current
val calculationResult by remember { derivedStateOf {
val primaryLocale = configuration.locales.get(0)
// Some filtering, calculations, etc.
} }
// Doesn't update
What would be an idiomatic/correct way to achieve what I'm trying to do here?Kamesh Yadav
06/24/2022, 1:12 PMBino
06/24/2022, 3:01 PMswipeable
modifier in a CoordinatorLayout but it is only working Horizontal but not Vertical
https://gist.github.com/thebino/4c95e46cca53ec1d9baa29953f0ccb20#file-mainactivity-kt-L79Vinay Gaba
06/24/2022, 3:45 PMchatterInDaSkull
06/24/2022, 4:57 PMModalBottomSheetScaffold
🤔 why is that? just the case of yet to be created?zt
06/24/2022, 8:47 PMnavController.navigate(destination.direction) {
popUpTo(navController.navGraph.startRoute) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
Ji Sungbin
06/25/2022, 5:40 AMinvalidateGroupsWithKey(key: Int)
function in SlotTable only used for testing? I followed the final call of invalidateGroupsWithKey and arrived at the invalidateGroupsWithKey function with @TestOnly attached, and this function is not used. I figured out that the only use case of the findEffectiveRecomposeScope(group: Int)
function, which is i think an important function of SlotTable, is invalidateGroupsWithKey, and I wanted to know where invalidateGroupsWithKey is called.
@TestOnly
fun invalidateGroupsWithKey(key: Int) = HotReloader.invalidateGroupsWithKey(key)
And in the process of reaching final TestOnly function, I saw a function like the one below.
fun invalidateGroupsWithKey(key: Int) {
val compositions: List<ControlledComposition> = synchronized(stateLock) {
knownCompositions.toMutableList()
}
compositions
.fastMapNotNull { it as? CompositionImpl }
.fastForEach { it.invalidateGroupsWithKey(key) }
}
}
knownCompositions
is already a MutableList, but why change MutableList to MutableList?Tolriq
06/25/2022, 8:25 AModay
06/25/2022, 9:03 AM@HiltViewModel
class AuthenticationViewModel @Inject constructor(
private val determineAuthStatus: DetermineAuthStatus,
private val populateUserPrefs: PopulateUserPrefs
) : ViewModel() {
and I want to use the viewmodel in a composable like so
val viewModel : AuthenticationViewModel = hiltViewModel()
but I get that the viewmodel does not have any zero-argument constructors, I’ve already created the module for these 2 deps to be provided
this composable that i’m using the viewmodel in, is started inside an Activity which I’ve set @AndroidEntryPoint on, what am I missing ?kotlinforandroid
06/25/2022, 1:32 PMTextField
does compose only update NameUI
or does it also re-compose AgeUI
since state updated and it includes the value for AgeUI
.
private data class State(
var name: String = "",
var age: Int = 0,
)
@Composable
fun UI() {
val state = remember { State() }
NameUI(name = state.name, onNameChange = { state.name = it })
AgeUI(age = state.age, onAgeChange = { state.age = it })
}
@Composable
private fun NameUI(name: String, onNameChange: (String) -> Unit) {
TextField(value = name, onValueChange = onNameChange)
}
@Composable
private fun AgeUI(age: Int, onAgeChange: (Int) -> Unit) {
TextField(value = age.toString(), onValueChange = { onAgeChange(it.toInt()) })
}
kotlinforandroid
06/25/2022, 1:32 PMTextField
does compose only update NameUI
or does it also re-compose AgeUI
since state updated and it includes the value for AgeUI
.
private data class State(
var name: String = "",
var age: Int = 0,
)
@Composable
fun UI() {
val state = remember { State() }
NameUI(name = state.name, onNameChange = { state.name = it })
AgeUI(age = state.age, onAgeChange = { state.age = it })
}
@Composable
private fun NameUI(name: String, onNameChange: (String) -> Unit) {
TextField(value = name, onValueChange = onNameChange)
}
@Composable
private fun AgeUI(age: Int, onAgeChange: (Int) -> Unit) {
TextField(value = age.toString(), onValueChange = { onAgeChange(it.toInt()) })
}
ste
06/25/2022, 2:42 PMname
and age
a MutableState
first. After doing so, the answer is yes, e.g. AgeUI
wont't recompose if name
changes (UI
and NameUI
will), because it doesn't read name
and it's Stable
kotlinforandroid
06/25/2022, 3:00 PMAdvitiay Anand
06/26/2022, 6:59 AMGrégory Lureau
06/27/2022, 7:39 AM