Skip to content

Commit

Permalink
Merge pull request #1064 from nventive/dev/jela/ios-xaml-parent
Browse files Browse the repository at this point in the history
[iOS] Fix items dependency property propagation in ListView items
  • Loading branch information
jeromelaban authored Jun 19, 2019
2 parents 06df4f6 + 14f59ab commit 95af420
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/ReleaseNotes/_ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
* `Grid` now supports `ColumnDefinition.MinWidth` and `MaxWidth` and `RowDefinition.MinHeight` and `MaxHeight` (#1032)
* Implement the `PivotPanel` measure/arrange to allow text wrapping in pivot items
* [Wasm] Add `PathIcon` support
* [iOS] Fix items dependency property propagation in ListView items
* [Wasm] Add UI Testing support through for `Uno.UI.Helpers.Automation.GetDependencyPropertyValue`\
* Add automated UI testing support for every PR

### Breaking Changes
* The `WebAssemblyRuntime.InvokeJSUnmarshalled` method with three parameters has been removed.
Expand Down
13 changes: 9 additions & 4 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
Expand Down Expand Up @@ -833,6 +833,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Infinite_Breadth.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -2437,6 +2441,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListViewResizableText.xaml.cs">
<DependentUpon>ListViewResizableText.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Infinite_Breadth.xaml.cs">
<DependentUpon>ListView_Infinite_Breadth.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -3515,8 +3520,8 @@
<Compile Update="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\NavigationViewTests\NavigationView_TopNavigation.xaml.cs">
<DependentUpon>NavigationView_TopNavigation.xaml</DependentUpon>
</Compile>
<Compile Update="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Pivot\PivotSimpleTest.xaml.cs">
<DependentUpon>PivotSimpleTest.xaml</DependentUpon>
<Compile Update="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml.cs">
<DependentUpon>ListView_DataContext_Propagation.xaml</DependentUpon>
</Compile>
<Compile Update="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Popup\MessageDialog.xaml.cs">
<DependentUpon>MessageDialog.xaml</DependentUpon>
Expand Down Expand Up @@ -3720,4 +3725,4 @@
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ChatBox\" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.ListView.ListView_DataContext_Propagation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.ListView"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid x:Name="topGrid" DataContext="This is the datacontext">
<TextBlock x:Name="Title" Text="{Binding}"/>

<ListView
Margin="0,20,0,0"
HorizontalContentAlignment="Stretch"
SelectionMode="None"
IsItemClickEnabled="False">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<RelativePanel Margin="0,20,0,0">
<Button FontSize="12" Click="Button_Click">
<Button.Content>
<TextBlock>
<Run Text="Should be 'this is the DataContext': " />
<Run Text="{Binding Text,ElementName=Title}" />
</TextBlock>
</Button.Content>
</Button>
</RelativePanel>

</DataTemplate>
</ListView.ItemTemplate>

<x:String>Item 01</x:String>
<x:String>Item 02</x:String>
</ListView>

</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Shared.Windows_UI_Xaml_Controls.ListView
{
[SampleControlInfo("ListView", "ListView_DataContext_Propagation")]
public sealed partial class ListView_DataContext_Propagation : UserControl
{
public ListView_DataContext_Propagation()
{
this.InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
topGrid.DataContext = "Button Clicked " + sender.ToString();
}
}
}
1 change: 0 additions & 1 deletion src/Uno.UI/Controls/BindableImageView.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using Java.Lang.Ref;
using System.IO;
using Math = System.Math;
using System.Drawing;
using Size = System.Drawing.Size;
using System.Reflection;
using Windows.UI.Core;
Expand Down
9 changes: 4 additions & 5 deletions src/Uno.UI/UI/Xaml/Controls/BorderLayerRenderer.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Windows.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Drawing;
using Uno.Disposables;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void UpdateLayers(
// This is required because android Height and Width are hidden by Control.
var baseView = view as View;

Size targetSize = new Size(baseView.Width, baseView.Height);
var targetSize = new global::System.Drawing.Size(baseView.Width, baseView.Height);
var drawArea = new Windows.Foundation.Rect(0, 0, targetSize.Width, targetSize.Height);
var newState = new LayoutState(drawArea, background, borderThickness, borderBrush, cornerRadius, padding);
var previousLayoutState = _currentState;
Expand Down Expand Up @@ -239,7 +238,7 @@ Action onImageSet
{
using (var strokePaint = new Paint(borderBrush.GetStrokePaint(drawArea)))
{
var overlay = GetOverlayDrawable(strokePaint, physicalBorderThickness, new Size((int)drawArea.Width, (int)drawArea.Height), path);
var overlay = GetOverlayDrawable(strokePaint, physicalBorderThickness, new global::System.Drawing.Size((int)drawArea.Width, (int)drawArea.Height), path);

if (overlay != null)
{
Expand Down Expand Up @@ -274,7 +273,7 @@ Action onImageSet
//TODO: Handle case that BorderBrush is an ImageBrush
using (var strokePaint = borderBrush.GetStrokePaint(drawArea))
{
var overlay = GetOverlayDrawable(strokePaint, physicalBorderThickness, new Size(view.Width, view.Height));
var overlay = GetOverlayDrawable(strokePaint, physicalBorderThickness, new global::System.Drawing.Size(view.Width, view.Height));

if (overlay != null)
{
Expand Down Expand Up @@ -423,7 +422,7 @@ private static void ExecuteWithNoRelayout(BindableView target, Action<BindableVi
}
}

private static Drawable GetOverlayDrawable(Paint strokePaint, Thickness physicalBorderThickness, Size viewSize, Path path = null)
private static Drawable GetOverlayDrawable(Paint strokePaint, Thickness physicalBorderThickness, global::System.Drawing.Size viewSize, Path path = null)
{
if (strokePaint != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
}

FrameworkElement.InitializePhaseBinding(selectorItem);
}

// Ensure the item has a parent, since it's added to the native collection view
// which does not automatically sets the parent DependencyObject.
selectorItem.SetParent(Owner?.XamlParent);
}
else if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Reusing view at indexPath={indexPath}, previously bound to {selectorItem.DataContext}.");
Expand Down
1 change: 0 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Panel/Panel.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Runtime.CompilerServices;
using Android.Graphics;
using Android.Graphics.Drawables;
using System.Drawing;
using Uno.UI;
using Windows.UI.Xaml.Media;

Expand Down
9 changes: 4 additions & 5 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -26,7 +25,7 @@ public partial class ImageSource
private const string ContactUriPrefix = "content://com.android.contacts/";

private static bool _resourceCacheLock;
private static Dictionary<Tuple<int, Size?>, Bitmap> _resourceCache = new Dictionary<Tuple<int, Size?>, Bitmap>();
private static Dictionary<Tuple<int, global::System.Drawing.Size?>, Bitmap> _resourceCache = new Dictionary<Tuple<int, global::System.Drawing.Size?>, Bitmap>();

/// <summary>
/// Defines an asynchronous image loader handler.
Expand All @@ -35,7 +34,7 @@ public partial class ImageSource
/// <param name="uri">The image uri</param>
/// <param name="targetSize">An optional target decoding size</param>
/// <returns>A Bitmap instance</returns>
public delegate Task<Bitmap> ImageLoaderHandler(CancellationToken ct, string uri, Android.Widget.ImageView imageView, Size? targetSize);
public delegate Task<Bitmap> ImageLoaderHandler(CancellationToken ct, string uri, Android.Widget.ImageView imageView, global::System.Drawing.Size? targetSize);

/// <summary>
/// Provides a optional external image loader.
Expand Down Expand Up @@ -131,7 +130,7 @@ internal async Task<Bitmap> Open(CancellationToken ct, Android.Widget.ImageView
options.InJustDecodeBounds = true;

var targetSize = UseTargetSize && targetWidth != null && targetHeight != null
? (Size?)new Size(targetWidth.Value, targetHeight.Value)
? (global::System.Drawing.Size?)new global::System.Drawing.Size(targetWidth.Value, targetHeight.Value)
: null;

if (ResourceId.HasValue)
Expand Down Expand Up @@ -273,7 +272,7 @@ private static bool IsContactUri(Uri uri)
/// <param name="resourceId"></param>
/// <param name="targetSize"></param>
/// <returns></returns>
private async Task<Bitmap> FetchResourceWithDownsampling(CancellationToken ct, int resourceId, Size? targetSize)
private async Task<Bitmap> FetchResourceWithDownsampling(CancellationToken ct, int resourceId, global::System.Drawing.Size? targetSize)
{
var key = Tuple.Create(resourceId, targetSize);

Expand Down

0 comments on commit 95af420

Please sign in to comment.