matteopuc / swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.
MIT License
916 stars 84 forks source link

[Unknown process name] CGAffineTransformInvert: singular matrix #24

Closed djrobby closed 4 years ago

djrobby commented 4 years ago

First off, your utility is AMAZING! Thank you so much for this! I'm running into the following warning/error:

2020-07-04 08:37:50.344351-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.
2020-07-04 08:37:50.344494-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.
2020-07-04 08:37:50.365485-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.
2020-07-04 08:37:50.561570-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.
2020-07-04 08:37:52.577640-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.
2020-07-04 08:37:52.779411-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.
2020-07-04 08:37:52.779592-0400 NavStackTest[11370:1800054] [Unknown process name] CGAffineTransformInvert: singular matrix.

After doing some digging, it seems to be originating from specifying the transitionType attribute for the NavigationStackView while having a List view inside the destination. If I leave this attribute out, there are no errors. Also, I'm not sure if this is related to an already closed issue #22. It would be greatly appreciated if you can help. Thank you in advance. Please see reproducible code see below:

import SwiftUI
import NavigationStack

struct ContentView: View {
  var body: some View {
    NavigationStackView(transitionType: .custom(.scale)) {
      ZStack {
        Color.orange.edgesIgnoringSafeArea(.all)
        HStack {
          PushView(destination:ChildView()) {
            Text("Settings")
          }
        }
      }
    }
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}

struct ChildView: View {
  @State var appName: String = ""
  var body: some View {
    ZStack {
      Color.yellow.edgesIgnoringSafeArea(.all)

      VStack {
        List {
          ForEach(0...10, id: \.self) { i in
            ListRow(item: "One")
          }
        }

        PopView { Text("Go Back") }
      }
    }
  }
}

struct ListRow: View {
  @State var item: String
  var body: some View {
    Text(self.item)
  }
}
matteopuc commented 4 years ago

Hi @djrobby! The issue you are experiencing is due to the .scale transition type . Sometimes when you "scale things" in SwiftUI you get these kind of warnings. Don't ask me why, I honestly don't know. If you change your example and try to use, for instance, .slide as transition type the warning will disappear.

struct ContentView: View {
    var body: some View {
        NavigationStackView(transitionType: .custom(.slide)) { //<-- changed here
            ZStack {
                Color.orange.edgesIgnoringSafeArea(.all)
                HStack {
                    PushView(destination:ChildView()) {
                        Text("Settings")
                    }
                }
            }
        }
    }
}

It seems that the warning occurs when you try to set the scale factor to 0 (i.e. the default scale factor for the .scale transition type). To solve this issue you can use a workaround: instead of using .scale as transition type, try to use .scale(0.001):

struct ContentView: View {
    var body: some View {
        NavigationStackView(transitionType: .custom(.scale(scale: 0.001))) { //<-- changed here
            ZStack {
                Color.orange.edgesIgnoringSafeArea(.all)
                HStack {
                    PushView(destination:ChildView()) {
                        Text("Settings")
                    }
                }
            }
        }
    }
}

This way SwiftUI won't scale the view until 0 and the warning will disappear.

djrobby commented 4 years ago

You're 100% correct. That did it! Thank you @matteopuc