Scott Kruse
08/29/2021, 2:54 AMFragmentStateAdapter
/ CoordinatorLayout
w/ NestedScrollView
? Do we need to wrap it in some scrollable parent or should LazyColumn be sufficient?Rekha
08/29/2021, 6:03 AMCristian Rosa
08/29/2021, 1:45 PMFlorian
08/29/2021, 2:03 PMDmitry Chernozubov
08/29/2021, 2:38 PMFudge
08/29/2021, 5:50 PM@Composable
fun FancyTextField(value: String, onValueChange: (String) -> Unit, modifier: Modifier = Modifier) {
Column(modifier) {
TextField(value, onValueChange)
Text("fancy!")
}
}
While looking innocent, this code breaks the passed modifiers. If I pass for example Modifier.fillMaxWidth()
, then only the Column
will have expanded width, and the TextField
will stay the same size, meaning that fillMaxWidth
will not make FancyTextField
fill max width (in practice). Obviously passing a modifier to TextFIeld
(instead or in addition) won't work well.
So how should FancyTextField
be declared in such a way that modifiers work as expected?Florian
08/29/2021, 6:27 PMSideEffect
here. The functionality works without the SideEffect
call. Can someone tell me why we need it?
https://google.github.io/accompanist/systemuicontroller/adjpd
08/29/2021, 7:49 PMimplementation "androidx.compose.ui:ui-tooling:$compose_version"
But then that means that library will increase the size of my production build. Is there a way around this?Slackbot
08/30/2021, 12:43 AMdarkmoon_uk
08/30/2021, 5:21 AM1.0.1
and ui-tooling
etc. same on Device / Emulator 🤷. Not even sure if the UIView/Compose mix is significant... inspector just plain doesn't work on Compose. Documentation says it should?Jan Skrasek
08/30/2021, 7:21 AMFelix Schütz
08/30/2021, 8:12 AMclass MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
// ...
}
}
}
However, setContent
replaces the root view when it finishes loading, so any custom splash screen animation will not play. Is there a better alternative?zokipirlo
08/30/2021, 9:12 AMTextField
to prevent showing soft input similar to showSoftInputOnFocus
on EditText
?Alex
08/30/2021, 9:59 AMcollectAsState()
(or an equivalent) inside of a LazyListScope
(outside of a @Composable
)?
The usecase is conditionally emitting either A or B items, depending on the content of a StateFlow
Felix Schütz
08/30/2021, 10:22 AMiamthevoid
08/30/2021, 10:46 AMremember
analog in SwiftUI?Marcin Środa
08/30/2021, 12:56 PMViewTreeObserver.OnPreDrawListener
in Compose? Looking for a way to delay startup due to data initialization. Was looking on https://developer.android.com/about/versions/12/features/splash-screen but can’t connect it with compose.Walter Berggren
08/30/2021, 1:48 PMZoltan Demant
08/30/2021, 1:57 PMselectableItemBackground
on the parent rather than child view in XML). If I specify a clickable composable around the button, the button will still grab focus (even if I mute its ripple effect through Modifier.clickable
). I can acheive it by using a Text
instead of Button
since it wouldnt be clickable, but then Id have to continiously mimic the button style exactly in the text composable.Fudge
08/30/2021, 2:39 PMConstraintLayout
. Will ConstraintLayout
throw an exception in that case? Or just try to make do, ignore some constraints, etc? I'm facing a case in which I have a slightly complicated layout, and it seems like some constraints i'm specifying are being ignoredRafs
08/30/2021, 3:09 PMrememberImagePainter
always returns empty state when I pass a content Uri to data
Lilly
08/30/2021, 3:13 PMViewModel
into one state object (e.g. data class ViewState(..)
)? In my opinion both have advantages and disadvantages. Exposing multiple states from VM keeps changes to the UI more granular but it's more cumbersome to keep track of every single state. On the other hand, exposing just one bigger state object has better maintenance because you always have to deal with just one state in your UI but in contrast when one of the fields changes, a new object is created. Imagine you have following state object:
data class MyScreenState(
val isLoaded: Boolean,
val items: List<SomeType>,
val sortedItems: List<SomeType>,
val recommendedItems: List<SomeType>,
)
While isLoaded
might changes quite frequently, the other fields do not and this yields to a massive unbalanced object creation. So I'm wondering if there is any rule of thumb when to use which approach?Scott Kruse
08/30/2021, 5:15 PMChris Johnson
08/30/2021, 5:58 PMCompositionLocalProvider
to other composables from your main composable? I assume this would be good for composables that you don't plan on re-using and are coupled tightly to that uiState. Rather than passing in my uiState to every composable that needs it.
Or is this already a smell because each composable should only have things passed into it it needs? I've thought about this when let's say composable B needs to send data to composable C from composable A (from the uiState) and rather than pass in 8 things to composable B, I'd rather pass in a uiState so I have access to everything I need. (If a composable only needs 1-2 things then it makes sense to only pass those, but for composable dependencies that need 7-8 fields does this make sense to do?)hfhbd
08/30/2021, 6:57 PMdao.get().collectAsState(emptyList())
with interface Dao { @Query(...) fun get(): Flow }
? You have to use a ViewModel to get updates on DB changes. WA: wrap the collect
in VM and emit them to the flow accessed by Compose...mattinger
08/30/2021, 7:14 PMtrickybits
08/30/2021, 7:17 PMvar tiledBackgroundImageShader by remember { mutableStateOf<ShaderBrush?>(null) }
val imageLoader = LocalImageLoader.current
val localContext = LocalContext.current
LaunchedEffect(backgroundImageSrc) {
val builder = ImageRequest.Builder(localContext).data(backgroundImageSrc)
val result = imageLoader.execute(builder.build()).drawable?.toBitmap()
if (result != null) {
val shader = ImageShader(result.asImageBitmap(), tileModeX = TileMode.Repeated, tileModeY = TileMode.Repeated)
tiledBackgroundImageShader = ShaderBrush(shader)
}
}
and for the content:
Box(
modifier = Modifier
.drawWithCache {
onDrawBehind {
drawRect(backgroundColor)
tiledBackgroundImageShader?.let { drawRect(it) }
}
}
) {
Slackbot
08/30/2021, 9:45 PMdarkmoon_uk
08/31/2021, 1:01 AMComposeView
within a traditional View
hierarchy? Any examples of this?jkm
08/31/2021, 1:16 AMModifier.onFocusEvent
Say I have a scrollable list of buttons and at the very bottom of this list I have a OutlinedTextField
.
I’ve applied the following to the OutlinedTextField
.onFocusEvent {
if (it.isFocused) {
scope.launch { scrollState.animateScrollTo(scrollState.maxValue) }
}
}
This works as expected in that when I tap on the OutlinedTextField
, my list scrolls to the bottom. The issue is that even when I tap on other elements (i.e. one of the buttons), that also scrolls the user to the bottom. Any ideas?jkm
08/31/2021, 1:16 AMModifier.onFocusEvent
Say I have a scrollable list of buttons and at the very bottom of this list I have a OutlinedTextField
.
I’ve applied the following to the OutlinedTextField
.onFocusEvent {
if (it.isFocused) {
scope.launch { scrollState.animateScrollTo(scrollState.maxValue) }
}
}
This works as expected in that when I tap on the OutlinedTextField
, my list scrolls to the bottom. The issue is that even when I tap on other elements (i.e. one of the buttons), that also scrolls the user to the bottom. Any ideas?Will Shelor
08/31/2021, 1:55 AM