I "fix" this by the save the selection to a temp variable onChange of the @Environment(.scenePhase)
.onChange(of: scenePhase) { phase in
if phase == .background{
tempSelectedId = selectedId
} else {
if phase == .inactive && selectedId == nil{
selectedId = tempSelectedId
print("Restore - scenePhase")
}
}
}
Post
Replies
Boosts
Views
Activity
I got the same problem.
My situation is the code works fine on Mac and iPhone, no setting to nil on the background, but the problem occurs occasionally on the iPad (not every time, 1/3 I guess).