提交 7c543657 编写于 作者: X xiaoy312

fix(ios): an instance of ListView crash during layout

上级 24e40d22
......@@ -34,5 +34,43 @@ namespace Uno.UI.Extensions
return output;
}
/// <summary>
/// ToDictionary that doesn't throw on duplicated key. The first value is kept per key.
/// </summary>
public static Dictionary<TKey, TElement> ToDictionaryKeepFirst<TSource, TKey, TElement>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector
) where TKey : notnull
{
var result = new Dictionary<TKey, TElement>();
foreach (var item in source)
{
result.TryAdd(keySelector(item), elementSelector(item));
}
return result;
}
/// <summary>
/// ToDictionary that doesn't throw on duplicated key. The last value is kept per key.
/// </summary>
public static Dictionary<TKey, TElement> ToDictionaryKeepLast<TSource, TKey, TElement>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector
) where TKey : notnull
{
var result = new Dictionary<TKey, TElement>();
foreach (var item in source)
{
result[keySelector(item)] = elementSelector(item);
}
return result;
}
}
}
......@@ -591,13 +591,13 @@ namespace Windows.UI.Xaml.Controls
// We are layouting after an INotifyCollectionChanged operation(s). Cache the previous element sizes, under their new index
// paths, so we can reuse them in order not to have to lay out elements with different databound sizes with their static size.
oldItemSizes = _itemLayoutInfos.SelectMany(kvp => kvp.Value)
.ToDictionary(
.ToDictionaryKeepLast(
kvp => OffsetIndexForPendingChanges(kvp.Key, NativeListViewBase.ListViewItemElementKind),
kvp => (CGSize?)kvp.Value.Size
);
oldGroupHeaderSizes = _supplementaryLayoutInfos
.UnoGetValueOrDefault(NativeListViewBase.ListViewSectionHeaderElementKind)?
.ToDictionary(
.ToDictionaryKeepLast(
kvp => OffsetIndexForPendingChanges(kvp.Key, NativeListViewBase.ListViewSectionHeaderElementKind).Section,
kvp => (CGSize?)kvp.Value.Size
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册