Skip to content

Commit

Permalink
Merge pull request #1 from muak/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
muak authored Oct 29, 2018
2 parents 905fac0 + d71af22 commit fd27113
Show file tree
Hide file tree
Showing 49 changed files with 1,604 additions and 828 deletions.
3 changes: 3 additions & 0 deletions AiForms.CollectionView.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|iPhoneSimulator = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6E8E8AAC-E482-4E9C-9759-27B03E4DC309}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -25,5 +26,7 @@ Global
{56F75955-E569-43D2-B6C7-5C2BB4E72FD3}.Release|Any CPU.Build.0 = Release|Any CPU
{56F75955-E569-43D2-B6C7-5C2BB4E72FD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56F75955-E569-43D2-B6C7-5C2BB4E72FD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56F75955-E569-43D2-B6C7-5C2BB4E72FD3}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{56F75955-E569-43D2-B6C7-5C2BB4E72FD3}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion CollectionView.Droid/CollectionView.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CollectionView\CollectionView.csproj">
<Project>{6E8E8AAC-E482-4E9C-9759-27B03E4DC309}</Project>
<Project>{D5C93D88-A5D6-4843-935B-CC72F073B54E}</Project>
<Name>CollectionView</Name>
</ProjectReference>
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion CollectionView.Droid/CollectionViewAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int positi
var group = 0;
var templatedItems = TemplatedItemsView.TemplatedItems;
if (_collectionView.IsGroupingEnabled)
{
group = templatedItems.GetGroupIndexFromGlobal(realPosition, out row);

if (group < 0) return;
}
var templatedList = templatedItems.GetGroup(group);

if (_collectionView.IsGroupingEnabled)
Expand All @@ -423,6 +425,8 @@ public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int positi
return;
}

if (cell == null) return;

AView view = GetCell(cell, container, _recyclerView, _context, _collectionView);


Expand Down
33 changes: 28 additions & 5 deletions CollectionView.Droid/GridCollectionViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class GridCollectionViewRenderer : CollectionViewRenderer, SwipeRefreshLa
public int RowSpacing { get; set; }
public int ColumnSpacing { get; set; }

int _bothSidesMargin;
int _firstSpacing;
int _lastSpacing;

SwipeRefreshLayout _refresh;
GridLayoutManager _gridLayoutManager => LayoutManager as GridLayoutManager;
CollectionViewSpanSizeLookup _spanSizeLookup;
Expand All @@ -43,6 +47,7 @@ protected override void Dispose(bool disposing)

