GithubHelp home page GithubHelp logo

Comments (5)

ElyesDer avatar ElyesDer commented on August 20, 2024

Try implement it this way.

@State var showMyPartial : Bool = false; 

var body: some View {
MyMainView()
.onAppear{
// important line to show the view
self.showMyPartial.toggle() 
}
.partialSheet(presented: $showMyPartial, view: YourView())
// onDismiss the boolean will automatically detoggle
}

from partialsheet.

MartinaRogach avatar MartinaRogach commented on August 20, 2024

I understand this, but
in your example, with PartialSheet YourView() will present
my question is - how can I dismiss YourView with button in YourView
//MainView
Button(action: {
self.changeMonthBool = true
})
...
.partialSheet(presented: $changeMonthBool) {
CalendarView(month: self.$month.month, year: self.$month.year, sectionMonth: self.$sections.month)

//CalendarView
Button(action: {
self.sectionMonth = self.month
self.presentationMode.wrappedValue.dismiss() //here I have to dismiss CalendarView
})

from partialsheet.

ElyesDer avatar ElyesDer commented on August 20, 2024

Ok try this :

// MainView

@State var changeMonthBool : Bool
...
CalendarView (shouldAppear : self.changeMonthBool , ... )

// CalendarView
@Binding var shouldAppear : Bool
init(shouldAppear : Binding<Bool> , .... ){
self._shouldAppear = shouldAppear
... 
}

// now to dissmiss from CalendarView
self. shouldAppear = false

from partialsheet.

AndreaMiotto avatar AndreaMiotto commented on August 20, 2024

@MartinaRogach it's very easy. You should just pass the State down the partial view and store it in a Bindable bool.
Like so:

import SwiftUI
import Combine
import PartialSheet

struct ContentView: View {
    
    @State private var modalPresented: Bool = false
    
    var body: some View {
        NavigationView {
            
            VStack {
                Text("""
                Hi, this is the Partial Sheet modifier.
                It allows you to dispaly a totally custom sheet with a relative height based on his content.
                In this way the sheet will cover the screen only for the space it will need
                """)
                Spacer()
                Button(action: {
                    self.modalPresented = true
                }, label: {
                    Text("Display the Partial Shehet")
                })
                    .padding()
                Spacer()
            }
            .padding()
            .navigationBarTitle("Partial Sheet")
        }
        .partialSheet(presented: $modalPresented) {
            PartialView(modalPresented: self.$modalPresented)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct PartialView: View {
    @Binding var modalPresented: Bool
    @State private var longer: Bool = false
    
    var body: some View {
        VStack {
            Group {
                Text("Settings Panel")
                    .font(.subheadline)
                Toggle(isOn: self.$longer) {
                    Text("Advanced")
                }
                .padding()
            }
            .frame(height: 50)
            if self.longer {
                VStack {
                    Text("More settings here...")
                }
                .frame(height: 200)
            }
                Button(action: {
                    self.modalPresented.toggle()
                }, label: {
                    Text("Close")
                })
            .frame(height: 100)
        }
    }
}

from partialsheet.

MartinaRogach avatar MartinaRogach commented on August 20, 2024

Thank you

from partialsheet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.