Support for environment #1
Replies: 3 comments 3 replies
-
Indeed. That's would be a really great addition, something like
BTW, not sure if this's "correct" in respect to the library, but seems to work quite well in my first tests and it seems to achieve (at least, generally speaking) to the import SwiftUI
import Perception
@Perceptible
class CounterModel: ObservableObject {
var counter: Int = 0
}
struct DetailView: View {
@EnvironmentObject private var model: CounterModel
var body: some View {
WithPerceptionTracking {
VStack {
Text("Counter: \(model.counter)")
Button(action: {
model.counter += 1
}, label: {
Text("Increment me")
})
}
}
}
}
struct ContentView: View {
let model = CounterModel()
@State private var isSheetShowing = false
var body: some View {
WithPerceptionTracking {
VStack {
Text("Counter: \(model.counter)")
Button(action: {
model.counter += 1
}, label: {
Text("Increment me")
})
Button(action: {
isSheetShowing.toggle()
}, label: {
Text("Show Modal")
})
}
}
.sheet(isPresented: $isSheetShowing, content: {
DetailView()
})
.environmentObject(model)
}
} I added the ObservableObject conformances. Not sure if this could lead to problems with the library itself. |
Beta Was this translation helpful? Give feedback.
-
Hi @PatrickDanino, we will look into back porting |
Beta Was this translation helpful? Give feedback.
-
@PatrickDanino @valvoline We've added a backport here: #13 Want to try it out? |
Beta Was this translation helpful? Give feedback.
-
Great work overall!
One question I had while perusing is whether it would be possible to also add support for environment(:) and possibly other features that are also iOS 17 specific.
We currently use this to inject context into our views.
Beta Was this translation helpful? Give feedback.
All reactions