values in the PartialSheet will not reflect updates
rny opened this issue · comments
rny commented
create a new test project
app.swift
import SwiftUI
import PartialSheet
@main
struct testApp: App {
let sheetManager: PartialSheetManager = PartialSheetManager()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(sheetManager)
}
}
}
ContentView.swift
import SwiftUI
import PartialSheet
struct ContentView: View {
@EnvironmentObject var partialSheet : PartialSheetManager
@State private var selectedStrength = 0
var body: some View {
VStack {
Text("Value \(selectedStrength)")
.font(.headline)
.padding()
Button(action: {
selectedStrength = selectedStrength + 1
}, label: {
Text("Add")
.padding()
})
Button(action: {
self.partialSheet.showPartialSheet({
print("dismissed")
}) {
VStack {
Text("Value \(selectedStrength)")
.font(.headline)
.padding()
Button(action: {
selectedStrength = selectedStrength + 1
}, label: {
Text("Add")
.padding()
})
}
}
}, label: {
Text("Show Partial Sheet")
})
}
.addPartialSheet()
}
}
click "Add" works in the content view. The same code not working in the partialsheet. The value is updated but keep showing the old value.
Andre commented
This is not a problem of PartialSheet, but about how you are using SwiftUI.
You should use a bindable variable for you sum.
struct InsideView: View {
@Binding var selectedStrength: Int
var body: some View {
VStack {
Text("Value \(selectedStrength)")
.font(.headline)
.padding()
Button(action: {
selectedStrength += 1
}, label: {
Text("Add")
.padding()
})
}
}
}