UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Ultimate Portfolio App: Editing a Project Dismiss immediately

Forums > SwiftUI

RocketSim Recording - iPhone 12 Pro - 2020-11-16 21 06 28

So i try to edit a project in the view created by https://www.hackingwithswift.com/plus/ultimate-portfolio-app/editing-projects

And whenever i do a change in the project, insert a new letter in the textField or tap the color. The EditProjectView automatically dismisses.

I'm definitively not sure what went wrong.

In ProjectsView i use the header like:

List {
                ForEach(projects.wrappedValue) { project in
                    Section(header: ProjectHeaderView(project: project)) {
                    ...
                    }

Then the ProjectHeaderView is defined like:

struct ProjectHeaderView: View {
    @ObservedObject var project: Project

    var body: some View {
        HStack {
            VStack(alignment: .leading) {
                Text(project.projectTitle)

                ProgressView(value: project.completionAmount)
                    .accentColor(Color(project.projectColor))
            }

            Spacer()

            NavigationLink(destination: EditProjectView(project: project)) {
                Image(systemName: "square.and.pencil")
                    .imageScale(.large)
            }
        }
        .padding(.bottom, 10)
    }
}

Finally the EditProjectView starts with code like:

struct EditProjectView: View {
    let project: Project

    @State var title: String
    @State var detail: String
    @State var color: String
    @State var isShowingAlert: Bool = false

    @Environment(\.presentationMode) var presentationMode
    @EnvironmentObject var dataController: DataController

    var colorColumns: [GridItem] = [GridItem(.adaptive(minimum: 44))]

    init(project: Project) {
        self.project = project

        self._title = State(wrappedValue: project.projectTitle)
        self._detail = State(wrappedValue: project.projectDetail)
        self._color = State(wrappedValue: project.projectColor)
    }

    var body: some View {
        Form {
            Section(header: Text("Basic settings")) {
                TextField("Title", text: $title.onChange(update))
                TextField("Description of the project", text: $detail.onChange(update))
            }
...

I don't get it, has anyone found an issue like this?

4      

I am also having this issue. Were you able to figure it out?

I was able to narrow it down to the update() call being what triggers this issue. Since it updates the Project object, it'll also tell all objects listening for changes to the Project object.

ProjectHeaderView listens to changes on the Project object so it'll recreate its body property. I think this is what causes the EditProjectView to disappear since the ProjectHeaderView is its parent view.

3      

How does you update method look like?

3      

I contacted Paul and he mentioned it was a new bug in iOS 14.2 which he reported to apple.

He also mentioned that:

if you rotate to landscape then back to portrait again it works just fine, or if you use any 14.1 simulator it works fine

9      

It seems to stll be there in 14.4 simulator and on my daily driver 11 Pro Max 14.4.2.

3      

Same with iPhone 12 Pro v14.4 simulator, Xcode 12.4, on Catalina 10.15.7

Rotating the simulator causes immediate dismissal for me - doesn't fix the problem.

I think @Luissh22 is probably right.

3      

@twostraws  Site AdminHWS+

This should be resolved in Xcode 12.5.

3      

The bug is still present on iOS 15.2 :/

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.