0

Presenting sheet from childView of tabItem rerendering the whole Windows Group. My TabView alrdy has a selection Binding. When I use Fullscreen Cover it work fine. and sheet work fine with NavigationSplitView on iPad too. I have Attached some of the snippets. Please give some Ideas.

.sheet(item: $selectedVoucher) {
// on dismiss action 
} content: { voucher in
VoucherDetailsView(voucher: voucher)
}

Here is my TabView

TabView(selection: $selection) {
ForEach([NavigationItem.home, NavigationItem.vehicles, NavigationItem.workshop, NavigationItem.wallet, NavigationItem.profile]) { item in
item.destination
.tabItem { item.label }
.id(item)
.tag(item)
}
}

My Child View is wrapped in NavigationStack

The result I want is Just show the sheet only , not re-render the whole WindowGroup just bcos sheet is shown. .fullScreenCover is working fine not messing up with the TabView.

2
  • 1
    What do you mean by "re-render the whole WindowGroup"? How can you tell that it is rerendered? Please show a minimal reproducible example. Commented Dec 20, 2023 at 9:56
  • 1
    show the code that can be compiled and executed, and produces your issue. Commented Dec 20, 2023 at 10:15

1 Answer 1

0

$selection must be binded to some persistent object.

I don't see your full code, but try to update it as follows:

Instead of @State var selection = … use:

@StateObject var model = ViewModel()

class ViewModel: ObservableObject {
    @Published var selection = ...
}
…
TabView(selection: $model.selection) {
   ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.