Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 101 characters in body
Source Link
Martijn Pieters
  • 1.1m
  • 326
  • 4.2k
  • 3.4k
added 146 characters in body
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889
struct ModalView : View { @Binding var activeModal: Bool var body : some View { VStack { Button(action: { withAnimation(.easeInOut(duration: 0.3)) { self.activeModal = false } }) { Text("Hide modal") } Text("Modal View") } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) .background(Color.green) } } struct MainView : View { @Binding var activeModal: Bool var body : some View { VStack { Button(action: { withAnimation(.easeInOut(duration: 0.3)) { self.activeModal = true } }) { Text("Show modal") } Text("Main View") } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) .background(Color.yellow) } } struct ModalContainer: View { @State var showingModal = false var body: some View { ZStack { MainView(activeModal: $showingModal) .allowsHitTesting(!showingModal)   .disabled(showingModal) if showingModal { ModalView(activeModal: $showingModal) .transition(.move(edge: .bottom)) .zIndex(1) } } } } 

backup

struct ModalView : View { @Binding var activeModal: Bool var body : some View { VStack { Button(action: { withAnimation(.easeInOut(duration: 0.3)) { self.activeModal = false } }) { Text("Hide modal") } Text("Modal View") } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) .background(Color.green) } } struct MainView : View { @Binding var activeModal: Bool var body : some View { VStack { Button(action: { withAnimation(.easeInOut(duration: 0.3)) { self.activeModal = true } }) { Text("Show modal") } Text("Main View") } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) .background(Color.yellow) } } struct ModalContainer: View { @State var showingModal = false var body: some View { ZStack { MainView(activeModal: $showingModal) .allowsHitTesting(!showingModal) if showingModal { ModalView(activeModal: $showingModal) .transition(.move(edge: .bottom)) .zIndex(1) } } } } 
struct ModalView : View { @Binding var activeModal: Bool var body : some View { VStack { Button(action: { withAnimation(.easeInOut(duration: 0.3)) { self.activeModal = false } }) { Text("Hide modal") } Text("Modal View") } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) .background(Color.green) } } struct MainView : View { @Binding var activeModal: Bool var body : some View { VStack { Button(action: { withAnimation(.easeInOut(duration: 0.3)) { self.activeModal = true } }) { Text("Show modal") } Text("Main View") } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center) .background(Color.yellow) } } struct ModalContainer: View { @State var showingModal = false var body: some View { ZStack { MainView(activeModal: $showingModal) .allowsHitTesting(!showingModal)   .disabled(showingModal) if showingModal { ModalView(activeModal: $showingModal) .transition(.move(edge: .bottom)) .zIndex(1) } } } } 

backup

Post Undeleted by Asperi
deleted 47 characters in body
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889

HereDisclaimer: Below is an approach with which you can control navigation between your views with anynot really like a "native modal", neither behave nor look&feel, but if anyone would need a custom transition/animation you wish (w/o UIKit representables)

Note: Transitions do not work in Preview (at least at my side, Xcode 11.2), so Simulator or real device should used for testing of one view over other, making active only top one, the following approach might be helpful.

IfSo, if you expectedexpect something like the following

Here is an approach with which you can control navigation between your views with any transition/animation you wish (w/o UIKit representables)

Note: Transitions do not work in Preview (at least at my side, Xcode 11.2), so Simulator or real device should used for testing

If you expected something like the following

Disclaimer: Below is not really like a "native modal", neither behave nor look&feel, but if anyone would need a custom transition of one view over other, making active only top one, the following approach might be helpful.

So, if you expect something like the following

Post Deleted by Asperi
tuned code
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889
Loading
added 117 characters in body
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889
Loading
added 29 characters in body
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889
Loading
added 127 characters in body
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889
Loading
Source Link
Asperi
  • 262.2k
  • 28
  • 594
  • 889
Loading