Has anyone working with `AndroidView` noticed that...
# compose
z
Has anyone working with
AndroidView
noticed that the view state of their nested Android view hierarchies isn’t being restored correctly either after config changes or navigation, or weird stuff with lifecycles? I’ve been exploring some of these interactions and found what I’m pretty sure are a number of bugs. The README in this repo describes a number of the (potential) issues I found, but if people have found other repro cases it would probably be good to add them to the Google issue.
a
I have encountered issues that AndroidView doesn’t rerender at all. https://issuetracker.google.com/issues/177561480 Would be nice if people could star this issue because it is stuck in some kind of hotlist.
h
I have encountered issues that AndroidView rerenders all the time 😄
😆 4
z
I think the rendering issue is probably unrelated
1
i
Note that the following changes might be related: • https://android-review.googlesource.com/c/platform/frameworks/support/+/1564002https://android-review.googlesource.com/c/platform/frameworks/support/+/1572944 Which change it so that CompositionLocals are now transferred down through AndroidViews
z
The first one is definitely related, I actually requested that for the same use case. I’m not sure about the second one, it looks like an optimization? I don’t think it addresses the issues I’m talking about though.
i
More of a fix to an issue created by the first one 😃
z
Oh interesting. That issue would have also affected Android views that had their composition references explicitly set though, wouldn’t it have?
a
Did these changes land on
alpha12
?
z
The first one Ian linked did, I saw it in the release notes. Presumably the second did too if it fixed a related bug
🙇🏻 1
j
@Zach Klippenstein (he/him) [MOD] did you also notice `View`s inside `AndroidView`s composables have their
onSaveInstanceState()
called but not
onRestoreInstanceState()
? (re: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1613139840305500 )
z
yep, that’s covered in the test cases in that repo
👌 1
🙏 1
j
From your readme:
Copy code
Android onRestoreInstanceState for Android views nested in ComposeViews is very broken, even when all known views have their IDs set:
It's not called after config changes.
I can confirm this happens with alpha12 even when not using
ComposeView
: it is enough if the
AndroidView
composable is loaded inside an Activity’s
setContent {}
.
z
Yea, they both do the same thing under the hood (use
AndroidComposeView
) – i should probably have been more precise about that in the readme, I just said
ComposeView
since that’s the primary API that you’re probably going to use if you do a lot of switching between worlds like this.
😮 1
👌 1
😛 1