-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from muak/dev1.1.0
Release 1.1.0
- Loading branch information
Showing
26 changed files
with
653 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{921EC4B4-C014-4C1D-8BF3-ED28838B22E5}</ProjectGuid> | ||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>AiForms.Layouts</RootNamespace> | ||
<AssemblyName>AiForms.Layouts</AssemblyName> | ||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="RepeatableWrapLayout.cs" /> | ||
<Compile Include="WrapLayout.cs" /> | ||
<Compile Include="RepeatableStack.cs" /> | ||
<Compile Include="LayoutsInit.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="project.json" /> | ||
<PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Properties\" /> | ||
<None Remove="AiForms.Layouts.csproj.nuget.cache" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> | ||
<Import Project="..\packages\Xamarin.Forms.2.3.3.180\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.3.3.180\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" /> | ||
</Project> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.