Giter Club home page Giter Club logo

Comments (5)

lukeredpath avatar lukeredpath commented on June 11, 2024

It looks like you’re missing WithPerceptionTracking inside your navigation stack’s destination closure, so iOS 16 cannot detect changes to the state inside the presented view.

from swift-composable-architecture.

 avatar commented on June 11, 2024

It looks like you’re missing WithPerceptionTracking inside your navigation stack’s destination closure, so iOS 16 cannot detect changes to the state inside the presented view.

@lukeredpath

Thank you for your response. Based on your suggestion, I wrapped the navigation stack's destination closure with WithPerceptionTracking. However, there have been no changes.

スクリーンショット 2024-03-30 8 16 54

I tried a different approach. I replaced NavigationStack with NavigationStackStore, and then it worked correctly on iOS16. I think there might be a slight difference between NavigationStack and NavigationStackStore.

NavigationStackStore(self.store.scope(state: \.path, action: \.path)) {
                    EmptyView()
                } destination: { store in
                    SwitchStore(store) {
                        switch $0 {
                        case .demo:
                            CaseLet(/RootStore.Path.State.demo,
                                     action: RootStore.Path.Action.demo) { _store in
                                DemoView(store: _store)
                            }
                        }
                    }
                }

from swift-composable-architecture.

lukeredpath avatar lukeredpath commented on June 11, 2024

@tsudo-kiroru the purple warnings are your clue that you're definitely missing a WithPerceptionTracking somewhere, that's why your view is not responding to state changes on iOS 16. Try expanding the backtrace of that error.

from swift-composable-architecture.

 avatar commented on June 11, 2024

@tsudo-kiroru the purple warnings are your clue that you're definitely missing a WithPerceptionTracking somewhere, that's why your view is not responding to state changes on iOS 16. Try expanding the backtrace of that error.

@lukeredpath
Thank you for your reply. Based on your suggestion, I fixed my code as following below. I wrapped NavigationStack destination scope with WithPerceptionTracking. Then, the purple warnings disappeared. So I guess that state must be tracked.

NavigationStack(path: $store.scope(state: \.path, action: \.path)
                ) {
                    EmptyView()
                } destination: { destination in
                    WithPerceptionTracking {
                        let scope = destination.case
                        switch scope {
                        case let .demo(store):
                            DemoView(store: store)
                        }
                    }
                }

However, the navigation feature does not work correctly on iOS 16. There seems to be a difference between iOS 16 and iOS 17(As same as capturing movie).
It becomes harder to find the problem because no errors or warnings occur.

from swift-composable-architecture.

mbrandonw avatar mbrandonw commented on June 11, 2024

Hi @tsudo-kiroru, I believe this is just a problem with vanilla SwiftUI in general. The following code snippet works fine in iOS 17, but does not work in iOS 16:

class Model: ObservableObject {
  @Published var values: [Int] = []
}

struct ParentView: View {
  @StateObject var model = Model()

  var body: some View {
    Form {
      Button("Open") {
        model.values.append(1)
      }
      .sheet(
        isPresented: Binding(
          get: { !model.values.isEmpty },
          set: { if !$0 { model.values = [] } }
        )
      ) {
        NavigationStack(path: $model.values) {
          EmptyView()
          .navigationDestination(for: Int.self) { int in
            Form {
              Button("Push") {
                model.values.append(.random(in: 0...1_000))
              }
            }
          }
        }
      }
    }
  }
}

Since this is not a TCA issue I am going to convert it to a discussion, but please feel free to continue the conversation over there.

from swift-composable-architecture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.