Not sure if this is an issue with snapshotting, wi...
# compose
z
Not sure if this is an issue with snapshotting, with subcomposition, or if I’m doing something wrong, but subcomposing inside of android views seems to be broken again (dev17, alpha01): https://issuetracker.google.com/issues/166482486
l
was this fixed in dev16? or just never worked, just different error now?
i assigned to chuck, i think he’s the right owner of this bug now but not 100% sure
z
It worked in dev16, and a few versions before as well. I started seeing it when upgrading from dev16 to 17, and still seeing it in the alpha.
l
ok so i think you need to actually trigger the setContent call in an onPreCommit block, instead of in the property setter
property sets happen during apply changes and we don’t have things in a reliable state for you to do a subcomposition until after the whole composition is applied
doing this instead should work:
Copy code
val compRef = compositionReference()
    for (i in 0 until childCount) {
      val viewRef = remember { Ref<IntermediateAndroidView>() }
      AndroidView(::IntermediateAndroidView) {
        viewRef.value = it
      }
      onPreCommit {
        viewRef.value.compRef = compRef
      }
    }
although it is significantly uglier IMO
z
I'll give that a try, thanks. I'm not too worried about ugliness/boilerplate at this point, this code is all pretty hidden away.
This fixed it! I found another bug that seems unrelated, but it’s harder to trigger. Will try to file later.