Posts

Post not yet marked as solved
0 Replies
462 Views
Currently in my project, I have a navigation stack where my parent ContentView contains a BackgroundViewModel that I pass down to child views as an @EnvironmentObject. The BackgroundVIewModel is in charge of rotating between a list of colors to act as a background for the whole navigation stack To rotate through the list of colors, I have a Timer that publishes to the ContentView when to change the background color using Swift .onReceive(backgroundVM.timer, perform: { _ in withAnimation(.easeInOut(duration: 1.5)) { backgroundVM.setColor() } } This creates an animation loop that changes the background color for all of the child views. Everything works as expected until I segue from View2 to View3 using a NavigationLink. The animation loop causes the BackgroundViewModel @EnvironmentObject to become nil in the middle of the segue. I know this because when I comment out the withAnimation call in the ContentView, the BackgroundViewModel is passed correctly during the segue. This is the error I receive: Swift No ObservableObject of type BackgroundViewModel found. A View.environmentObject(_:) for BackgroundViewModel may be missing as an ancestor of this view. This animated color rotation of the background worked in iOS 14.4 but as soon as I updated to 14.5 it fell apart. I'm thinking it is because of this update to NavigationLinks (from iOS 14.5 release notes) The destination of NavigationLink that only differs by local state now resets that state when switching between links as expected. (72117345) Below is my sample code that I reference above: Swift import SwiftUI class BackgroundViewModel: ObservableObject { @Published var backgroundColor: Color = .orange @Published var colorIndex: Int = 0 { willSet { backgroundColor = colors[newValue] } } var colors: [Color] = [.orange, .green, .purple] var timer = Timer.publish(every: 1.5, on: .main, in: .common).autoconnect() func setColor() { if colorIndex + 1 == colors.count { colorIndex = 0 } else { colorIndex += 1 } } } struct ContentView: View { @StateObject var backgroundVM = BackgroundViewModel() @State var presentNext: Bool = false var body: some View { NavigationView { VStack{ Text("Hello, world!") .padding() NavigationLink( destination: View2(), isActive: $presentNext) { Button { presentNext = true } label: { Text("Navigate") } } } .background(backgroundVM.backgroundColor) } .environmentObject(backgroundVM) .onReceive(backgroundVM.timer, perform: { _ in withAnimation(.easeInOut(duration: 1.5)) { backgroundVM.setColor() } }) } } struct View2: View { @EnvironmentObject var viewEnvObj: BackgroundViewModel @State var presentNext: Bool = false var body: some View { VStack { Text("View 2") NavigationLink( destination: View3(), isActive: $presentNext) { Button { presentNext = true } label: { Text("Navigate") } } } .background(viewEnvObj.backgroundColor) } } struct View3: View { @EnvironmentObject var backgroundVM: BackgroundViewModel var body: some View { VStack { Text("View 3") } .background(backgroundVM.backgroundColor) } }
Posted
by nfarrell.
Last updated
.
Post not yet marked as solved
0 Replies
378 Views
Hello, I plugged in a friends iPhone 11 to see if ARKit supports the 120fps front camera when using an ARFaceTrackingConfiguration and the highest available AVFrameRate I could find was 60fps. Does anybody know if they will add the capability to use the ARFaceTrackingConfiguration at 120fps? Any help would be appreciated.
Posted
by nfarrell.
Last updated
.