From 3a15de8ecf19f5ba5e186d1324041e996feb0f2a Mon Sep 17 00:00:00 2001 From: kamu Date: Sat, 26 May 2018 20:17:52 +0900 Subject: [PATCH] Release 1.1.0 --- AiForms.Layouts/AiForms.Layouts.csproj | 42 +---- AiForms.Layouts/AiForms.Layouts.nuget.props | 18 -- AiForms.Layouts/AiForms.Layouts.nuget.targets | 9 - AiForms.Layouts/RepeatableFlex.cs | 151 ++++++++++++++++ AiForms.Layouts/project.json | 10 -- README.md | 30 +++- Sample/Sample.Droid/MainActivity.cs | 8 +- Sample/Sample.Droid/Sample.Droid.csproj | 66 ++++--- Sample/Sample.Droid/packages.config | 14 +- Sample/Sample.iOS/AppDelegate.cs | 13 +- Sample/Sample.iOS/Sample.iOS.csproj | 56 +++--- Sample/Sample.iOS/packages.config | 26 +-- Sample/Sample/App.xaml.cs | 9 +- Sample/Sample/AppTheme.xaml | 9 +- Sample/Sample/Sample.csproj | 111 +----------- Sample/Sample/Sample.nuget.props | 18 -- Sample/Sample/Sample.nuget.targets | 9 - .../FlexLayoutWithSelectorViewModel.cs | 14 ++ .../ViewModels/RepeatableFlexPageViewModel.cs | 162 ++++++++++++++++++ .../Sample/Views/FlexLayoutWithSelector.xaml | 61 +++++++ .../Views/FlexLayoutWithSelector.xaml.cs | 15 ++ Sample/Sample/Views/RepeatableFlexPage.xaml | 47 +++++ .../Sample/Views/RepeatableFlexPage.xaml.cs | 15 ++ Sample/Sample/Views/SelectPage.xaml | 21 ++- Sample/Sample/project.json | 49 ------ nuget/AiLayouts_mac.nuspec | 27 +-- 26 files changed, 653 insertions(+), 357 deletions(-) delete mode 100644 AiForms.Layouts/AiForms.Layouts.nuget.props delete mode 100644 AiForms.Layouts/AiForms.Layouts.nuget.targets create mode 100644 AiForms.Layouts/RepeatableFlex.cs delete mode 100644 AiForms.Layouts/project.json delete mode 100644 Sample/Sample/Sample.nuget.props delete mode 100644 Sample/Sample/Sample.nuget.targets create mode 100644 Sample/Sample/ViewModels/FlexLayoutWithSelectorViewModel.cs create mode 100644 Sample/Sample/ViewModels/RepeatableFlexPageViewModel.cs create mode 100644 Sample/Sample/Views/FlexLayoutWithSelector.xaml create mode 100644 Sample/Sample/Views/FlexLayoutWithSelector.xaml.cs create mode 100644 Sample/Sample/Views/RepeatableFlexPage.xaml create mode 100644 Sample/Sample/Views/RepeatableFlexPage.xaml.cs delete mode 100644 Sample/Sample/project.json diff --git a/AiForms.Layouts/AiForms.Layouts.csproj b/AiForms.Layouts/AiForms.Layouts.csproj index c919bfb..a2938d4 100644 --- a/AiForms.Layouts/AiForms.Layouts.csproj +++ b/AiForms.Layouts/AiForms.Layouts.csproj @@ -1,42 +1,14 @@ - - + + - Debug - AnyCPU - {921EC4B4-C014-4C1D-8BF3-ED28838B22E5} - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - AiForms.Layouts - AiForms.Layouts - v5.0 + netstandard2.0 - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - - - true - bin\Release - prompt - 4 - - - - - - - + - + + - + - - \ No newline at end of file diff --git a/AiForms.Layouts/AiForms.Layouts.nuget.props b/AiForms.Layouts/AiForms.Layouts.nuget.props deleted file mode 100644 index d347022..0000000 --- a/AiForms.Layouts/AiForms.Layouts.nuget.props +++ /dev/null @@ -1,18 +0,0 @@ - - - - True - NuGet - /Users/kamu/Dropbox/work/projects/AiForms.Layouts/AiForms.Layouts/project.lock.json - /Users/kamu/.nuget/packages/ - /Users/kamu/.nuget/packages/ - ProjectJson - 4.3.1 - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - \ No newline at end of file diff --git a/AiForms.Layouts/AiForms.Layouts.nuget.targets b/AiForms.Layouts/AiForms.Layouts.nuget.targets deleted file mode 100644 index d404c2f..0000000 --- a/AiForms.Layouts/AiForms.Layouts.nuget.targets +++ /dev/null @@ -1,9 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - \ No newline at end of file diff --git a/AiForms.Layouts/RepeatableFlex.cs b/AiForms.Layouts/RepeatableFlex.cs new file mode 100644 index 0000000..dd6d8be --- /dev/null +++ b/AiForms.Layouts/RepeatableFlex.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections; +using System.Collections.Specialized; +using Xamarin.Forms; + +namespace AiForms.Layouts +{ + public class RepeatableFlex: FlexLayout + { + public static BindableProperty ItemsSourceProperty = + BindableProperty.Create( + nameof(ItemsSource), + typeof(IEnumerable), + typeof(RepeatableFlex), + null, + defaultBindingMode: BindingMode.OneWay, + propertyChanged: ItemsChanged + ); + + public IEnumerable ItemsSource { + get { return (IEnumerable)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + + public static BindableProperty ItemTemplateProperty = + BindableProperty.Create( + nameof(ItemTemplate), + typeof(DataTemplate), + typeof(RepeatableFlex), + default(DataTemplate), + propertyChanged: (bindable, oldValue, newValue) => { + var control = (RepeatableFlex)bindable; + //when to occur propertychanged earlier ItemsSource than ItemTemplate, raise ItemsChanged manually + if (newValue != null && control.ItemsSource != null && !control.doneItemSourceChanged) { + ItemsChanged(bindable, null, control.ItemsSource); + } + } + ); + + public DataTemplate ItemTemplate { + get { return (DataTemplate)GetValue(ItemTemplateProperty); } + set { SetValue(ItemTemplateProperty, value); } + } + + private bool doneItemSourceChanged = false; + + private static void ItemsChanged(BindableObject bindable, object oldValue, object newValue) + { + var control = (RepeatableFlex)bindable; + // when to occur propertychanged earlier ItemsSource than ItemTemplate, do nothing. + if (control.ItemTemplate == null) { + control.doneItemSourceChanged = false; + return; + } + + control.doneItemSourceChanged = true; + + IEnumerable newValueAsEnumerable; + try { + newValueAsEnumerable = newValue as IEnumerable; + } + catch (Exception e) { + throw e; + } + + var oldObservableCollection = oldValue as INotifyCollectionChanged; + + if (oldObservableCollection != null) { + oldObservableCollection.CollectionChanged -= control.OnItemsSourceCollectionChanged; + } + + var newObservableCollection = newValue as INotifyCollectionChanged; + + if (newObservableCollection != null) { + newObservableCollection.CollectionChanged += control.OnItemsSourceCollectionChanged; + } + + control.Children.Clear(); + + if (newValueAsEnumerable != null) { + foreach (var item in newValueAsEnumerable) { + var view = CreateChildViewFor(control.ItemTemplate, item, control); + + control.Children.Add(view); + } + } + + control.UpdateChildrenLayout(); + control.InvalidateLayout(); + } + + private void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Replace) { + + this.Children.RemoveAt(e.OldStartingIndex); + + var item = e.NewItems[e.NewStartingIndex]; + var view = CreateChildViewFor(this.ItemTemplate, item, this); + + this.Children.Insert(e.NewStartingIndex, view); + } + + else if (e.Action == NotifyCollectionChangedAction.Add) { + if (e.NewItems != null) { + for (var i = 0; i < e.NewItems.Count; ++i) { + var item = e.NewItems[i]; + var view = CreateChildViewFor(this.ItemTemplate, item, this); + + this.Children.Insert(i + e.NewStartingIndex, view); + } + } + } + + else if (e.Action == NotifyCollectionChangedAction.Remove) { + if (e.OldItems != null) { + this.Children.RemoveAt(e.OldStartingIndex); + } + } + + else if (e.Action == NotifyCollectionChangedAction.Reset) { + this.Children.Clear(); + } + + else { + return; + } + + } + + private View CreateChildViewFor(object item) + { + this.ItemTemplate.SetValue(BindableObject.BindingContextProperty, item); + return (View)this.ItemTemplate.CreateContent(); + } + + private static View CreateChildViewFor(DataTemplate template, object item, BindableObject container) + { + var selector = template as DataTemplateSelector; + + if (selector != null) { + template = selector.SelectTemplate(item, container); + } + + //Binding context + template.SetValue(BindableObject.BindingContextProperty, item); + + return (View)template.CreateContent(); + } + } +} diff --git a/AiForms.Layouts/project.json b/AiForms.Layouts/project.json deleted file mode 100644 index 4283539..0000000 --- a/AiForms.Layouts/project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.Portable.Compatibility": "1.0.1", - "NETStandard.Library": "1.6.0", - "Xamarin.Forms": "2.5.0.91635" - }, - "frameworks": { - "netstandard1.1": {} - } -} \ No newline at end of file diff --git a/README.md b/README.md index 88399b8..522a626 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ This is a collection of Xamarin.Forms custom layouts ## Features +* [RepeatableFlex](#repeatableflex) * [WrapLayout](#wraplayout) * [RepeatableWrapLayout](#repeatablewraplayout) * [RepeatableStack](#repeatablestack) - ## Demo https://twitter.com/muak_x/status/830061279330996224 @@ -28,9 +28,6 @@ https://twitter.com/muak_x/status/830061279330996224 Install-Package AiForms.Layouts ``` -~~All you need to do is installing to PCL project.~~ -~~You need not to install this nuget package to each platform project.~~ - You need to install this package to .NETStandard / PCL project and **each platform project**. ### iOS @@ -49,10 +46,35 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options) } ``` +## RepeatableFlex + +This layout is a FlexLayout corresponding to DataTemplate and DataTemplateSelector. + +### Parameters + +* ItemsSource +* ItemTemplate + +### How to write with Xaml + +```xml + + + + + + + + + +``` + ## WrapLayout This Layout performs wrapping on the boundaries. +_By Flex Layout having come, there is seldom opportunity using this layout. But it can be used when you want to arrange uniformly each items depending on screen width or make it square._ + ### Parameters * Spacing diff --git a/Sample/Sample.Droid/MainActivity.cs b/Sample/Sample.Droid/MainActivity.cs index 3a38236..4c4b11a 100644 --- a/Sample/Sample.Droid/MainActivity.cs +++ b/Sample/Sample.Droid/MainActivity.cs @@ -1,8 +1,8 @@ using Android.App; using Android.Content.PM; using Android.OS; -using Microsoft.Practices.Unity; -using Prism.Unity; +using Prism; +using Prism.Ioc; namespace Sample.Droid { @@ -18,15 +18,15 @@ protected override void OnCreate(Bundle bundle) global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental"); global::Xamarin.Forms.Forms.Init(this, bundle); + LoadApplication(new App(new AndroidInitializer())); } } public class AndroidInitializer : IPlatformInitializer { - public void RegisterTypes(IUnityContainer container) + public void RegisterTypes(IContainerRegistry containerRegistry) { - } } } diff --git a/Sample/Sample.Droid/Sample.Droid.csproj b/Sample/Sample.Droid/Sample.Droid.csproj index b4c20e2..1e5a8be 100644 --- a/Sample/Sample.Droid/Sample.Droid.csproj +++ b/Sample/Sample.Droid/Sample.Droid.csproj @@ -1,6 +1,6 @@ - + Debug AnyCPU @@ -48,9 +48,6 @@ ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - - ..\packages\Unity.4.0.1\lib\portable-net45+wp80+win8+wpa81+MonoAndroid10+MonoTouch10\Microsoft.Practices.Unity.dll - @@ -65,12 +62,6 @@ ..\packages\System.Reactive.PlatformServices.3.1.1\lib\netstandard1.3\System.Reactive.PlatformServices.dll - - ..\packages\ReactiveProperty.3.2.0\lib\MonoAndroid\ReactiveProperty.Android.dll - - - ..\packages\ReactiveProperty.3.2.0\lib\MonoAndroid\ReactiveProperty.dll - @@ -121,29 +112,56 @@ ..\packages\Xamarin.Android.Support.v7.MediaRouter.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.MediaRouter.dll + + ..\packages\Prism.Core.7.0.0.396\lib\netstandard2.0\Prism.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\CommonServiceLocator.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\Unity.Abstractions.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\Unity.Container.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\Unity.ServiceLocation.dll + + + ..\packages\Prism.Forms.7.0.0.396\lib\netstandard2.0\Prism.Forms.dll + + + ..\packages\Prism.Unity.Forms.7.0.0.396\lib\netstandard2.0\Prism.Unity.Forms.dll + + + ..\packages\ReactiveProperty.4.2.2\lib\MonoAndroid\ReactiveProperty.Android.dll + + + ..\packages\ReactiveProperty.4.2.2\lib\MonoAndroid\ReactiveProperty.dll + - ..\packages\Xamarin.Forms.2.5.0.91635\lib\MonoAndroid10\FormsViewGroup.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\MonoAndroid10\FormsViewGroup.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\MonoAndroid10\Xamarin.Forms.Core.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Core.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\MonoAndroid10\Xamarin.Forms.Platform.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Platform.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll - - ..\packages\Prism.Core.6.3.0\lib\MonoAndroid10\Prism.dll + + ..\packages\AiForms.Effects.1.3.1\lib\MonoAndroid\AiForms.Effects.dll - - ..\packages\Prism.Forms.6.3.0\lib\MonoAndroid1.0\Prism.Forms.dll + + ..\packages\AiForms.Effects.1.3.1\lib\MonoAndroid\AiForms.Effects.Droid.dll - - ..\packages\Prism.Unity.Forms.6.3.0\lib\MonoAndroid1.0\Prism.Unity.Forms.dll + + ..\packages\AiForms.Layouts.1.1.0\lib\netstandard2.0\AiForms.Layouts.dll @@ -155,10 +173,6 @@ {9A48D096-CB04-4932-9538-BBFB58AD7052} Sample - - {921EC4B4-C014-4C1D-8BF3-ED28838B22E5} - AiForms.Layouts - @@ -199,5 +213,5 @@ - + \ No newline at end of file diff --git a/Sample/Sample.Droid/packages.config b/Sample/Sample.Droid/packages.config index 9be3d42..f7a68ea 100644 --- a/Sample/Sample.Droid/packages.config +++ b/Sample/Sample.Droid/packages.config @@ -1,13 +1,15 @@  + + - - - - + + + + @@ -59,7 +61,7 @@ - + @@ -76,5 +78,5 @@ - + \ No newline at end of file diff --git a/Sample/Sample.iOS/AppDelegate.cs b/Sample/Sample.iOS/AppDelegate.cs index 13f466e..50476db 100644 --- a/Sample/Sample.iOS/AppDelegate.cs +++ b/Sample/Sample.iOS/AppDelegate.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; - using Foundation; -using Microsoft.Practices.Unity; using Prism; -using Prism.Unity; +using Prism.Ioc; using UIKit; namespace Sample.iOS @@ -27,6 +22,9 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); + AiForms.Layouts.LayoutsInit.Init(); + AiForms.Effects.iOS.Effects.Init(); + LoadApplication(new App(new iOSInitializer())); return base.FinishedLaunching(app, options); @@ -35,9 +33,8 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options) public class iOSInitializer : IPlatformInitializer { - public void RegisterTypes(IUnityContainer container) + public void RegisterTypes(IContainerRegistry containerRegistry) { - } } } diff --git a/Sample/Sample.iOS/Sample.iOS.csproj b/Sample/Sample.iOS/Sample.iOS.csproj index 36595cd..71a3cd3 100644 --- a/Sample/Sample.iOS/Sample.iOS.csproj +++ b/Sample/Sample.iOS/Sample.iOS.csproj @@ -1,6 +1,6 @@ - + Debug iPhoneSimulator @@ -87,9 +87,6 @@ ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - - ..\packages\Unity.4.0.1\lib\portable-net45+wp80+win8+wpa81+MonoAndroid10+MonoTouch10\Microsoft.Practices.Unity.dll - @@ -104,32 +101,53 @@ ..\packages\System.Reactive.PlatformServices.3.1.1\lib\netstandard1.3\System.Reactive.PlatformServices.dll + + ..\packages\Prism.Core.7.0.0.396\lib\netstandard2.0\Prism.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\CommonServiceLocator.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\Unity.Abstractions.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\Unity.Container.dll + + + ..\packages\Unity.5.5.5\lib\netstandard2.0\Unity.ServiceLocation.dll + + + ..\packages\Prism.Forms.7.0.0.396\lib\netstandard2.0\Prism.Forms.dll + + + ..\packages\Prism.Unity.Forms.7.0.0.396\lib\netstandard2.0\Prism.Unity.Forms.dll + - ..\packages\ReactiveProperty.3.2.0\lib\Xamarin.iOS10\ReactiveProperty.dll + ..\packages\ReactiveProperty.4.2.2\lib\Xamarin.iOS10\ReactiveProperty.dll - ..\packages\ReactiveProperty.3.2.0\lib\Xamarin.iOS10\ReactiveProperty.iOS.dll + ..\packages\ReactiveProperty.4.2.2\lib\Xamarin.iOS10\ReactiveProperty.iOS.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll - ..\packages\Xamarin.Forms.2.5.0.91635\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll + ..\packages\Xamarin.Forms.3.0.0.482510\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll - - ..\packages\Prism.Core.6.3.0\lib\Xamarin.iOS10\Prism.dll + + ..\packages\AiForms.Effects.1.3.1\lib\Xamarin.iOS10\AiForms.Effects.dll - - ..\packages\Prism.Forms.6.3.0\lib\Xamarin.iOS1.0\Prism.Forms.dll + + ..\packages\AiForms.Effects.1.3.1\lib\Xamarin.iOS10\AiForms.Effects.iOS.dll - - ..\packages\Prism.Unity.Forms.6.3.0\lib\Xamarin.iOS1.0\Prism.Unity.Forms.dll + + ..\packages\AiForms.Layouts.1.1.0\lib\netstandard2.0\AiForms.Layouts.dll @@ -141,10 +159,6 @@ {9A48D096-CB04-4932-9538-BBFB58AD7052} Sample - - {921EC4B4-C014-4C1D-8BF3-ED28838B22E5} - AiForms.Layouts - @@ -162,5 +176,5 @@ - + \ No newline at end of file diff --git a/Sample/Sample.iOS/packages.config b/Sample/Sample.iOS/packages.config index d2455a7..0fc8761 100644 --- a/Sample/Sample.iOS/packages.config +++ b/Sample/Sample.iOS/packages.config @@ -1,18 +1,20 @@  + + - - - - + + + + - + - + @@ -31,17 +33,17 @@ - + - - + + - + @@ -62,6 +64,6 @@ - - + + \ No newline at end of file diff --git a/Sample/Sample/App.xaml.cs b/Sample/Sample/App.xaml.cs index 7869392..ea71fd7 100644 --- a/Sample/Sample/App.xaml.cs +++ b/Sample/Sample/App.xaml.cs @@ -1,7 +1,9 @@ using System.Linq; using System.Reflection; -using Microsoft.Practices.ObjectBuilder2; +using Prism; +using Prism.Ioc; using Prism.Unity; +using Xamarin.Forms.Internals; [assembly: Xamarin.Forms.Xaml.XamlCompilation(Xamarin.Forms.Xaml.XamlCompilationOptions.Compile)] namespace Sample @@ -17,16 +19,15 @@ protected async override void OnInitialized() await NavigationService.NavigateAsync("MyNavigationPage/SelectPage"); } - protected override void RegisterTypes() + protected override void RegisterTypes(IContainerRegistry containerRegistry) { var types = this.GetType().GetTypeInfo().Assembly.DefinedTypes; this.GetType().GetTypeInfo().Assembly.DefinedTypes .Where(t => t.Namespace?.EndsWith(".Views", System.StringComparison.Ordinal) ?? false) .ForEach(t => { - Container.RegisterTypeForNavigation(t.AsType(), t.Name); + containerRegistry.RegisterForNavigation(t.AsType(), t.Name); }); } - } } diff --git a/Sample/Sample/AppTheme.xaml b/Sample/Sample/AppTheme.xaml index a4fb938..a67fecb 100644 --- a/Sample/Sample/AppTheme.xaml +++ b/Sample/Sample/AppTheme.xaml @@ -2,6 +2,7 @@ @@ -19,11 +20,9 @@ 28 diff --git a/Sample/Sample/Sample.csproj b/Sample/Sample/Sample.csproj index 66fd038..01f1ff3 100644 --- a/Sample/Sample/Sample.csproj +++ b/Sample/Sample/Sample.csproj @@ -1,107 +1,14 @@ - - + + - Debug - AnyCPU - {9A48D096-CB04-4932-9538-BBFB58AD7052} - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Sample - Sample - v5.0 + netstandard2.0 - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - - - true - bin\Release - prompt - 4 - - - - App.xaml - - - MainPage.xaml - - - - AppTheme.xaml - - - MyNavigationPage.xaml - - - OtherTheme.xaml - - - - SelectPage.xaml - - - - RepeatableStackPage.xaml - - - - WrapLayoutWithSelector.xaml - - - - - StackLayoutWithSelector.xaml - - - - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - - - - - - + - - {921EC4B4-C014-4C1D-8BF3-ED28838B22E5} - AiForms.Layouts - + + + + + - - \ No newline at end of file diff --git a/Sample/Sample/Sample.nuget.props b/Sample/Sample/Sample.nuget.props deleted file mode 100644 index 7a004c3..0000000 --- a/Sample/Sample/Sample.nuget.props +++ /dev/null @@ -1,18 +0,0 @@ - - - - True - NuGet - /Users/kamu/Dropbox/work/projects/AiForms.Layouts/Sample/Sample/project.lock.json - /Users/kamu/.nuget/packages/ - /Users/kamu/.nuget/packages/ - ProjectJson - 4.3.1 - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - \ No newline at end of file diff --git a/Sample/Sample/Sample.nuget.targets b/Sample/Sample/Sample.nuget.targets deleted file mode 100644 index d404c2f..0000000 --- a/Sample/Sample/Sample.nuget.targets +++ /dev/null @@ -1,9 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - \ No newline at end of file diff --git a/Sample/Sample/ViewModels/FlexLayoutWithSelectorViewModel.cs b/Sample/Sample/ViewModels/FlexLayoutWithSelectorViewModel.cs new file mode 100644 index 0000000..96b21ac --- /dev/null +++ b/Sample/Sample/ViewModels/FlexLayoutWithSelectorViewModel.cs @@ -0,0 +1,14 @@ +using System; +using Prism.Navigation; +using Prism.Services; + +namespace Sample.ViewModels +{ + public class FlexLayoutWithSelectorViewModel:RepeatableFlexPageViewModel + { + public FlexLayoutWithSelectorViewModel(INavigationService navigationService, IPageDialogService pageDlg) + :base(navigationService,pageDlg) + { + } + } +} diff --git a/Sample/Sample/ViewModels/RepeatableFlexPageViewModel.cs b/Sample/Sample/ViewModels/RepeatableFlexPageViewModel.cs new file mode 100644 index 0000000..c4c6dae --- /dev/null +++ b/Sample/Sample/ViewModels/RepeatableFlexPageViewModel.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Prism.Mvvm; +using Prism.Navigation; +using Prism.Services; +using Reactive.Bindings; +using Xamarin.Forms; + +namespace Sample.ViewModels +{ + public class RepeatableFlexPageViewModel:BindableBase + { + + public ReactiveCommand ClearCommand { get; } = new ReactiveCommand(); + public ReactiveCommand DeleteCommand { get; } = new ReactiveCommand(); + public ReactiveCommand ReplaceCommand { get; } = new ReactiveCommand(); + public ReactiveCommand AddCommand { get; } = new ReactiveCommand(); + public ReactiveCommand DirectionCommand { get; } = new ReactiveCommand(); + public ReactiveCommand AlignItemsCommand { get; } = new ReactiveCommand(); + public ReactiveCommand JustifyContentCommand { get; } = new ReactiveCommand(); + public ReactiveCommand WrapCommand { get; } = new ReactiveCommand(); + public ReactiveProperty[] DirectionColor { get; } = new ReactiveProperty[3]; + public ReactiveProperty[] AColor { get; } = new ReactiveProperty[5]; + public ReactiveProperty[] JColor { get; } = new ReactiveProperty[7]; + public ReactiveProperty[] WrapColor { get; } = new ReactiveProperty[2]; + public ObservableCollection BoxList { get; } + + public ReactiveProperty FlexDirection { get; } = new ReactiveProperty(); + public ReactiveProperty FlexAlignItems { get; } = new ReactiveProperty(); + public ReactiveProperty FlexJustify { get; } = new ReactiveProperty(); + public ReactiveProperty FlexWrap { get; } = new ReactiveProperty(); + public ReactiveProperty ScrollDirection { get; } = new ReactiveProperty(); + + public RepeatableFlexPageViewModel(INavigationService navigationService, IPageDialogService pageDlg) + { + + + + FlexDirection.Value = Xamarin.Forms.FlexDirection.Row; + FlexAlignItems.Value = Xamarin.Forms.FlexAlignItems.Start; + FlexJustify.Value = Xamarin.Forms.FlexJustify.Start; + FlexWrap.Value = Xamarin.Forms.FlexWrap.NoWrap; + ScrollDirection.Value = ScrollOrientation.Horizontal; + + SetColors(DirectionColor,0); + SetColors(AColor,3); + SetColors(JColor,3); + SetColors(WrapColor,0); + + DirectionCommand.Subscribe(x => { + var idx = int.Parse(x); + FlexDirection.Value = (Xamarin.Forms.FlexDirection)idx; + SetScrollDirection(); + SetColors(DirectionColor, idx); + }); + AlignItemsCommand.Subscribe(x => { + var idx = int.Parse(x); + FlexAlignItems.Value = (Xamarin.Forms.FlexAlignItems)idx; + SetColors(AColor, idx); + }); + JustifyContentCommand.Subscribe(x => { + var idx = int.Parse(x); + FlexJustify.Value = (Xamarin.Forms.FlexJustify)idx; + SetColors(JColor, idx); + }); + WrapCommand.Subscribe(x => { + var idx = int.Parse(x); + FlexWrap.Value = (Xamarin.Forms.FlexWrap)idx; + SetScrollDirection(); + SetColors(WrapColor, idx); + }); + + + BoxList = new ObservableCollection(Shuffle()); + + AddCommand.Subscribe(_ => { + BoxList.Add(GetNextItem()); + }); + + DeleteCommand.Subscribe(_ => { + BoxList.Remove(BoxList.Last()); + }); + + ReplaceCommand.Subscribe(__ => { + BoxList[0] = GetNextItem(); + }); + + ClearCommand.Subscribe(__ => { + BoxList.Clear(); + }); + } + + void SetScrollDirection() + { + if (FlexDirection.Value == Xamarin.Forms.FlexDirection.Row && FlexWrap.Value == Xamarin.Forms.FlexWrap.NoWrap || + FlexDirection.Value == Xamarin.Forms.FlexDirection.Column && FlexWrap.Value == Xamarin.Forms.FlexWrap.Wrap) { + ScrollDirection.Value = ScrollOrientation.Horizontal; + } + else { + ScrollDirection.Value = ScrollOrientation.Vertical; + } + } + + void SetColors(ReactiveProperty[] reactiveProperties,int target = -1) + { + for (var i = 0; i < reactiveProperties.Length; i++){ + if(reactiveProperties[i] == null){ + reactiveProperties[i] = new ReactiveProperty(); + } + reactiveProperties[i].Value = Color.Blue; + } + if (target >= 0) { + reactiveProperties[target].Value = Color.Red; + } + } + + List Shuffle() + { + var list = new List(); + + var rand = new Random(); + for (var i = 0; i < 8; i++) { + + var r = rand.Next(10, 245); + var g = rand.Next(10, 245); + var b = rand.Next(10, 245); + var color = Color.FromRgb(r, g, b); + var w = rand.Next(30, 100); + var h = rand.Next(30, 60); + + list.Add(new Hoge { + Name = $"#{r:X2}{g:X2}{b:X2}", + Color = color, + Width = w, + Height = h, + }); + } + + return list; + } + + Hoge GetNextItem() + { + var rand = new Random(); + var r = rand.Next(10, 245); + var g = rand.Next(10, 245); + var b = rand.Next(10, 245); + var color = Color.FromRgb(r, g, b); + var w = rand.Next(30, 100); + var h = rand.Next(30, 60); + + return new Hoge { + Name = $"#{r:X2}{g:X2}{b:X2}", + Color = color, + Width = w, + Height = h, + }; + } + } +} diff --git a/Sample/Sample/Views/FlexLayoutWithSelector.xaml b/Sample/Sample/Views/FlexLayoutWithSelector.xaml new file mode 100644 index 0000000..ae3b463 --- /dev/null +++ b/Sample/Sample/Views/FlexLayoutWithSelector.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + +