Skip to content

Commit

Permalink
Merge pull request #223 from nventive/release/beta/X
Browse files Browse the repository at this point in the history
Additional fixes for beta
  • Loading branch information
jeromelaban authored Sep 27, 2018
2 parents a225617 + 054269a commit a4dc359
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 77 deletions.
11 changes: 11 additions & 0 deletions Doc/ReleaseNotes/_ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release notes

## Next version

### Features

### Breaking changes

### Bug fixes

* 129762 - Updated Android SimpleOrientationSensor calculations based on SensorType.Gravity or based on single angle orientation when the device does not have a Gyroscope.
68 changes: 43 additions & 25 deletions src/Uno.UI.Tests/ControlTests/Given_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,64 @@ namespace Uno.UI.Tests.ControlTests
public partial class Given_Control
{
[TestMethod]
public void When_ManualyApplyTemplate()
public void When_ManuallyApplyTemplate()
{
var templatedRoot = default(UIElement);
var sut = new MyControl
var current = FeatureConfiguration.Control.UseLegacyLazyApplyTemplate;
try
{
Template = new ControlTemplate(() => templatedRoot = new Grid())
};
FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = true;
var templatedRoot = default(UIElement);
var sut = new MyControl
{
Template = new ControlTemplate(() => templatedRoot = new Grid())
};

Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);
Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);

new Grid().Children.Add(sut); // This kind-of simulate that the control is in the visual tree.
new Grid().Children.Add(sut); // This kind-of simulate that the control is in the visual tree.

Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);
Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);

var applied = sut.ApplyTemplate();
var applied = sut.ApplyTemplate();

Assert.IsTrue(applied);
Assert.IsNotNull(sut.TemplatedRoot);
Assert.AreSame(templatedRoot, sut.TemplatedRoot);
Assert.IsTrue(applied);
Assert.IsNotNull(sut.TemplatedRoot);
Assert.AreSame(templatedRoot, sut.TemplatedRoot);
}
finally
{
FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = current;
}
}

[TestMethod]
public void When_ManualyApplyTemplate_OutOfVisualTree()
public void When_ManuallyApplyTemplate_OutOfVisualTree()
{
var templatedRoot = default(UIElement);
var sut = new MyControl
var current = FeatureConfiguration.Control.UseLegacyLazyApplyTemplate;
try
{
Template = new ControlTemplate(() => templatedRoot = new Grid())
};
FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = true;
var templatedRoot = default(UIElement);
var sut = new MyControl
{
Template = new ControlTemplate(() => templatedRoot = new Grid())
};

Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);
Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);

var applied = sut.ApplyTemplate();
var applied = sut.ApplyTemplate();

Assert.IsFalse(applied);
Assert.IsNull(sut.TemplatedRoot);
Assert.IsNull(templatedRoot);
Assert.IsTrue(applied);
Assert.IsNotNull(sut.TemplatedRoot);
Assert.AreSame(templatedRoot, sut.TemplatedRoot);
}
finally
{
FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = current;
}
}

public partial class MyControl : Control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,6 @@ public void When_ControlTemplate_And_Animation()
});

SUT.Template = template;

new Grid().Children.Add(SUT); // This is enough for now, but the `SUT` should be in the visual tree for its template to get applied
SUT.ApplyTemplate();

Assert.IsNotNull(anim);
Expand Down
3 changes: 0 additions & 3 deletions src/Uno.UI.Tests/ItemsControlTests/Given_ItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public void When_EarlyItems()
}
};

new Grid().Children.Add(SUT); // This is enough for now, but the `SUT` should be in the visual tree for its template to get applied
SUT.ApplyTemplate();

