Comments (5)
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.
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.
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.
@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.
Thank you
from partialsheet.
Related Issues (20)
- PartialSheet disappears automatically after Alert is presented
- PartialSheet 3: PSButton action is never called in ListExample
- PartialSheet Crash when using multiple horizontal scroll views HOT 2
- Partial Sheet over tab bar
- The `DragGesture.onEnded(_:)` not be called up. HOT 1
- PartialSheet auto close when openURL in sheet content with `@Environment(\.scenePhase)`
- Could not find module 'PartialSheet' for target 'x86_64-apple-ios-simulator'; found: arm64-apple-ios-simulator HOT 1
- Can't scroll with WKWebView inside the PartialSheet
- TabView over the PartialSheet
- Partial sheet on top of .sheet() gets cut off HOT 1
- How to prevent PartialSheet from closing when clicking on the background or dragging down? HOT 1
- onDismiss in version 3+ HOT 1
- Crash on tap to show the Partial sheet HOT 2
- macOS Support Mentioned in README but Not in Package.swift
- Partial Sheet Not Triggering When Using @Published Variable in ViewModel HOT 1
- Sticky Footer In ScrollView Partial Sheet HOT 1
- Simple partialSheet with type .scrollView doesn't work HOT 1
- Issue in updating the state variable's value within the partial sheet's content
- UIKit can use it?
- How to prevent dismiss on swipe / background tap HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from partialsheet.