Skip to content

Commit

Permalink
Set Android View ID on TreehouseLayout by default
Browse files Browse the repository at this point in the history
If one doesn't explicitly set an Android View ID, `onSaveInstanceState` is never invoked, and thus `rememberSaveable` will never work as intended.
  • Loading branch information
veyndan committed Sep 28, 2023
1 parent 89750b1 commit 7ec4832
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public class TreehouseLayout(

override var saveCallback: TreehouseView.SaveCallback? = null

init {
// The view needs to have an id for Android to populate saved data back
@SuppressLint("ResourceType")
id = 9000
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()
readyForContent = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class EmojiSearchActivity : ComponentActivity() {

setContentView(
TreehouseLayout(this, widgetSystem, onBackPressedDispatcher).apply {
// The view needs to have an id for Android to populate saved data back
this.id = 9000
treehouseContentSource.bindWhenReady(this, treehouseApp)
},
)
Expand Down

0 comments on commit 7ec4832

Please sign in to comment.