From 524fd5a38876e2f678449d48a1020f558c9b376a Mon Sep 17 00:00:00 2001 From: Jon Lipsky Date: Thu, 11 Jul 2019 11:11:38 -0500 Subject: [PATCH] =?UTF-8?q?Added=20support=20for=20=E2=80=9CViewRepresenta?= =?UTF-8?q?ble=E2=80=9D=20on=20iOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HotUI.sln | 136 +++++++++--------- sample/HotUI.Samples/Comparisons/Section4b.cs | 2 +- sample/HotUI.Samples/MainPage.cs | 5 +- sample/HotUI.iOS.Sample/AppDelegate.cs | 52 ++++++- .../HotUI.iOS.Sample/HotUI.iOS.Sample.csproj | 1 + sample/HotUI.iOS.Sample/Main.cs | 2 +- .../Handlers/ViewRepresentableHandler.cs | 32 +++++ src/HotUI.iOS/HotUI.iOS.csproj | 2 + src/HotUI.iOS/UI.cs | 1 + src/HotUI.iOS/UIViewRepresentable.cs | 22 +++ src/HotUI/Controls/ViewRepresentable.cs | 54 +++++++ 11 files changed, 237 insertions(+), 72 deletions(-) create mode 100644 src/HotUI.iOS/Handlers/ViewRepresentableHandler.cs create mode 100644 src/HotUI.iOS/UIViewRepresentable.cs create mode 100644 src/HotUI/Controls/ViewRepresentable.cs diff --git a/HotUI.sln b/HotUI.sln index aa4d1a1e..5f04390e 100644 --- a/HotUI.sln +++ b/HotUI.sln @@ -37,15 +37,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotUI.Android", "src\HotUI. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{586C3CCB-82A5-47F0-A099-B9A31BB4EA88}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotUI.Tests", "tests\HotUI.Tests\HotUI.Tests.csproj", "{EA098E78-E56C-43B2-9D78-D4565EC04D09}" +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "HotUI.UWP.Sample", "sample\HotUI.UWP.Sample\HotUI.UWP.Sample.csproj", "{FF9663EE-49AF-41D8-A25F-1C56C67274D3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotUI.UWP.Sample", "sample\HotUI.UWP.Sample\HotUI.UWP.Sample.csproj", "{35664234-EB75-47BA-A082-9F96BDF6FC92}" +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "HotUI.WPF.Sample", "sample\HotUI.WPF.Sample\HotUI.WPF.Sample.csproj", "{5ACE2391-4864-4EE7-80D8-F7464C6F2D24}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotUI.WPF.Sample", "sample\HotUI.WPF.Sample\HotUI.WPF.Sample.csproj", "{0FC87DE5-B5E5-4846-894B-824497118143}" +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "HotUI.UWP", "src\HotUI.UWP\HotUI.UWP.csproj", "{8BC94226-339B-4183-9AC2-EB3FD0D5D811}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotUI.UWP", "src\HotUI.UWP\HotUI.UWP.csproj", "{2D337300-B3E9-4A36-8387-76A9A1100C5B}" +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "HotUI.WPF", "src\HotUI.WPF\HotUI.WPF.csproj", "{425DF4F6-3C01-4B6A-A678-701F36919C4D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotUI.WPF", "src\HotUI.WPF\HotUI.WPF.csproj", "{F8BA5DE0-AEC0-4423-B036-5F9157E939D0}" +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "HotUI.Tests", "tests\HotUI.Tests\HotUI.Tests.csproj", "{EDC997D0-2358-416F-A628-5DFD85728060}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -214,64 +214,64 @@ Global {1E8FBBC2-9E06-4960-A116-65CDEFEFE11D}.Release|iPhone.Build.0 = Release|Any CPU {1E8FBBC2-9E06-4960-A116-65CDEFEFE11D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {1E8FBBC2-9E06-4960-A116-65CDEFEFE11D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Debug|iPhone.Build.0 = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Release|Any CPU.Build.0 = Debug|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Release|iPhone.ActiveCfg = Release|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Release|iPhone.Build.0 = Release|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {EA098E78-E56C-43B2-9D78-D4565EC04D09}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Debug|iPhone.Build.0 = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Release|Any CPU.Build.0 = Debug|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Release|iPhone.ActiveCfg = Release|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Release|iPhone.Build.0 = Release|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Debug|Any CPU.ActiveCfg = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Debug|Any CPU.Build.0 = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Debug|Any CPU.Deploy.0 = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Debug|iPhone.ActiveCfg = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Debug|iPhone.Build.0 = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Debug|iPhoneSimulator.ActiveCfg = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|Any CPU.ActiveCfg = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|Any CPU.Build.0 = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|Any CPU.Deploy.0 = Debug|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|iPhone.ActiveCfg = Release|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|iPhone.Build.0 = Release|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|iPhoneSimulator.ActiveCfg = Release|x86 - {35664234-EB75-47BA-A082-9F96BDF6FC92}.Release|iPhoneSimulator.Build.0 = Release|x86 - {0FC87DE5-B5E5-4846-894B-824497118143}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Debug|iPhone.Build.0 = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Release|Any CPU.Build.0 = Debug|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Release|iPhone.ActiveCfg = Release|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Release|iPhone.Build.0 = Release|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {0FC87DE5-B5E5-4846-894B-824497118143}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Debug|iPhone.Build.0 = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Release|Any CPU.Build.0 = Debug|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Release|iPhone.ActiveCfg = Release|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Release|iPhone.Build.0 = Release|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {2D337300-B3E9-4A36-8387-76A9A1100C5B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Debug|Any CPU.ActiveCfg = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Debug|Any CPU.Build.0 = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Debug|Any CPU.Deploy.0 = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Debug|iPhone.ActiveCfg = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Debug|iPhone.Build.0 = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Debug|iPhoneSimulator.ActiveCfg = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|Any CPU.ActiveCfg = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|Any CPU.Build.0 = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|Any CPU.Deploy.0 = Debug|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|iPhone.ActiveCfg = Release|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|iPhone.Build.0 = Release|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|iPhoneSimulator.ActiveCfg = Release|x86 + {FF9663EE-49AF-41D8-A25F-1C56C67274D3}.Release|iPhoneSimulator.Build.0 = Release|x86 + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Debug|iPhone.Build.0 = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Release|Any CPU.Build.0 = Debug|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Release|iPhone.ActiveCfg = Release|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Release|iPhone.Build.0 = Release|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Debug|iPhone.Build.0 = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Release|Any CPU.Build.0 = Debug|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Release|iPhone.ActiveCfg = Release|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Release|iPhone.Build.0 = Release|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {8BC94226-339B-4183-9AC2-EB3FD0D5D811}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Debug|iPhone.Build.0 = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Release|Any CPU.Build.0 = Debug|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Release|iPhone.ActiveCfg = Release|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Release|iPhone.Build.0 = Release|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {425DF4F6-3C01-4B6A-A678-701F36919C4D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Debug|iPhone.Build.0 = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Release|Any CPU.Build.0 = Debug|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Release|iPhone.ActiveCfg = Release|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Release|iPhone.Build.0 = Release|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {EDC997D0-2358-416F-A628-5DFD85728060}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -290,11 +290,11 @@ Global {6F6832FA-2E11-4324-B336-5673DFE15862} = {C3FDCDB7-0C29-472D-A406-E2F21A4B0EAE} {BCAF5569-30DB-4D44-BF46-DFFE93DDCBD0} = {AB9AD206-4B1E-4B0C-88A2-5C769314E8A4} {1E8FBBC2-9E06-4960-A116-65CDEFEFE11D} = {AB9AD206-4B1E-4B0C-88A2-5C769314E8A4} - {EA098E78-E56C-43B2-9D78-D4565EC04D09} = {586C3CCB-82A5-47F0-A099-B9A31BB4EA88} - {35664234-EB75-47BA-A082-9F96BDF6FC92} = {C3FDCDB7-0C29-472D-A406-E2F21A4B0EAE} - {0FC87DE5-B5E5-4846-894B-824497118143} = {C3FDCDB7-0C29-472D-A406-E2F21A4B0EAE} - {2D337300-B3E9-4A36-8387-76A9A1100C5B} = {AB9AD206-4B1E-4B0C-88A2-5C769314E8A4} - {F8BA5DE0-AEC0-4423-B036-5F9157E939D0} = {AB9AD206-4B1E-4B0C-88A2-5C769314E8A4} + {FF9663EE-49AF-41D8-A25F-1C56C67274D3} = {C3FDCDB7-0C29-472D-A406-E2F21A4B0EAE} + {5ACE2391-4864-4EE7-80D8-F7464C6F2D24} = {C3FDCDB7-0C29-472D-A406-E2F21A4B0EAE} + {8BC94226-339B-4183-9AC2-EB3FD0D5D811} = {AB9AD206-4B1E-4B0C-88A2-5C769314E8A4} + {425DF4F6-3C01-4B6A-A678-701F36919C4D} = {AB9AD206-4B1E-4B0C-88A2-5C769314E8A4} + {EDC997D0-2358-416F-A628-5DFD85728060} = {586C3CCB-82A5-47F0-A099-B9A31BB4EA88} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0653DB4A-5BBE-4D78-99B2-DB1C82663246} diff --git a/sample/HotUI.Samples/Comparisons/Section4b.cs b/sample/HotUI.Samples/Comparisons/Section4b.cs index 52478d6e..0623bc00 100644 --- a/sample/HotUI.Samples/Comparisons/Section4b.cs +++ b/sample/HotUI.Samples/Comparisons/Section4b.cs @@ -30,7 +30,7 @@ namespace HotUI.Samples.Comparisons new Image("turtlerock.jpg") .ClipShape(new Circle()) .Overlay(new Circle().Stroke(Color.White, lineWidth: 4)) - .Shadow(radius: 10) + //.Shadow(radius: 10) }; } } diff --git a/sample/HotUI.Samples/MainPage.cs b/sample/HotUI.Samples/MainPage.cs index 0c6c7d74..c47b0f48 100644 --- a/sample/HotUI.Samples/MainPage.cs +++ b/sample/HotUI.Samples/MainPage.cs @@ -32,8 +32,11 @@ namespace HotUI.Samples { new MenuItem("SwiftUI Tutorial Section 4b", ()=> new Section4b()), new MenuItem("SwiftUI Tutorial Section 4c", ()=> new Section4c()), }; - public MainPage () + public MainPage (List additionalPage = null) { + if (additionalPage != null) + pages.AddRange(additionalPage); + Body = () => new NavigationView { new ListView (pages) { Cell = (page) => new NavigationButton (page.Title,page.Page), diff --git a/sample/HotUI.iOS.Sample/AppDelegate.cs b/sample/HotUI.iOS.Sample/AppDelegate.cs index 3939f616..7c9be7a5 100644 --- a/sample/HotUI.iOS.Sample/AppDelegate.cs +++ b/sample/HotUI.iOS.Sample/AppDelegate.cs @@ -1,6 +1,9 @@ using System; +using System.Collections.Generic; +using CoreLocation; using Foundation; using HotUI.Samples; +using MapKit; using UIKit; namespace HotUI.iOS.Sample { @@ -31,7 +34,11 @@ namespace HotUI.iOS.Sample { "turtlerock.jpg".LoadImage(); window = new UIWindow { - RootViewController = new MainPage ().ToViewController (), + RootViewController = new MainPage (new List + { + new MenuItem("SwiftUI Tutorial Section 5 (Native)", () => new Section5Native()), + new MenuItem("SwiftUI Tutorial Section 5b (Native)", () => new Section5NativeB()) + }).ToViewController (), }; window.MakeKeyAndVisible (); @@ -69,5 +76,48 @@ namespace HotUI.iOS.Sample { // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground. } } + + public class Section5Native : View + { + public Section5Native() + { + Body = () => new VStack + { + new ViewRepresentable() + { + MakeView = () => new MKMapView(UIScreen.MainScreen.Bounds), + UpdateView = (view, data) => + { + var mapView = (MKMapView)view; + var coordinate = new CLLocationCoordinate2D(latitude: 34.011286, longitude: -116.166868); + var span = new MKCoordinateSpan(latitudeDelta: 2.0, longitudeDelta: 2.0); + var region = new MKCoordinateRegion(center: coordinate, span: span); + mapView.SetRegion(region, animated: true); + } + } + }; + } + } + + public class Section5NativeB : View + { + public Section5NativeB() + { + Body = () => new VStack + { + new UIViewRepresentable() + { + MakeView = () => new MKMapView(UIScreen.MainScreen.Bounds), + UpdateView = (view, data) => + { + var coordinate = new CLLocationCoordinate2D(latitude: 34.011286, longitude: -116.166868); + var span = new MKCoordinateSpan(latitudeDelta: 2.0, longitudeDelta: 2.0); + var region = new MKCoordinateRegion(center: coordinate, span: span); + view.SetRegion(region, animated: true); + } + } + }; + } + } } diff --git a/sample/HotUI.iOS.Sample/HotUI.iOS.Sample.csproj b/sample/HotUI.iOS.Sample/HotUI.iOS.Sample.csproj index 40f8bfb4..34d8ca05 100644 --- a/sample/HotUI.iOS.Sample/HotUI.iOS.Sample.csproj +++ b/sample/HotUI.iOS.Sample/HotUI.iOS.Sample.csproj @@ -137,6 +137,7 @@ + diff --git a/sample/HotUI.iOS.Sample/Main.cs b/sample/HotUI.iOS.Sample/Main.cs index c30b10dd..e1722334 100644 --- a/sample/HotUI.iOS.Sample/Main.cs +++ b/sample/HotUI.iOS.Sample/Main.cs @@ -7,7 +7,7 @@ namespace HotUI.iOS.Sample { { // if you want to use a different Application Delegate class from "AppDelegate" // you can specify it here. - UIApplication.Main (args, null, "AppDelegate"); + UIApplication.Main (args, null, "AppDelegate"); } } } \ No newline at end of file diff --git a/src/HotUI.iOS/Handlers/ViewRepresentableHandler.cs b/src/HotUI.iOS/Handlers/ViewRepresentableHandler.cs new file mode 100644 index 00000000..6dabc86e --- /dev/null +++ b/src/HotUI.iOS/Handlers/ViewRepresentableHandler.cs @@ -0,0 +1,32 @@ +using System; +using UIKit; + +// ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable MemberCanBePrivate.Global + +namespace HotUI.iOS +{ + public class ViewRepresentableHandler : AbstractHandler + { + public static readonly PropertyMapper Mapper = new PropertyMapper(ViewHandler.Mapper) + { + [nameof(ViewRepresentable.Data)] = MapDataProperty + }; + + public ViewRepresentableHandler() : base(Mapper) + { + + } + + protected override UIView CreateView() + { + return VirtualView?.MakeView() as UIView; + } + + public static void MapDataProperty(IViewHandler viewHandler, ViewRepresentable virtualView) + { + var data = virtualView.Data; + virtualView.UpdateView?.Invoke(viewHandler.NativeView, data); + } + } +} \ No newline at end of file diff --git a/src/HotUI.iOS/HotUI.iOS.csproj b/src/HotUI.iOS/HotUI.iOS.csproj index a93035ff..04cdf2db 100644 --- a/src/HotUI.iOS/HotUI.iOS.csproj +++ b/src/HotUI.iOS/HotUI.iOS.csproj @@ -73,6 +73,8 @@ + + diff --git a/src/HotUI.iOS/UI.cs b/src/HotUI.iOS/UI.cs index f90ae112..5b56f8b0 100644 --- a/src/HotUI.iOS/UI.cs +++ b/src/HotUI.iOS/UI.cs @@ -28,6 +28,7 @@ namespace HotUI.iOS { Registrar.Handlers.Register (); Registrar.Handlers.Register(); Registrar.Handlers.Register(); + Registrar.Handlers.Register(); ModalView.PerformPresent = (o) => { PresentingViewController.PresentViewController (o.ToViewController(), true,null); diff --git a/src/HotUI.iOS/UIViewRepresentable.cs b/src/HotUI.iOS/UIViewRepresentable.cs new file mode 100644 index 00000000..c4c0e5a9 --- /dev/null +++ b/src/HotUI.iOS/UIViewRepresentable.cs @@ -0,0 +1,22 @@ +using System; +using UIKit; + +namespace HotUI.iOS +{ + public class UIViewRepresentable : ViewRepresentable where T:UIView + { + public delegate void UpdateUIView(T view, object state); + + public new Func MakeView + { + get => () => base.MakeView?.Invoke() as T; + set => base.MakeView = () => value?.Invoke(); + } + + public new UpdateUIView UpdateView + { + get => (view, state) => base.UpdateView?.Invoke(view, state); + set => base.UpdateView = (view, state) => value?.Invoke(view as T, state); + } + } +} diff --git a/src/HotUI/Controls/ViewRepresentable.cs b/src/HotUI/Controls/ViewRepresentable.cs new file mode 100644 index 00000000..1dc00db5 --- /dev/null +++ b/src/HotUI/Controls/ViewRepresentable.cs @@ -0,0 +1,54 @@ +using System; +namespace HotUI +{ + public delegate void UpdateView(object view, object state); + + public class ViewRepresentable : View + { + public ViewRepresentable() + { + + } + + public ViewRepresentable(object data) : base (true) + { + Data = data; + } + + public ViewRepresentable(Func dataBuilder) + { + DataBinding = dataBuilder; + } + + public Func MakeView { get; set; } + + public UpdateView UpdateView { get; set; } + + private object context; + public object Data + { + get => context; + private set => (this).SetValue(base.State, ref context, value, base.ViewPropertyChanged); + } + + public Func DataBinding { get; private set; } + + protected override void WillUpdateView () + { + base.WillUpdateView (); + if (DataBinding != null) + { + base.State.StartProperty (); + var text = DataBinding.Invoke (); + var props = base.State.EndProperty (); + var propCount = props.Length; + if (propCount > 0) + { + base.State.BindingState.AddViewProperty (props, (s, o) => Data = DataBinding.Invoke ()); + } + Data = text; + } + } + + } +}