// Search on the panel for now, as the name lookup is not properly
// aligned on net46.
Assert.IsNotNull(panel.FindName("b1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public bool HidesIfEmpty
}
}
#endif
#if __ANDROID__ || __IOS__ || NET46 || __WASM__
#if false || false || false || false
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Controls.DataTemplateSelector HeaderTemplateSelector
{
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ private void OnTemplateChanged(DependencyPropertyChangedEventArgs e)
internal void SetUpdateControlTemplate(bool forceUpdate = false)
{
if (
(!FeatureConfiguration.Control.UseLegacyLazyApplyTemplate
|| forceUpdate
|| CanCreateTemplateWithoutParent)
&& this.HasParent() // Instead we should check if we are in a the visual tree
!FeatureConfiguration.Control.UseLegacyLazyApplyTemplate
|| forceUpdate
|| this.HasParent()
|| CanCreateTemplateWithoutParent
)
{
UpdateTemplate();
Expand Down
11 changes: 9 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/GroupStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ namespace Windows.UI.Xaml.Controls
public partial class GroupStyle
{
public DataTemplate HeaderTemplate { get; set; }
public Style HeaderContainerStyle { get; set; }
public bool HidesIfEmpty { get; set; }

#if false || false || NET46 || __WASM__
[Uno.NotImplemented]
#endif
public DataTemplateSelector HeaderTemplateSelector { get; set; }

public Style HeaderContainerStyle { get; set; }

public bool HidesIfEmpty { get; set; }
}
}
66 changes: 57 additions & 9 deletions src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBaseSource.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public static class TraceProvider
private DataTemplateSelector _currentSelector;
private Dictionary<DataTemplate, CGSize> _templateCache = new Dictionary<DataTemplate, CGSize>(DataTemplate.FrameworkTemplateEqualityComparer.Default);
private Dictionary<DataTemplate, NSString> _templateCells = new Dictionary<DataTemplate, NSString>(DataTemplate.FrameworkTemplateEqualityComparer.Default);
/// <summary>
/// The furthest item in the source which has already been materialized. Items up to this point can safely be retrieved.
/// </summary>
private NSIndexPath _lastMaterializedItem = NSIndexPath.FromRowSection(0, 0);

/// <summary>
/// Is the UICollectionView currently undergoing animated scrolling, either user-initiated or programmatic.
Expand Down Expand Up @@ -198,10 +202,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
// is used during the calculation of the layout.
// This is required for paged lists, so that the layout calculation
// does not eagerly get all the items of the ItemsSource.
if (!_materializedItems.Contains(indexPath))
{
_materializedItems.Add(indexPath);
}
UpdateLastMaterializedItem(indexPath);

var index = Owner?.XamlParent?.GetIndexFromIndexPath(IndexPath.FromNSIndexPath(indexPath)) ?? -1;

Expand Down Expand Up @@ -240,6 +241,32 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
}
}

/// <summary>
/// Update record of the furthest item materialized.
/// </summary>
/// <param name="newItem">Item currently being materialized.</param>
/// <returns>True if the value has changed and the layout would change.</returns>
internal bool UpdateLastMaterializedItem(NSIndexPath newItem)
{
if (newItem.Compare(_lastMaterializedItem) > 0)
{
_lastMaterializedItem = newItem;
return Owner.ItemTemplateSelector != null; ;
}
else
{
return false;
}
}

/// <summary>
/// Is item in the range of already-materialized items?
/// </summary>
private bool IsMaterialized(NSIndexPath itemPath) => itemPath.Compare(_lastMaterializedItem) >= 0;

// Consider group header to be materialized if first item in group is materialized
private bool IsMaterialized(int section) => section <= _lastMaterializedItem.Section;

