Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kamusoft committed Dec 4, 2018
1 parent 9a844c9 commit 92d63fd
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CollectionView.Droid/CollectionView.Droid.csproj
Expand Up @@ -14,7 +14,7 @@
<AndroidResgenClass>Resource</AndroidResgenClass>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<ReleaseVersion>1.1.2</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -142,7 +142,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CollectionView\CollectionView.csproj">
<Project>{D5C93D88-A5D6-4843-935B-CC72F073B54E}</Project>
<Project>{9D6D76D0-B250-4262-B970-52DAE6764B88}</Project>
<Name>CollectionView</Name>
</ProjectReference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CollectionView.Droid/CollectionViewAdapter.cs
Expand Up @@ -33,7 +33,7 @@ public class CollectionViewAdapter : RecyclerView.Adapter, AView.IOnClickListene
Context _context;
RecyclerView _recyclerView;
ICollectionViewRenderer _collectionViewRenderer;
List<ViewHolder> _viewHolders = new List<ViewHolder>();
List<CollectionViewHolder> _viewHolders = new List<CollectionViewHolder>();
Dictionary<DataTemplate, int> _templateToId = new Dictionary<DataTemplate, int>();

IListViewController Controller => _collectionView;
Expand Down
10 changes: 8 additions & 2 deletions CollectionView.Droid/GridCollectionViewRenderer.cs
Expand Up @@ -466,9 +466,15 @@ public override void GetItemOffsets(Android.Graphics.Rect outRect, Android.Views
{
outRect.Left = spanIndex * _parentRenderer.ColumnSpacing / _spanCount; // column * ((1f / spanCount) * spacing)
outRect.Right = _parentRenderer.ColumnSpacing - (spanIndex + 1) * _parentRenderer.ColumnSpacing / _spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing)
}
}

// Group bottom spacing is applied at the last cell.
if (_parentRenderer.Element.IsGroupingEnabled && position >= _parentRenderer.Adapter.ItemCount - _spanCount)
{
outRect.Bottom = _parentRenderer._lastSpacing;
}

