Saturday, November 7, 2026
HomeiOS Developmentios - @Printed property change on underlying view detaches fullscreen view

ios – @Printed property change on underlying view detaches fullscreen view

[ad_1]

I’ve a @StateObject that comprises a @Printed property consumer. My consumer has an isPremium variable on it, which signifies whether or not it is a premium account or not (topic to in-app subscription standing). Sure views are proven/hidden relying on this worth. A really simplified model of my view could be like this:

struct MyView: View {
  @State non-public var showPremium = false
  @StateObject non-public var auth = Auth.shared // Incorporates Printed consumer property
  non-public var username: String {
    guard let consumer = auth.consumer else {
      return ""
    }
    return "@" + consumer.username
  }

  var physique: some View {
    NavigationView {
      ScrollView {
        // Some gadgets
      }
      .toolbar {
        ToolbarItem(placement: .navigationBarTrailing) {
          if auth.consumer.isPremium == false {
            PremiumButtonView()
          }
        }
      }
      .fullScreenCover(
        isPresented: $showPremium,
        content material: {
          SubscriptionView()
        }
      )
    }
  }
}

As you possibly can see, I’ve a SubscriptionView offered modally utilizing fullScreenCover that handles the Subscription a part of the app. When a consumer subscribes, it updates the consumer property. This then makes MyView refresh its physique. This by some means detaches the offered SubscriptionView such that I can not shut it.

I’ve tried passing the dismiss @Surroundings property to the subscription handler, such that it tries to dismiss the view earlier than it updates the consumer property however that did not work.

How can I cease this from taking place?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments