Chris Fillmore
04/22/2021, 1:16 AMComposeView
to draw a composition into a Canvas, off-screen? More or less this:
val canvas = Canvas()
val composeView = ComposeView(context)
composeView.setContent {
// Call composables here
SideEffect {
composeView.draw(canvas)
}
}
Important to note that the ComposeView is never attached to a window / drawn in the UI. The view is created programmatically, as above.
I am ultimately trying to get the composition into a Bitmap for the purpose of drawing into an OpenGL texture. (If there is a better approach, I’m all ears.) Thanks for any help!Indu
04/22/2021, 2:06 AMShivam Sethi
04/22/2021, 4:28 AMShivam Sethi
04/22/2021, 6:00 AMSamir Basnet
04/22/2021, 6:41 AMPaul Woitaschek
04/22/2021, 7:48 AMloloof64
04/22/2021, 8:40 AMComposable
, is there a way to get the component size based on its given Modifier
?
I mean, given
@Composable
fun MyComposable(modifier: Modifier = Modifier){}
Is there a way to get the allocated width and height (inside MyComposable
definition) ?mzgreen
04/22/2021, 9:02 AMRow
with 2 Texts
which both take up 50% of the screen width. Here is an xml version of the thing I want to achieve:
<LinearLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Foo"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Bar"
/>
</LinearLayout>
I came up with this:
Row(Modifier.fillMaxWidth()) {
Text(text = "Foo", Modifier.fillMaxWidth(0.5f))
Text(text = "Bar", Modifier.fillMaxWidth())
}
Is there some other, maybe better way to do it?loloof64
04/22/2021, 10:03 AMVector Drawable
: is there a way to do it ?Lucien Guimaraes
04/22/2021, 10:56 AMescodro
04/22/2021, 11:58 AM:app
are no longer working because it can not find the ComponentActivity
registered in the debug AndroidManifest.xml
. Is it the expected behavior now? Should we have one debug Manifest for each library modules?
It worked fine on Compose 1.0.0-alpha04.
Issue tracker opened with more info:
https://issuetracker.google.com/issues/186019857Konyaco
04/22/2021, 1:18 PMtryAwaitRelease()
always returns false
.Altynbek Nurtaza
04/22/2021, 2:06 PMsen kumar
04/22/2021, 2:29 PMdewildte
04/22/2021, 2:55 PMTextFieldValue(
cursorPosition = text.length
)
Manipulating the cursor position causes weird bugs when using a hardware keyboard.
Especially around new lines.alorma
04/22/2021, 4:59 PMstate
(i guess) to save a value in preferences, and trigger recomposition when it changes...
However, i managed to save the new value, but it is not triggering a recompostion.. what I'm missing? code on threadMarko Novakovic
04/22/2021, 8:21 PMrememberUpdatedState
. what is it used for and what is it really doing? am trying to write some code in order to test/grasp what’s it doing but still nothingBrady Aiello
04/22/2021, 8:57 PM@ExperimentalComposeUiApi
@Composable
fun UsernameTextField(
state: State<String>,
label: String,
onValueChange: (String) -> Unit
) {
Column {
TextField(
value = state.value,
onValueChange = onValueChange,
label = { Text(label) },
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
singleLine = true
)
}
}
and call it like this:
UsernameTextField(
state = userName,
label = getString(R.string.Username),
) {
loginViewModel.updateUserName(it)
}
When typing most characters, the onValueChange
is triggered on the whole String there, like “a”, “ad”, “ada”. But if I type a tab or return at the end of a String, onValueChange
is triggered on only the tab/return character. Does anyone understand why this is happening?YASAN
04/22/2021, 10:34 PMAppCompatDelegate
to change dark mode but on my Compose app it has no effect.
It looks like isSystemInDarkTheme()
just checks the system settings and even when I use my own function to check dark mode, it only effects the Compose MaterialTheme colors which I don't use much. I use resources for dark/light colors and it works fine except this.
How can I handle this in Compose? It does not look like AppCompatDelegate
has any effect on Compose.Zhelyazko Atanasov
04/23/2021, 5:53 AMAndroidXScreenshotTestRule
. But I can't seem to find the appropriate dependency to add to my project so that I can use AndroidXScreenshotTestRule
. I looked into Google's Maven repo for androidx.test
group and I also have added these dependencies to my project:
• androidx.test:core-ktx
• androidx.test:runner
• androidx.test:rules
• androidx.test.ext:junit-ktx
But none of them seems to contain the desired AndroidXScreenshotTestRule
. What am I missing?mzgreen
04/23/2021, 6:02 AMjean
04/23/2021, 8:25 AMImage
composable with rememberCoilPainter
nested under a LazyColumn
but it seems to not be working, the image is not loading. If I take the composable out of the LazyColumn
then it works fine. Any idea what’s going on?loloof64
04/23/2021, 8:34 AMComposable
, but I don't know how to make this drawing reactive to click. More in the thread.Adrian Landborn
04/23/2021, 9:56 AMRipple
-indication for Buttons and Cards? Or to override rememberRipple
in a custom theme?YASAN
04/23/2021, 11:06 AMallan.conda
04/23/2021, 12:20 PMProfile(userId: String) {
val viewModel = hiltNavGraphViewModel<ProfileViewModel>()
DisposableEffect(userId) {
viewModel.loadProfile(userId) // don't trigger on config change
onDispose { }
}
val profile = viewModel.profile.collectAsState(...)
}
Actually, with compose-navigation it seems the backstack arguments are also in the ViewModel savedStateHandle. I’m wondering if it would be better to extract the userId from there instead.MaxUt
04/23/2021, 1:16 PMNavHostController
. I have several NavHostController so I can navigate through sub-pages and would like to send an event to the root Composable so I get the current NavHostController. The idea behind is to use it in a topBar so I can pop element off the stack and go back to the previous view. Do you guys have any experience with that ?Colton Idle
04/23/2021, 1:16 PMI'm building a new app with no DI. It's a breath of fresh air, to be frank.
CompositionLocalProvider currently serves the need I had for DI, and there's no sacrifice in testability (so far).Is it find to use CompositionLocalProvider for this sort of stuff? https://www.reddit.com/r/androiddev/comments/mwjut9/dagger_hilt_is_now_stable_with_235/gvj2beu?utm_source=share&utm_medium=web2x&context=3
grandstaish
04/23/2021, 1:43 PMBryan Herbst
04/23/2021, 1:51 PMText()
measure as though its text is bold even when its not so that the size of the Text()
component doesn’t change as text gets bolded/unbolded.
What’s the best way to accomplish that?
Here’s an example of the behavior I don’t want:Bryan Herbst
04/23/2021, 1:51 PMText()
measure as though its text is bold even when its not so that the size of the Text()
component doesn’t change as text gets bolded/unbolded.
What’s the best way to accomplish that?
Here’s an example of the behavior I don’t want:grandstaish
04/23/2021, 2:18 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:18 PMBryan Herbst
04/23/2021, 2:19 PMfun Modifier.widthByTextStyle(
text: String,
style: TextStyle
) = composed {
val maxIntrinsics = MultiParagraphIntrinsics(
annotatedString = AnnotatedString(text),
style = style,
placeholders = emptyList(),
density = LocalDensity.current,
resourceLoader = LocalFontLoader.current
)
val widthDp = with(LocalDensity.current) {
maxIntrinsics.maxIntrinsicWidth.toDp()
}
width(widthDp)
}
Zach Klippenstein (he/him) [MOD]
04/23/2021, 2:19 PMBryan Herbst
04/23/2021, 2:19 PMJavier
04/23/2021, 2:22 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:23 PMBryan Herbst
04/23/2021, 2:24 PMprivate fun Modifier.scrollableSegmentBackground(selected: Boolean) = composed {
val elevationDp by animateDpAsState(
targetValue = if (selected) TargetElevation.OnLight.medium else 0.dp
)
val backgroundColor by animateColorAsState(
targetValue = if (selected) {
TargetTheme.colors.background.default
} else {
TargetTheme.colors.background.container
}
)
graphicsLayer(
shadowElevation = with(LocalDensity.current) { elevationDp.toPx() },
shape = SegmentShape
).background(
color = backgroundColor,
shape = SegmentShape
)
}
Siyamed
04/23/2021, 4:40 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 5:01 PMThis makes grade a useful axis of variation as it can be varied or animated without causing reflow of the text itself.Wow this is super interesting. Learning so much today!
Colton Idle
04/23/2021, 5:04 PMBryan Herbst
04/23/2021, 5:08 PMscrollableSegmentBackground()
does both the background color and the elevation.