From 92ceba203f7aa6dfdf853f08f582a17094656142 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 8 Jul 2020 00:14:02 +0100 Subject: [PATCH 1/7] Avoid AnyView in the Counter code It's not needed there as `ViewBuilder` is smarter now. --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8c1b602ca..eca984766 100644 --- a/README.md +++ b/README.md @@ -45,15 +45,16 @@ struct Counter: View { let limit: Int var body: some View { - count < limit ? - AnyView( - VStack { - Button("Increment") { count += 1 } - Text("\(count)") - } - ) : AnyView( - VStack { Text("Limit exceeded") } - ) + if count < limit { + VStack { + Button("Increment") { count += 1 } + Text("\(count)") + } + .onAppear { print("Counter.VStack onAppear") } + .onDisappear { print("Counter.VStack onDisappear") } + } else { + VStack { Text("Limit exceeded") } + } } } ``` From 4ecc657ade7159c8f14764d293b3a99835e46f8a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 8 Jul 2020 00:14:44 +0100 Subject: [PATCH 2/7] Update Counter.swift --- Sources/TokamakDemo/Counter.swift | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Sources/TokamakDemo/Counter.swift b/Sources/TokamakDemo/Counter.swift index 78d7d4766..92627efb0 100644 --- a/Sources/TokamakDemo/Counter.swift +++ b/Sources/TokamakDemo/Counter.swift @@ -27,16 +27,15 @@ public struct Counter: View { let limit: Int public var body: some View { - count < limit ? - AnyView( - VStack { - Button("Increment") { count += 1 } - Text("\(count)") - } - .onAppear { print("Counter.VStack onAppear") } - .onDisappear { print("Counter.VStack onDisappear") } - ) : AnyView( - VStack { Text("Limit exceeded") } - ) + if count < limit { + VStack { + Button("Increment") { count += 1 } + Text("\(count)") + } + .onAppear { print("Counter.VStack onAppear") } + .onDisappear { print("Counter.VStack onDisappear") } + } else { + VStack { Text("Limit exceeded") } + } } } From 57ffd50554e51ffae80fd5234e49b4153ea9f7b9 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 8 Jul 2020 00:21:02 +0100 Subject: [PATCH 3/7] Add @ViewBuilder annotation on `View.body` --- Sources/TokamakCore/Views/View.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TokamakCore/Views/View.swift b/Sources/TokamakCore/Views/View.swift index 12b734af5..d20b81c15 100644 --- a/Sources/TokamakCore/Views/View.swift +++ b/Sources/TokamakCore/Views/View.swift @@ -18,7 +18,7 @@ public protocol View { associatedtype Body: View - var body: Self.Body { get } + @ViewBuilder var body: Self.Body { get } } extension Never: View { From 0c92f0b864fbbd4159f14e3816d4d636e2baa2ee Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 16 Jul 2020 18:36:40 +0100 Subject: [PATCH 4/7] Print xcode version in ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 153637566..0a64fb27d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,5 +26,6 @@ jobs: run: | set -ex sudo xcode-select --switch /Applications/Xcode_12_beta.app/Contents/Developer/ + xcodebuild -version cd "TokamakDemo Native" xcodebuild -scheme macOS From 72f5119248f26df61c9d9926603c50538a56050c Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 16 Jul 2020 18:43:09 +0100 Subject: [PATCH 5/7] _ConditionalContent body:Never for compatibility --- Sources/TokamakCore/Views/ViewBuilder.swift | 21 ++++++++++++--------- Sources/TokamakDOM/Shapes/Path.swift | 2 +- Sources/TokamakDOM/Views/SecureField.swift | 8 ++++---- Sources/TokamakDOM/Views/TextField.swift | 8 ++++---- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Sources/TokamakCore/Views/ViewBuilder.swift b/Sources/TokamakCore/Views/ViewBuilder.swift index 36a4e5669..301750530 100644 --- a/Sources/TokamakCore/Views/ViewBuilder.swift +++ b/Sources/TokamakCore/Views/ViewBuilder.swift @@ -34,25 +34,28 @@ public struct _ConditionalContent: View let storage: Storage - @ViewBuilder - public var body: some View { + public var body: Never { + neverBody("_ConditionContent") + } +} + +extension _ConditionalContent: GroupView { + public var children: [AnyView] { switch storage { case let .trueContent(view): - view + return [AnyView(view)] case let .falseContent(view): - view + return [AnyView(view)] } } } -// FIXME: Remove type erasure when https://github.com/swiftwasm/swift/issues/1379 -// is resolved extension Optional: View where Wrapped: View { - public var body: AnyView { + public var body: some View { if let view = self { - return AnyView(view) + view } else { - return AnyView(EmptyView()) + EmptyView() } } } diff --git a/Sources/TokamakDOM/Shapes/Path.swift b/Sources/TokamakDOM/Shapes/Path.swift index 752fb7cbb..801c38652 100644 --- a/Sources/TokamakDOM/Shapes/Path.swift +++ b/Sources/TokamakDOM/Shapes/Path.swift @@ -50,7 +50,7 @@ extension Path: ViewDeferredToRenderer { "rx": "\(roundedRect.cornerSize.width)", "ry": "\(roundedRect.style == .continuous ? roundedRect.cornerSize.width : roundedRect.cornerSize.height)", ] - .merging(stroke, uniquingKeysWith: uniqueKeys))) + .merging(stroke, uniquingKeysWith: uniqueKeys))) case let .stroked(stroked): return stroked.path.svgFrom(storage: stroked.path.storage, strokeStyle: stroked.style) case let .trimmed(trimmed): diff --git a/Sources/TokamakDOM/Views/SecureField.swift b/Sources/TokamakDOM/Views/SecureField.swift index d500afc79..0a8d4f604 100644 --- a/Sources/TokamakDOM/Views/SecureField.swift +++ b/Sources/TokamakDOM/Views/SecureField.swift @@ -29,10 +29,10 @@ extension SecureField: ViewDeferredToRenderer where Label == Text { ], listeners: [ "keypress": { event in if event.key == "Enter" { proxy.onCommit() } }, "input": { event in - if let newValue = event.target.object?.value.string { - proxy.textBinding.wrappedValue = newValue - } - }, + if let newValue = event.target.object?.value.string { + proxy.textBinding.wrappedValue = newValue + } + }, ])) } } diff --git a/Sources/TokamakDOM/Views/TextField.swift b/Sources/TokamakDOM/Views/TextField.swift index f1df76314..7222818c2 100644 --- a/Sources/TokamakDOM/Views/TextField.swift +++ b/Sources/TokamakDOM/Views/TextField.swift @@ -44,10 +44,10 @@ extension TextField: ViewDeferredToRenderer where Label == Text { "blur": { _ in proxy.onEditingChanged(false) }, "keypress": { event in if event.key == "Enter" { proxy.onCommit() } }, "input": { event in - if let newValue = event.target.object?.value.string { - proxy.textBinding.wrappedValue = newValue - } - }, + if let newValue = event.target.object?.value.string { + proxy.textBinding.wrappedValue = newValue + } + }, ])) } } From 65527369a2bc87c09faa024f65cb69d375d27d57 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 16 Jul 2020 18:49:22 +0100 Subject: [PATCH 6/7] Fix macOS compilation issue --- Sources/TokamakDemo/OutlineGroupDemo.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TokamakDemo/OutlineGroupDemo.swift b/Sources/TokamakDemo/OutlineGroupDemo.swift index bcc4627d8..34266529b 100644 --- a/Sources/TokamakDemo/OutlineGroupDemo.swift +++ b/Sources/TokamakDemo/OutlineGroupDemo.swift @@ -27,7 +27,7 @@ struct File: Identifiable { let children: [File]? } -@available(OSX 10.16, *) +@available(OSX 10.16, iOS 14, *) struct OutlineGroupDemo: View { let fs: [File] = [ .init(id: 0, name: "Users", children: [ From 9d3c29a10f1b05ce824cebb3602a208f2e5adb70 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 16 Jul 2020 18:58:42 +0100 Subject: [PATCH 7/7] Build for macOS on CI --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a64fb27d..f81025480 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,4 +28,5 @@ jobs: sudo xcode-select --switch /Applications/Xcode_12_beta.app/Contents/Developer/ xcodebuild -version cd "TokamakDemo Native" - xcodebuild -scheme macOS + xcodebuild -scheme iOS -destination 'generic/platform=iOS' \ + CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO