alorma
12/23/2020, 6:20 PMLauren Yew
12/23/2020, 9:08 PMLayout(
modifier = modifier,
children = children
) { measurables, constraints ->
...
}
My Android Studio (on Compose alpha 9) is saying that API isn't available.Vsevolod Ganin
12/23/2020, 10:06 PMImageVector
in runtime anywayManuel Lorenzo
12/23/2020, 10:19 PMChethan
12/24/2020, 8:55 AMChethan
12/24/2020, 9:14 AMConstraintLayout(modifier = Modifier.fillMaxWidth()) {
val (dot, title, deleteButton) = createRefs()
Image(
asset = vectorResource(id = if (!notifications.readFlag) R.drawable.ic_ellipse_red else R.drawable.ic_ellipse_white),
modifier = Modifier
.constrainAs(dot) {
linkTo(
start = parent.start,
end = title.start
)
centerVerticallyTo(parent)
}
)
Text(
text = notifications.title,
style = TextStyle(
color = black33,
fontSize = 14.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Start
),
modifier = Modifier.fillMaxWidth(0.9F).constrainAs(title) {
linkTo(
start = dot.end,
end = deleteButton.start
)
}.padding(start = 10.dp)
)
Image(
asset = vectorResource(id = R.drawable.ic_icon_delete_gray),
modifier = Modifier.wrapContentSize()
.clickable(
onClick = {
showPopUpToDelete.value = true
}
).constrainAs(deleteButton) {
end.linkTo(parent.end)
linkTo(
start = title.end,
end = parent.end
)
}
)
}
This is how presently lookingGeert
12/24/2020, 10:06 AMKshitij Patil
12/24/2020, 10:56 AMAutoCompleteTextField
few days ago but with the latest compose (alpha09) it seems like it's a bad idea to put a TextField inside a LazyColumn
as one of its item
, especially when its other items are decided based on what we type in the TextField, as I found my current implementation just gets stuck in an infinite loop of recomposition, freezing the textfield.
Any best practices, guidelines to follow in this regard? What should we keep inside a LazyColumn and what we shouldn't?Bradleycorn
12/24/2020, 4:17 PMderivedStateOf
and wondering if there is any difference between the following 2 examples? Is one approach "better" than the other? Are there problems with one approach or the other? Is there an advantage to one over the other (other than just the amount of code)? Is example 2 a proper use of derivedStateOf
? Am I likely to run into concurrency issues?
EXAMPLE 1
var UiState by mutableStateOf(MyCompositeDataClass(value1 = null, value2 = null))
private set
init {
viewModelScope.launch {
getValue1Flow().collect { UiState = UiState.copy(value1 = it) }
}
viewModelScope.launch {
getValue2Flow().collect { UiState = UiState.copy(value2 = it) }
}
}
EXAMPLE 2
private var state1 by mutableStateOf<String?>(null)
private var state2 by mutableStateOf<String?>(null)
val UiState by derivedStateOf {
UiState(value1 = state1, value2 = state2)
}
init {
viewModelScope.launch {
getValue1Flow().collect { state1 = it }
}
viewModelScope.launch {
getValue2Flow().collect { state2 = it }
}
}
Kshitij Patil
12/24/2020, 5:08 PMmodifier
as first optional argument. May I know why?
I've some Custom Composables like HeaderText
which used to have first parameter the text itself so I didn't need to write parameter names explicitly, but putting modifier as first parameter makes me lose this power.rsktash
12/24/2020, 6:35 PMbirdsofparadise
12/24/2020, 6:43 PMeventually
Compose will replace Fragments? Looking at the Compose navigation feature it leads me to believe that.birdsofparadise
12/24/2020, 11:47 PMclass MyActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberNavController()
NavHost(navController, startDestination = "") {
composable("") { TestCompose() }
composable("test") { TestCompose() }
}
}
}
}
@Composable
fun TestCompose(vm: TestViewModel = viewModel()) {
}
Reading about the API viewModel it seems like using it in the manor I am, it's lifecycle gets attached to MyActivity
and thus if I navigate multiple TestCompose
views it will leak my ViewModelBrady Aiello
12/25/2020, 1:20 AMShakil Karim
12/25/2020, 11:00 AMvar imageBitmap by remember { mutableStateOf<ImageBitmap?>(null) }
SwiftUI syntx read so much better
@State var someValue = ""Marko Novakovic
12/25/2020, 11:06 AMJetNews
compose sample. It's still not migrated to navigation component nor does it use LazyColumn
, it uses ScrollableColumn
instead. JetSurvey
doesn't implement navigation component too. Is there any sample that is up to date with everything, not just navigation and LazyColumn
?Marko Novakovic
12/25/2020, 11:08 AMNavigation Component
?Shakil Karim
12/25/2020, 11:22 AMgeorgiy.shur
12/25/2020, 9:52 PMviewModel
extension, which should use the Hilt factory underneath and create my ViewModel
from it.
Everything works fine, but when I'm adding the Compose NavHost
to the mix, the composable inside it that calls viewModel
just uses the generic factory instead the one generated by Hilt. I think it has something to do with this code from the source:
public fun NavHost(navController: NavHostController, graph: NavGraph) {
var context = AmbientContext.current
val lifecycleOwner = AmbientLifecycleOwner.current
val viewModelStore = AmbientViewModelStoreOwner.current.viewModelStore
...
}
What is the right way to make them work together? I'm still not sure that I'm getting the Ambient concept right.Halil Ozercan
12/25/2020, 10:07 PMjava.lang.IllegalArgumentException: Invalid slot table detected
and I'm pretty sure it has nothing to do with using incompatible versions together. My setup is complicated, which means it would be very hard for me to isolate the issue. However, involved pieces are AnimatedVisibility
and a button click listener. I would like to give more information if these ring any bells.Sinan Gunes
12/26/2020, 2:13 PMConcatAdapter
once and it was very easy.frankelot
12/26/2020, 6:46 PMPhilip Dukhov
12/27/2020, 3:26 AMdata class SurfaceViewContext(
val eglBase: EglBase,
val videoTrack: VideoTrack,
)
@Composable
fun SurfaceView(
surfaceViewContext: SurfaceViewContext,
modifier: Modifier,
) {
val context = AmbientContext.current
val customView = remember {
SurfaceViewRenderer(context).apply {
init(surfaceViewContext.eglBase.eglBaseContext, null)
setEnableHardwareScaler(true)
setMirror(true)
}
}
AndroidView(
{ customView },
modifier = modifier
) {
surfaceViewContext.videoTrack.addSink(it)
}
onDispose {
surfaceViewContext.videoTrack.removeSink(customView)
}
}
And using it like this:
@Composable
fun TestView(context: SurfaceViewContext?) =
Column(
modifier = Modifier
.fillMaxWidth()
) {
context?.let {
SurfaceView(
it,
modifier = Modifier
.weight(1F)
)
}
Box(
modifier = Modifier
.size(40.dp)
.background(Color.Red)
)
Text("hello",
color = Color.White,
modifier = Modifier
)
Box(
modifier = Modifier
.background(Color.Red)
.aspectRatio(1080F/1920)
.align(Alignment.End)
.padding(10.dp)
.weight(1F)
) {
context?.let {
if (counter % 2 == 0) {
SurfaceView(
it,
modifier = Modifier
.fillMaxSize()
)
}
}
}
Text(
"hello again",
color = Color.White,
modifier = Modifier
.align(Alignment.End)
)
}
But there’s a bug. All views above SurfaceView, except an other SurfaceView, becomes invisible. I’ve added a counter and update the view once a second to add/remove a second SurfaceView. When it’s presented, the container containing it disappears, as well as other Box and Text. Text below is visible all the time. If I use Box instead of a Column as a main container, problem is the same.
sample project: https://github.com/PhilipDukhov/ComposeWebRTCTestPrashant Priyadarshi
12/27/2020, 2:56 PMfrankelot
12/27/2020, 4:34 PMtylerwilson
12/27/2020, 10:20 PMNat Strangerweather
12/27/2020, 10:22 PMval checkedState = remember { mutableStateOf(true) }
VerticalGrid(modifier = Modifier.padding(start = 30.dp, end = 30.dp)) {
listOf(
"Alarms",
"Media",
"Touch",
"Reminders",
"Events",
"Repeat Callers"
).forEachIndexed { index, string ->
Column(
Modifier.fillMaxWidth().padding(20.dp),
horizontalAlignment = CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
CustomToggle(
color = accentColor,
selected = checkedState.value,
onClick = {
checkedState.value = !checkedState.value
toggleAtIndex(index)
}
)
}
}
}
}
fun toggleAtIndex(index: Int) {
when (index) {
0 -> println(0)
1 -> println(1)
2 -> println(2)
3 -> println(3)
4 -> println(4)
5 -> println(5)
}
}
John O'Reilly
12/28/2020, 11:10 AMGoogleMap.InfoWindowAdapter
in a Compose app? I tried returning a ComposeView
from getInfoContents()
but getting
java.lang.IllegalStateException: Composition view not present for measure!
Kshitij Patil
12/28/2020, 12:04 PMLazyRow
inside FlowRow
but doesn't seem to workCyril Find
12/28/2020, 1:33 PMRow
parent in my case)Cyril Find
12/28/2020, 1:33 PMRow
parent in my case)