if(position < _spanCount || _parentRenderer.Adapter.FirstSectionItems.Contains(position - spanIndex)) {
if (position < _spanCount || _parentRenderer.Adapter.FirstSectionItems.Contains(position - spanIndex)) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions CollectionView.Droid/ViewHolder.cs
Expand Up @@ -6,9 +6,9 @@
namespace AiForms.Renderers.Droid
{
[Android.Runtime.Preserve(AllMembers = true)]
public class ViewHolder : RecyclerView.ViewHolder
public class CollectionViewHolder : RecyclerView.ViewHolder
{
public ViewHolder(AView view) : base(view) { }
public CollectionViewHolder(AView view) : base(view) { }

protected override void Dispose(bool disposing)
{
Expand All @@ -22,7 +22,7 @@ protected override void Dispose(bool disposing)
}

[Android.Runtime.Preserve(AllMembers = true)]
public class ContentViewHolder : ViewHolder
public class ContentViewHolder : CollectionViewHolder
{
ICollectionViewRenderer _renderer;
public bool IsHeader => ItemViewType >= CollectionViewAdapter.DefaultGroupHeaderTemplateId;
Expand Down
3 changes: 2 additions & 1 deletion CollectionView.iOS/CollectionView.iOS.csproj
Expand Up @@ -9,6 +9,7 @@
<RootNamespace>AiForms.Renderers.iOS</RootNamespace>
<AssemblyName>CollectionView.iOS</AssemblyName>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<ReleaseVersion>1.1.2</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -85,7 +86,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CollectionView\CollectionView.csproj">
<Project>{D5C93D88-A5D6-4843-935B-CC72F073B54E}</Project>
<Project>{9D6D76D0-B250-4262-B970-52DAE6764B88}</Project>
<Name>CollectionView</Name>
</ProjectReference>
</ItemGroup>
Expand Down
14 changes: 8 additions & 6 deletions CollectionView.iOS/CollectionViewRenderer.cs
Expand Up @@ -214,12 +214,14 @@ protected virtual void UpdateBackgroundColor()

protected virtual void OnGroupedCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{

var til = (TemplatedItemsList<ItemsView<Cell>, Cell>)sender;

var templatedItems = TemplatedItemsView.TemplatedItems;
var groupIndex = templatedItems.IndexOf(til.HeaderContent);

// On iOS, sometimes the groupIndex can't be correctly got using
// "templatedItems.IndexOf(til.HeaderContent)" for some reason.
// So BindingContext instead of HeaderContent is used and got the group index.
var groupIndex = TemplatedItemsView.TemplatedItems.ListProxy.IndexOf(til.BindingContext);
UpdateItems(e, groupIndex, false);
}

Expand Down Expand Up @@ -247,10 +249,10 @@ protected virtual void UpdateItems(NotifyCollectionChangedEventArgs e, int secti

// HACK: When an item is added for the first time, UICollectionView is sometimes crashed for some reason.
// So, in that case, ReloadData is called.
//if (!Control.IndexPathsForVisibleItems.Any())
//{
// groupReset = true;
//}
if (!Control.IndexPathsForVisibleItems.Any())
{
groupReset = true;
}

// We can't do this check on grouped lists because the index doesn't match the number of rows in a section.
// Likewise, we can't do this check on lists using RecycleElement because the number of rows in a section will remain constant because they are reused.
Expand Down
1 change: 1 addition & 0 deletions CollectionView.iOS/CollectionViewSource.cs
Expand Up @@ -68,6 +68,7 @@ public override nint NumberOfSections(UICollectionView collectionView)
{
return TemplatedItemsView.TemplatedItems.Count;
}

return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions CollectionView.iOS/GridCollectionViewRenderer.cs
Expand Up @@ -11,6 +11,8 @@
using Foundation;
using System.Collections.Generic;
using CoreFoundation;
using System.Collections.Specialized;
using Xamarin.Forms.Internals;

[assembly: ExportRenderer(typeof(GridCollectionView), typeof(GridCollectionViewRenderer))]
namespace AiForms.Renderers.iOS
Expand Down
8 changes: 1 addition & 7 deletions CollectionView.iOS/HCollectionViewRenderer.cs
Expand Up @@ -136,13 +136,7 @@ protected override void OnGroupedCollectionChanged(object sender, NotifyCollecti
return;
}

var til = (TemplatedItemsList<ItemsView<Cell>, Cell>)sender;
// When scroll orientation is horizontal, the groupIndex can't be correctly got using
// "templatedItems.IndexOf(til.HeaderContent)" for some reason.
// So BindingContext instead of HeaderContent is used and got the group index.
var groupIndex = TemplatedItemsView.TemplatedItems.ListProxy.IndexOf(til.BindingContext);

UpdateItems(e, groupIndex, false);
base.OnGroupedCollectionChanged(sender, e);
}

protected override void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down
12 changes: 11 additions & 1 deletion CollectionView/CollectionView.csproj
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>AiForms.Renderers</RootNamespace>
<ReleaseVersion>1.1.2</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -20,4 +19,15 @@
<ItemGroup>
<Compile Remove="Cells\CententCellBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md">
<Link>README.md</Link>
</None>
<None Include="..\README-ja.md">
<Link>README-ja.md</Link>
</None>
<None Include="..\nuget\AzurePipelines.nuspec">
<Link>AzurePipelines.nuspec</Link>
</None>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Sample/Sample.Droid/Properties/AndroidManifest.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="kamusoft.sample">
<uses-sdk android:minSdkVersion="22" />
<application android:label="Sample"></application>
Expand Down
1 change: 0 additions & 1 deletion Sample/Sample.Droid/Sample.Droid.csproj
Expand Up @@ -16,7 +16,6 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
11 changes: 5 additions & 6 deletions Sample/Sample/ViewModels/Tests/RowSpacingAndHeightTest.cs
Expand Up @@ -61,12 +61,11 @@ public void GroupHeaderHeight()
VM.HeaderHeight.Value *= 2;
}


[Test(Message = "Has HeaderCell position been released from sticky? (iOS)")]
public void Sticky()
{
VM.IsGroupHeaderSticky.Value = false;
}
//[Test(Message = "Has HeaderCell position been released from sticky? (iOS)")]
//public void Sticky()
//{
// VM.IsGroupHeaderSticky.Value = false;
//}

}
}
56 changes: 56 additions & 0 deletions Sample/Sample/Views/SurveyPage.xaml
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:cv="clr-namespace:AiForms.Renderers;assembly=CollectionView"
xmlns:ff="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Sample.Views.SurveyPage">

<cv:GridCollectionView
x:Name="collectionView"
ItemsSource="{Binding BookList}"
ItemTapCommand="{Binding SelectCommand}"
ItemLongTapCommand="{Binding DeleteCommand}"
TouchFeedbackColor="#80FF0000"
IsGroupingEnabled="true"
IsPullToRefreshEnabled="true"
RefreshCommand="{Binding RefreshCommand}"
IsRefreshing="{Binding IsRefreshing.Value}"
GroupHeaderHeight="30"
GroupFirstSpacing="6"
GroupLastSpacing="16"
BothSidesMargin="6"
ColumnSpacing="10"
RowSpacing="6"
GridType="UniformGrid"
PortraitColumns="3"
SpacingType="Center"
ColumnWidth="80" ColumnHeight="1.0" AdditionalHeight="10" >

<ListView.GroupHeaderTemplate>
<DataTemplate>
<cv:ContentCell>
<FlexLayout Direction="Row" JustifyContent="Start" AlignItems="Center"
BackgroundColor="Silver" HeightRequest="30">
<Label Text="{Binding Title}" TextColor="Black"
FontSize="12" Margin="10,0,0,0" />
</FlexLayout>
</cv:ContentCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>

<ListView.ItemTemplate>
<DataTemplate>
<cv:ContentCell>
<StackLayout Spacing="0" CompressedLayout.IsHeadless="true">
<ff:CachedImage HorizontalOptions="FillAndExpand"
HeightRequest="{Binding ComputedWidth,Source={x:Reference collectionView}}" Aspect="AspectFill"
InputTransparent="true" Source="{Binding Image}" />
<Label LineBreakMode="TailTruncation" Text="{Binding Name}" HorizontalTextAlignment="Center" VerticalTextAlignment="Start" FontSize="9" />
</StackLayout>
</cv:ContentCell>
</DataTemplate>
</ListView.ItemTemplate>

</cv:GridCollectionView>
</ContentPage>
15 changes: 15 additions & 0 deletions Sample/Sample/Views/SurveyPage.xaml.cs
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace Sample.Views
{
public partial class SurveyPage : ContentPage
{
public SurveyPage()
{
InitializeComponent();
}
}
}

0 comments on commit 92d63fd

Please sign in to comment.