我将文本字段的 FocusState 属性传递给子视图。这按预期工作。在这个子视图中,我想让预览正常工作,但是我似乎无法为 Focusstate 设置恒定值。有人有想法吗?
struct MainContentView: View {
@FocusState private var focusedField: Bool
var body: some View {
ScoreView(focussed: $focusedField)
}
}
struct ScoreView: View {
@FocusState.Binding var focussed: Bool
var body: some View {
someSubView(focussed: $focussed)
}
}
struct ScoreView_Previews: PreviewProvider {
static var previews: some View {
ScoreView(focussed: ????????). <- here
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够为状态属性设置一个常量,就像 @State 布尔属性一样,但我收到消息:
类型“FocusState.Binding”没有成员“constant”