diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 25ebca8f..02b4c14a 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -53,6 +53,7 @@ /* End PBXFileReference section */ /* Begin PBXFileSystemSynchronizedRootGroup section */ + 27C4C20C2D8178CF00511552 /* Examples */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Examples; sourceTree = ""; }; 27E6C4F62D2842D80010502F /* Configurations */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); name = Configurations; path = ../Configurations; sourceTree = ""; }; /* End PBXFileSystemSynchronizedRootGroup section */ @@ -130,6 +131,7 @@ 27D49DF92BA604FB00F6E2E2 /* HostingExample */ = { isa = PBXGroup; children = ( + 27C4C20C2D8178CF00511552 /* Examples */, 27D49DFA2BA604FB00F6E2E2 /* AppDelegate.swift */, 27D49DFC2BA604FB00F6E2E2 /* SceneDelegate.swift */, 27D49DFE2BA604FB00F6E2E2 /* ViewController.swift */, @@ -186,6 +188,9 @@ ); dependencies = ( ); + fileSystemSynchronizedGroups = ( + 27C4C20C2D8178CF00511552 /* Examples */, + ); name = HostingExample; packageProductDependencies = ( 27D49E0D2BA60AF600F6E2E2 /* OpenSwiftUI */, diff --git a/Example/HostingExample/Examples/AppearanceActionModifierExample.swift b/Example/HostingExample/Examples/AppearanceActionModifierExample.swift new file mode 100644 index 00000000..b25e41c6 --- /dev/null +++ b/Example/HostingExample/Examples/AppearanceActionModifierExample.swift @@ -0,0 +1,28 @@ +// +// AppearanceActionModifierExample.swift +// HostingExample + +#if OPENSWIFTUI +import OpenSwiftUI +#else +import SwiftUI +#endif +import Foundation + +struct AppearanceActionModifierExample: View { + @State private var first = true + + var body: some View { + Color(uiColor: first ? .red : .blue) + .onAppear { + print("View appear") + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + first.toggle() + } + } + .onDisappear { + print("View disappear") + } + .id(first) + } +} diff --git a/Example/HostingExample/Examples/ConditionalContentExample.swift b/Example/HostingExample/Examples/ConditionalContentExample.swift new file mode 100644 index 00000000..0252ec7f --- /dev/null +++ b/Example/HostingExample/Examples/ConditionalContentExample.swift @@ -0,0 +1,42 @@ +// +// ConditionalContentExample.swift +// HostingExample + +#if OPENSWIFTUI +import OpenSwiftUI +#else +import SwiftUI +#endif +import Foundation + +// FIXME +struct ConditionalContentExample: View { + @State private var first = true + + var body: some View { + if first { + Color.red + .onAppear { + print("Red appear") + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + first.toggle() + } + } + .onDisappear { + print("Red disappear") + } + .id(first) + } else { + Color.blue + .onAppear { + print("Blue appear") + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + first.toggle() + } + } + .onDisappear { + print("Blue disappear") + } + } + } +} diff --git a/Example/HostingExample/Examples/NamespaceExample.swift b/Example/HostingExample/Examples/NamespaceExample.swift new file mode 100644 index 00000000..84afa47a --- /dev/null +++ b/Example/HostingExample/Examples/NamespaceExample.swift @@ -0,0 +1,29 @@ +// +// NamespaceExample.swift +// HostingExample + +#if OPENSWIFTUI +import OpenSwiftUI +#else +import SwiftUI +#endif +import Foundation + +struct NamespaceExample: View { + @State private var first = true + @Namespace private var id + + var body: some View { + Color(uiColor: first ? .red : .blue) + .onAppear { + print("View appear \(id)") + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + first.toggle() + } + } + .onDisappear { + print("View disappear \(id)") + } + .id(first) + } +} diff --git a/Example/HostingExample/ViewController.swift b/Example/HostingExample/ViewController.swift index 9c39f805..25b5d955 100644 --- a/Example/HostingExample/ViewController.swift +++ b/Example/HostingExample/ViewController.swift @@ -39,37 +39,8 @@ final class EntryViewController: UIViewController { } } -// TODO: Known issue -// 1. State toggle crash -// 2. pop - UIHostingView deinit crash / onDisappear -// 3. if else builder issue struct ContentView: View { - @State private var first = true - var body: some View { -// if first { - Color(uiColor: first ? .red : .blue) - .onAppear { - print("View appear") - DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - first.toggle() - } - } - .onDisappear { - print("Red disappear") - } - .id(first) -// } else { -// Color.blue -// .onAppear { -// print("Blue appear") -// DispatchQueue.main.asyncAfter(deadline: .now() + 1) { -// first.toggle() -// } -// } -// .onDisappear { -// print("Blue disappear") -// } -// } + AppearanceActionModifierExample() } } diff --git a/Tests/OpenSwiftUICoreTests/Data/NamespaceTests.swift b/Tests/OpenSwiftUICoreTests/Data/NamespaceTests.swift new file mode 100644 index 00000000..64ed394b --- /dev/null +++ b/Tests/OpenSwiftUICoreTests/Data/NamespaceTests.swift @@ -0,0 +1,31 @@ +// +// NamespaceTests.swift +// OpenSwiftUICoreTests + +import Testing +import OpenSwiftUICore +import Foundation + +struct NamespaceTests { + @Test + func example() { + struct ContentView: View { + @State private var first = false + @Namespace private var id + + var body: some View { + Color(uiColor: first ? .red : .blue) + .onAppear { + print("View appear") + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + first.toggle() + } + } + .onDisappear { + print("Red disappear") + } + .id(first) + } + } + } +}