-
Hi, I have been unable to remove the perception warnings logs when using custom Bindings, are there any ways around it? public struct MainView: View {
@Perception.Bindable var store: StoreOf<Main>
public var body: some View {
WithPerceptionTracking {
Text("hello")
.sheet(isPresented: Binding(
get: {
store.isSheetOpen // ⚠️ [Perception] Perceptible state was accessed but is not being tracked.
},
set: { value in
store.send(.sheetUpdated(isPresented: value))
}
)) {
Text("world")
}
}
}
} Sometimes using Thanks! 👉Complete Running Example👈import SwiftUI
import ComposableArchitecture
@main
struct HelloWorldApp: App {
var body: some Scene {
WindowGroup {
MainView(store: StoreOf<Main>(initialState: .init(), reducer: { Main() }))
}
}
}
@Reducer
public struct Main {
@ObservableState
public struct State: Equatable {
public var isSheetOpen: Bool = false
}
public enum Action {
case sheetUpdated(isPresented: Bool)
}
public var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case let .sheetUpdated(isPresented):
state.isSheetOpen = isPresented
return .none
}
}
}
}
public struct MainView: View {
@Perception.Bindable var store: StoreOf<Main>
public var body: some View {
WithPerceptionTracking {
Button("hello", action: {
store.send(.sheetUpdated(isPresented: true))
})
.sheet(isPresented: Binding(
get: {
store.isSheetOpen // ⚠️ [Perception] Perceptible state was accessed but is not being tracked.
},
set: { value in
store.send(.sheetUpdated(isPresented: value))
}
)) {
Text("world")
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @wes-nz, unfortunately there's nothing we can do (as far as we know) to detect when bindings are accessed in view bodies vs out of view bodies. Since TCA can control the creation of bindings we perform extra work in them to disable perception checks. If you really do want to create your own ad hoc bindings, then you can wrap state access inside the However, I would highly recommend against creating ad hoc bindings like this. Not only does it run afoul of things like perception checking, but it can also breaking SwiftUI animations in subtle ways. For whatever reason, deriving bindings via dynamic member lookup tends to play better with SwiftUI's tools. In your case you could simply do |
Beta Was this translation helpful? Give feedback.
Hi @wes-nz, unfortunately there's nothing we can do (as far as we know) to detect when bindings are accessed in view bodies vs out of view bodies. Since TCA can control the creation of bindings we perform extra work in them to disable perception checks.
If you really do want to create your own ad hoc bindings, then you can wrap state access inside the
get
with _withoutPerceptionChecking to disable perception checking for a lexical scope.However, I would highly recommend against creating ad hoc bindings like this. Not only does it run afoul of things like perception checking, but it can also breaking SwiftUI animations in subtle ways. For whatever reason, deriving bindings via dynamic mem…