if (disposing)
{
RecyclerView?.StopScroll();
RecyclerView?.SetAdapter(null);
RecyclerView?.RemoveItemDecoration(_itemDecoration);
_gridLayoutManager?.SetSpanSizeLookup(null);
Expand Down Expand Up @@ -126,7 +131,10 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
e.PropertyName == GridCollectionView.ColumnHeightProperty.PropertyName ||
e.PropertyName == GridCollectionView.ColumnWidthProperty.PropertyName ||
e.PropertyName == GridCollectionView.SpacingTypeProperty.PropertyName ||
e.PropertyName == GridCollectionView.AdditionalHeightProperty.PropertyName)
e.PropertyName == GridCollectionView.AdditionalHeightProperty.PropertyName ||
e.PropertyName == CollectionView.GroupFirstSpacingProperty.PropertyName ||
e.PropertyName == CollectionView.GroupLastSpacingProperty.PropertyName ||
e.PropertyName == GridCollectionView.BothSidesMarginProperty.PropertyName)
{
UpdateGridType();
RefreshAll();
Expand Down Expand Up @@ -250,6 +258,9 @@ protected virtual void UpdateGridType(int containerWidth = 0)
RecyclerView.SetPadding(0, 0, 0, 0);
RowSpacing = (int)Context.ToPixels(_gridCollectionView.RowSpacing);

_firstSpacing = (int)Context.ToPixels(_gridCollectionView.GroupFirstSpacing);
_lastSpacing = (int)Context.ToPixels(_gridCollectionView.GroupLastSpacing);

int spanCount = 0;
if (_gridCollectionView.GridType == GridType.UniformGrid)
{
Expand All @@ -265,6 +276,7 @@ protected virtual void UpdateGridType(int containerWidth = 0)
spanCount = _gridCollectionView.LandscapeColumns;
break;
}
_bothSidesMargin = (int)Context.ToPixels(_gridCollectionView.BothSidesMargin);
ColumnSpacing = (int)(Context.ToPixels(_gridCollectionView.ColumnSpacing));
CellHeight = GetUniformItemHeight(containerWidth, spanCount);
System.Diagnostics.Debug.WriteLine($"Decided RowHeight {CellHeight}");
Expand Down Expand Up @@ -295,7 +307,8 @@ protected virtual double CalcurateColumnHeight(double itemWidth)

protected virtual int GetUniformItemHeight(int containerWidth, int columns)
{
float actualWidth = containerWidth - (float)ColumnSpacing * (float)(columns - 1.0f);
RecyclerView.SetPadding(_bothSidesMargin, 0, _bothSidesMargin, 0);
float actualWidth = containerWidth - _bothSidesMargin * 2f - (float)ColumnSpacing * (float)(columns - 1.0f);
var itemWidth = (float)(actualWidth / (float)columns);
_gridCollectionView.SetValue(GridCollectionView.ComputedWidthProperty, Context.FromPixels(itemWidth));
return (int)CalcurateColumnHeight(itemWidth);
Expand Down Expand Up @@ -413,13 +426,14 @@ public override void GetItemOffsets(Android.Graphics.Rect outRect, Android.Views
var param = view.LayoutParameters as GridLayoutManager.LayoutParams;
var spanIndex = param.SpanIndex;
var spanSize = param.SpanSize;
var position = parent.GetChildAdapterPosition(view);

if (spanSize == _spanCount)
{
var headparams = view.LayoutParameters as ViewGroup.MarginLayoutParams;
var margin = 0;
if (_gridCollectionView.GridType == GridType.AutoSpacingGrid &&
_gridCollectionView.SpacingType == SpacingType.Center)
if (_gridCollectionView.GridType == GridType.AutoSpacingGrid && _gridCollectionView.SpacingType == SpacingType.Center ||
_gridCollectionView.GridType == GridType.UniformGrid && _gridCollectionView.BothSidesMargin > 0)
{
margin = _parentRenderer.RecyclerView.PaddingLeft * -1;
headparams.SetMargins(margin, headparams.TopMargin, margin, headparams.BottomMargin);
Expand All @@ -430,6 +444,11 @@ public override void GetItemOffsets(Android.Graphics.Rect outRect, Android.Views
headparams.SetMargins(margin, headparams.TopMargin, margin, headparams.BottomMargin);
view.LayoutParameters = headparams;
}

outRect.Bottom = _parentRenderer._firstSpacing;
if(position != 0) {
outRect.Top = _parentRenderer._lastSpacing;
}
return;
}

Expand All @@ -447,9 +466,13 @@ 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)
}

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

outRect.Bottom = _parentRenderer.RowSpacing;
outRect.Top = _parentRenderer.RowSpacing;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions CollectionView.Droid/HCollectionViewAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ protected override void OnCollectionChanged(object sender, NotifyCollectionChang

public override int GetRealPosition(int position)
{
if (_listCount == 0)
{
return position;
}
return _hCollectionView.IsInfinite ? position % _listCount : position;
}

Expand Down
23 changes: 21 additions & 2 deletions CollectionView.Droid/HCollectionViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class HCollectionViewRenderer : CollectionViewRenderer, ICollectionViewRe
HCollectionViewAdapter _hAdapter => Adapter as HCollectionViewAdapter;
int _spacing;
bool _disposed;
int _firstSpacing;
int _lastSpacing;

public HCollectionViewRenderer(Context context) : base(context)
{
Expand All @@ -31,6 +33,7 @@ protected override void Dispose(bool disposing)
}
if (disposing)
{
RecyclerView?.StopScroll();
RecyclerView?.SetAdapter(null);
RecyclerView?.RemoveItemDecoration(_itemDecoration);

Expand Down Expand Up @@ -89,7 +92,9 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateGroupHeaderWidth();
RefreshAll();
}
else if (e.PropertyName == HCollectionView.SpacingProperty.PropertyName)
else if (e.PropertyName == HCollectionView.SpacingProperty.PropertyName ||
e.PropertyName == CollectionView.GroupFirstSpacingProperty.PropertyName ||
e.PropertyName == CollectionView.GroupLastSpacingProperty.PropertyName)
{
UpdateSpacing();
RefreshAll();
Expand Down Expand Up @@ -164,6 +169,8 @@ protected virtual void UpdateCellSize()
protected virtual void UpdateSpacing()
{
_spacing = (int)Context.ToPixels(_hCollectionView.Spacing);
_firstSpacing = (int)Context.ToPixels(_hCollectionView.GroupFirstSpacing);
_lastSpacing = (int)Context.ToPixels(_hCollectionView.GroupLastSpacing);
}

protected virtual void UpdateGroupHeaderWidth()
Expand Down Expand Up @@ -202,7 +209,19 @@ public override void GetItemOffsets(Rect outRect, Android.Views.View view, Recyc
{
realPosition = _renderer.Adapter.GetRealPosition(position);
}
if (position == 0 || holder.IsHeader || _renderer.Adapter.FirstSectionItems.Contains(realPosition))

if(holder.IsHeader)
{
outRect.Right = _renderer._firstSpacing;
if (position != 0)
{
outRect.Left = _renderer._lastSpacing;
}

return;
}

if (position == 0 || _renderer.Adapter.FirstSectionItems.Contains(realPosition))
{
return;
}
Expand Down
8 changes: 7 additions & 1 deletion CollectionView.iOS/CollectionView.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<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 @@ -79,10 +78,17 @@
<Compile Include="HCollectionViewSource.cs" />
<Compile Include="GridCollectionViewSource.cs" />
<Compile Include="KeyboardInsetTracker.cs" />
<Compile Include="GridViewLayout.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CollectionView\CollectionView.csproj">
<Project>{D5C93D88-A5D6-4843-935B-CC72F073B54E}</Project>
<Name>CollectionView</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<Import Project="..\packages\Xamarin.Forms.3.2.0.839982\build\netstandard2.0\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.3.2.0.839982\build\netstandard2.0\Xamarin.Forms.targets')" />
</Project>
8 changes: 4 additions & 4 deletions CollectionView.iOS/CollectionViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,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
19 changes: 17 additions & 2 deletions CollectionView.iOS/CollectionViewSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ protected override void Dispose(bool disposing)

public override nint NumberOfSections(UICollectionView collectionView)
{
if (TemplatedItemsView.TemplatedItems.Count == 0)
{
return 0;
}

if (CollectionView.IsGroupingEnabled)
{
return TemplatedItemsView.TemplatedItems.Count;
Expand Down Expand Up @@ -168,15 +173,14 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec

Performance.Start(out string reference);


var cachingStrategy = CollectionView.CachingStrategy;
if (cachingStrategy == ListViewCachingStrategy.RetainElement)
{
nativeCell = GetNativeHeaderCell(realIndexPath);
}
else if ((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0)
{
var id = TemplateIdForPath(realIndexPath);

// Here is used the argument indexPath as it is because header cell will be got not to displayed when IsInfinite.
nativeCell = collectionView.DequeueReusableSupplementaryView(
UICollectionElementKindSection.Header,
Expand Down Expand Up @@ -278,6 +282,17 @@ protected virtual ContentCellContainer GetNativeHeaderCell(NSIndexPath indexPath

var nativeCell = renderer.GetCell(cell, reusableCell, _uiCollectionView) as ContentCellContainer;

var cellWithContent = nativeCell;

// Sometimes iOS for returns a dequeued cell whose Layer is hidden.
// This prevents it from showing up, so lets turn it back on!
if (cellWithContent.Layer.Hidden)
cellWithContent.Layer.Hidden = false;

// Because the layer was hidden we need to layout the cell by hand
if (cellWithContent != null)
cellWithContent.LayoutSubviews();

return nativeCell;
}

Expand Down
Loading

0 comments on commit fd27113

Please sign in to comment.