AndreaMiotto / PartialSheet

A SwiftUI Partial Sheet fully customizable with dynamic height

Home Page:https://github.com/AndreaMiotto/PartialSheet/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

values in the PartialSheet will not reflect updates

rny opened this issue · comments

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.

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()
            })
        }
    }
}