Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/Data/State/StoredLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package class StoredLocationBase<Value>: AnyLocation<Value>, Location, @unchecke
return false
}
box.$data.access { data in
_ = data.savedValue.removeFirst()
_ = data.savedValue.removeLast()
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Testing
import OpenSwiftUITestsSupport

@MainActor
struct StateCompatibilityTests {
@Test
func appear() async throws {
Expand Down Expand Up @@ -32,4 +33,41 @@ struct StateCompatibilityTests {
)
}
}

@Test("StoredLocationBase.BeginUpdate.removeLast verify")
func nestedStateUpdate() async throws {
@MainActor
enum Helper {
static var values: [Int] = []
static var valueChanges: [[Int]] = []
}

struct ContentView: View {
@State private var value = 0

var body: some View {
let _ = Helper.values.append(value)
Color.white
.onAppear {
value = 1
value = 2
withAnimation {
value = 3
value = 4
}
}
.onChange(of: value) { oldValue, newValue in
Helper.valueChanges.append([oldValue, newValue])
}
}
}

try await triggerLayoutWithWindow(expectedCount: 0) { _ in
PlatformHostingController(
rootView: ContentView()
)
}
#expect(Helper.values == [0, 2, 4])
#expect(Helper.valueChanges == [[0, 2], [2, 4]])
}
}
Loading