From ce7ae7442bb580918f3c9c3ba33283652bf73a7e Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 9 Nov 2023 11:35:53 +0800 Subject: [PATCH] Add ContentView_ FB13341321 --- .../ContentView_FB13341321.swift | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Tests/OpenSwiftUI_UITests/ContentView_FB13341321.swift diff --git a/Tests/OpenSwiftUI_UITests/ContentView_FB13341321.swift b/Tests/OpenSwiftUI_UITests/ContentView_FB13341321.swift new file mode 100644 index 00000000..0d17f40a --- /dev/null +++ b/Tests/OpenSwiftUI_UITests/ContentView_FB13341321.swift @@ -0,0 +1,105 @@ +// +// ContentView.swift +// Test +// +// Created by Kyle on 2023/11/6. +// + +// (4 toggles: C1T1 C1T2 C2T1 C2T2 - C1T1&C2T1 use the same truth, C1T2&C2T2 use the same truth ) +// macOS 14 behavior with SwiftUI +// C1T1's UI will only be updated at most 1 time if we only tap T1. +// C2T1 will always reflect the latest value in UI. A tap for T2 will make C1T1's UI up to data. +// Tap on C1T2 or C2T2 will update both toggle at the same time. (Expected) +// +// iOS 17 behavior with SwiftUI +// Tap on C2T1 will only update toggle C2T1 while the UI of C1T1 remains the same. +// Tap on C1T1 will update both toggle(C1T1 & C2T1) at the same time. (Expected) +// Tap on C1T2 or C2T2 will update both toggle at the same time. (Expected) +// +// iOS 15.5 behavior with SwiftUI +// Tap on C1T1 or C2T1 will update both toggle at the same time. (Expected) +// Tap on C1T2 or C2T2 will update both toggle at the same time. (Expected) +// But one is with transactino and the other is not. + +import SwiftUI +import Observation + +public struct Section: View { + + public let content: AnyView + + public init( + @ViewBuilder content: @escaping () -> some View + ) { + + self.content = content().eraseToAnyView() + } + + public var body: some View { + content + } +} + +@resultBuilder +public struct SectionBuilder { + public static func buildBlock(_ sections: Section...) -> [Section] { + sections + } +} +public struct Container: View { + private let builder: () -> [Section] + + public init( + @SectionBuilder builder: @escaping () -> [Section] + ) { + self.builder = builder + } + + public var body: some View { + let sections = builder() + return sections[0] + } +} + +public struct Container2: View { + private let sections: [Section] + + public init( + sections: [Section] = [] + ) { + self.sections = sections + } + + public var body: some View { + return sections[0] + } +} + +struct ContentView: View { + @AppStorage("Test") private var toggle = false + @State private var toggle2 = false + var body: some View { + Container { + Section { + Toggle("Demo Toggle", isOn: $toggle) + Toggle("Demo Toggle2", isOn: $toggle2) + } + } + Container2(sections: [ + Section { + Toggle("Demo Toggle", isOn: $toggle) + Toggle("Demo Toggle2", isOn: $toggle2) + } + ]) + } +} + +extension View { + func eraseToAnyView() -> AnyView { + AnyView(self) + } +} +#Preview { + ContentView() + .padding(20) +}