Allow non-consecutive state variables (#191)

* Fix error when state variables are non-consecutive

* Update one of the demos to cause it to fail without the fix
This commit is contained in:
Jed Fox 2020-07-16 17:10:09 -04:00 committed by GitHub
parent ffa686c7dc
commit 314a6f3a5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -112,9 +112,11 @@ public final class StackReconciler<R: Renderer> {
let needsSubscriptions = compositeView.subscriptions.isEmpty let needsSubscriptions = compositeView.subscriptions.isEmpty
for (id, property) in info.properties.enumerated() { var stateIdx = 0
for property in info.properties {
if property.type is ValueStorage.Type { if property.type is ValueStorage.Type {
setupState(id: id, for: property, of: compositeView) setupState(id: stateIdx, for: property, of: compositeView)
stateIdx += 1
} else if needsSubscriptions && property.type is ObservedProperty.Type { } else if needsSubscriptions && property.type is ObservedProperty.Type {
setupSubscription(for: property, of: compositeView) setupSubscription(for: property, of: compositeView)
} }

View File

@ -40,12 +40,6 @@ public struct ColorDemo: View {
case rgb, hsb case rgb, hsb
} }
@State private var colorForm: ColorForm = .hsb
@State private var v0: String = "0.9"
@State private var v1: String = "1"
@State private var v2: String = "0.5"
let colors: [Color] = [ let colors: [Color] = [
.clear, .clear,
.black, .black,
@ -62,6 +56,12 @@ public struct ColorDemo: View {
.secondary, .secondary,
] ]
@State private var colorForm: ColorForm = .hsb
@State private var v0: String = "0.9"
@State private var v1: String = "1"
@State private var v2: String = "0.5"
public var body: some View { public var body: some View {
VStack { VStack {
Button("Input \(colorForm.rawValue.uppercased())") { Button("Input \(colorForm.rawValue.uppercased())") {