public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
{
var index = Owner?.XamlParent?.GetIndexFromIndexPath(IndexPath.FromNSIndexPath(indexPath)) ?? -1;
Expand Down Expand Up @@ -294,14 +321,17 @@ public override UICollectionReusableView GetViewForSupplementaryElement(

else if (elementKind == NativeListViewBase.ListViewSectionHeaderElementKind)
{
// Ensure correct template can be retrieved
UpdateLastMaterializedItem(indexPath);

return GetBindableSupplementaryView(
collectionView: collectionView,
elementKind: NativeListViewBase.ListViewSectionHeaderElementKindNS,
indexPath: indexPath,
reuseIdentifier: NativeListViewBase.ListViewSectionHeaderReuseIdentifierNS,
//ICollectionViewGroup.Group is used as context for sectionHeader
context: listView.XamlParent.GetGroupAtDisplaySection(indexPath.Section).Group,
template: listView.GroupStyle?.HeaderTemplate,
template: GetTemplateForGroupHeader(indexPath.Section),
style: listView.GroupStyle?.HeaderContainerStyle
);
}
Expand Down Expand Up @@ -418,6 +448,11 @@ public override void WillEndDragging(UIScrollView scrollView, CGPoint velocity,

#endregion

internal void ReloadData()
{
_lastMaterializedItem = NSIndexPath.FromRowSection(0, 0);
}

/// <summary>
/// Get item container corresponding to an element kind (header, footer, list item, etc)
/// </summary>
Expand Down Expand Up @@ -448,12 +483,12 @@ internal CGSize GetFooterSize()
return Owner.FooterTemplate != null ? GetTemplateSize(Owner.FooterTemplate, NativeListViewBase.ListViewFooterElementKindNS) : CGSize.Empty;
}

internal CGSize GetSectionHeaderSize()
internal CGSize GetSectionHeaderSize(int section)
{
return (Owner.GroupStyle?.HeaderTemplate).SelectOrDefault(ht => GetTemplateSize(ht, NativeListViewBase.ListViewSectionHeaderElementKindNS), CGSize.Empty);
var template = GetTemplateForGroupHeader(section);
return template.SelectOrDefault(ht => GetTemplateSize(ht, NativeListViewBase.ListViewSectionHeaderElementKindNS), CGSize.Empty);
}

HashSet<NSIndexPath> _materializedItems = new HashSet<NSIndexPath>();

public virtual CGSize GetItemSize(UICollectionView collectionView, NSIndexPath indexPath)
{
Expand Down Expand Up @@ -483,7 +518,7 @@ public virtual CGSize GetItemSize(UICollectionView collectionView, NSIndexPath i

private DataTemplate GetTemplateForItem(NSIndexPath indexPath)
{
if (_materializedItems.Contains(indexPath))
if (IsMaterialized(indexPath))
{
return Owner?.ResolveItemTemplate(Owner.XamlParent.GetDisplayItemFromIndexPath(indexPath.ToIndexPath()));
}
Expand All @@ -494,6 +529,19 @@ private DataTemplate GetTemplateForItem(NSIndexPath indexPath)
}
}

private DataTemplate GetTemplateForGroupHeader(int section)
{
var groupStyle = Owner.GroupStyle;
if (IsMaterialized(section))
{
return DataTemplateHelper.ResolveTemplate(groupStyle?.HeaderTemplate, groupStyle?.HeaderTemplateSelector, Owner.XamlParent.GetGroupAtDisplaySection(section).Group);
}
else
{
return groupStyle?.HeaderTemplate;
}
}

/// <summary>
/// Gets the actual item template size, using a non-databound materialized
/// view of the template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ partial void OnUnloadedPartial()

public void Refresh()
{
CurrentAdapter?.NotifyDataSetChanged();
CurrentAdapter?.Refresh();

var isScrollResetting = NativeLayout != null && NativeLayout.ContentOffset != 0;
NativeLayout?.Refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,15 @@ void ScrollInner()
{
//Scroll to individual item, We set the UICollectionViewScrollPosition to None to have the same behavior as windows.
//We can potentially customize this By using ConvertScrollAlignment and use different alignments.
ScrollToItem(index, ConvertSnapPointsAlignmentToScrollPosition(), AnimateScrollIntoView);
var needsMaterialize = Source.UpdateLastMaterializedItem(index);
if (needsMaterialize)
{
NativeLayout.InvalidateLayout();
}

var offset = NativeLayout.GetTargetScrollOffset(index, alignment);
SetContentOffset(offset, AnimateScrollIntoView);
NativeLayout.UpdateStickyHeaderPositions();
}
}
}
Expand Down Expand Up @@ -680,6 +688,7 @@ internal void ReloadDataIfNeeded()
_needsLayoutAfterReloadData = true;
ReloadData();

Source?.ReloadData();
NativeLayout?.ReloadData();

_listEmptyLastRefresh = XamlParent?.NumberOfItems == 0;
Expand Down
Loading

0 comments on commit a4dc359

Please sign in to comment.