Skip to content

Commit

Permalink
fix(calendar): Fix vertical stretching (most probably not on Android …
Browse files Browse the repository at this point in the history
…and iOS)
  • Loading branch information
dr1rrb committed Jun 1, 2021
1 parent 7b8bacd commit 31ae25b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uno="using:Uno.UI.Xaml.Controls">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<StaticResource x:Key="CalendarViewFocusBorderBrush" ResourceKey="SystemControlForegroundBaseHighBrush" />
Expand Down Expand Up @@ -201,6 +202,7 @@
<Setter Property="TabNavigation" Value="Once" />
<Setter Property="BringIntoViewOnFocusChange" Value="False" />
<Setter Property="Template" Value="{StaticResource ScrollViewerScrollBarlessTemplate}" />
<Setter Property="(uno:ScrollViewer.ShouldFallBackToNativeScrollBars)" Value="False" />
</Style>
</Border.Resources>
<VisualStateManager.VisualStateGroups>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:automation="clr-namespace:Windows.UI.Xaml.Automation">
xmlns:automation="clr-namespace:Windows.UI.Xaml.Automation"
xmlns:uno="using:Uno.UI.Xaml.Controls">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<StaticResource x:Key="CalendarViewFocusBorderBrush" ResourceKey="SystemControlForegroundBaseHighBrush" />
Expand Down Expand Up @@ -200,6 +201,7 @@
<Setter Property="TabNavigation" Value="Once" />
<Setter Property="BringIntoViewOnFocusChange" Value="False" />
<Setter Property="Template" Value="{StaticResource ScrollViewerScrollBarlessTemplate}" />
<Setter Property="(uno:ScrollViewer.ShouldFallBackToNativeScrollBars)" Value="False" />
</Style>
</Border.Resources>
<VisualStateManager.VisualStateGroups>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Windows.UI.Xaml.Controls.Primitives
{
// This file is aimed to implement methods that should be implemented by the ModernCollectionBasePanel which is not present in Uno

partial class CalendarPanel : ILayoutDataInfoProvider
partial class CalendarPanel : ILayoutDataInfoProvider, ICustomScrollInfo
{
// The CalendarView has a minimum size of 296x350, any size under this one will trigger clipping
// TODO: Is this size updated according to accessibility font scale factor?
Expand Down Expand Up @@ -327,6 +327,13 @@ private void base_Initialize()
EffectiveViewportChanged += OnEffectiveViewportChanged;
}


/// <inheritdoc />
public double? ViewportWidth { get; private set; }

/// <inheritdoc />
public double? ViewportHeight { get; private set; }

#region Private and internal API required by UWP code
internal int FirstVisibleIndexBase { get; private set; } = -1;
internal int LastVisibleIndexBase { get; private set; } = -1;
Expand Down Expand Up @@ -554,6 +561,9 @@ private Size base_MeasureOverride(Size availableSize)
global::System.Diagnostics.Debug.Assert(_cache.LastIndex >= LastVisibleIndex || LastVisibleIndex == -1);
global::System.Diagnostics.Debug.Assert(Children.Count == _cache.LastIndex - _cache.FirstIndex + 1 || (_cache.LastIndex == -1 && _cache.LastIndex == -1));

// We force the parent ScrollViewer to use the same viewport as us, no matter its own stretching.
ViewportHeight = viewport.Height;

ShouldInterceptInvalidate = false;
_layoutStrategy.EndMeasure();
}
Expand Down Expand Up @@ -593,7 +603,7 @@ private Size base_ArrangeOverride(Size finalSize)

return finalSize;
}
#endregion
#endregion

private static void OnEffectiveViewportChanged(FrameworkElement sender, EffectiveViewportChangedEventArgs args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,14 @@ protected override Size MeasureOverride(Size size)

child.Measure(slotSize);

var desired = child.DesiredSize;

// Give opportunity to the the content to define the viewport size itself
(child as ICustomScrollInfo)?.ApplyViewport(ref desired);

return new Size(
Math.Min(size.Width, child.DesiredSize.Width),
Math.Min(size.Height, child.DesiredSize.Height)
Math.Min(size.Width, desired.Width),
Math.Min(size.Height, desired.Height)
);
}

Expand All @@ -170,6 +175,9 @@ protected override Size ArrangeOverride(Size finalSize)
childRect.Height = Math.Max(finalSize.Height, desiredSize.Height);

child.Arrange(childRect);

// Give opportunity to the the content to define the viewport size itself
(child as ICustomScrollInfo)?.ApplyViewport(ref finalSize);
}

return finalSize;
Expand Down
48 changes: 48 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ICustomScrollInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Linq;
using Windows.Foundation;

namespace Windows.UI.Xaml.Controls
{
internal interface ICustomScrollInfo
{
/// <summary>
/// Defines the desired viewport width, if not set, fallbacks to the default algorithm.
/// This is used in the ScrollViewer measure and in computation of all the ScrollViewer properties.
/// </summary>
public double? ViewportWidth { get; }

/// <summary>
/// Defines the desired viewport height, if not set, fallbacks to the default algorithm
/// This is used in the ScrollViewer measure and in computation of all the ScrollViewer properties.
/// </summary>
public double? ViewportHeight { get; }
}

internal static class CustomScrollInfoExtensions
{
public static void ApplyViewport(this ICustomScrollInfo scrollInfo, ref Size size)
{
if (scrollInfo.ViewportWidth is { } width)
{
size.Width = width;
}
if (scrollInfo.ViewportHeight is { } height)
{
size.Height = height;
}
}

public static void ApplyViewport(this ICustomScrollInfo scrollInfo, ref Rect rect)
{
if (scrollInfo.ViewportWidth is { } width)
{
rect.Width = width;
}
if (scrollInfo.ViewportHeight is { } height)
{
rect.Height = height;
}
}
}
}

0 comments on commit 31ae25b

Please sign in to comment.