Skip to content

Commit

Permalink
fix(calendar): Year and Decade views are not working on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Jun 2, 2021
1 parent b44444d commit d4b1a81
Showing 1 changed file with 45 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,12 @@ private Size base_MeasureOverride(Size availableSize)
}

var viewport = GetLayoutViewport(availableSize);
if (Rows > 0 && Cols > 0)
{
// Uno: This SetViewportSize should be done in the CalendarPanel_Partial.ArrangeOverride of the Panel(not the 'base_'),
// but (due to invalid layouting event sequence in uno?) it would cause a second layout pass.
// Invoking it here makes sure that the ItemSize is valid for this measure pass.
_layoutStrategy.SetViewportSize(viewport.Size, out _);
}
_lastLayoutedViewport = viewport;

// Uno: This SetViewportSize should be done in the CalendarPanel_Partial.ArrangeOverride of the Panel(not the 'base_'),
// but (due to invalid layouting event sequence in uno?) it would cause a second layout pass.
// Invoking it here makes sure that Rows, Cols and ItemSize are valid for this measure pass.
ForceConfigViewport(viewport.Size);

_layoutStrategy.BeginMeasure();
#if __ANDROID__
Expand Down Expand Up @@ -609,7 +608,6 @@ private Size base_MeasureOverride(Size availableSize)

FirstVisibleIndexBase = Math.Max(firstVisibleIndex, startIndex);
LastVisibleIndexBase = Math.Max(FirstVisibleIndexBase, lastVisibleIndex);
_lastLayoutedViewport = viewport;
}
finally
{
Expand Down Expand Up @@ -689,28 +687,51 @@ private Size base_ArrangeOverride(Size finalSize)
#endregion

private static void OnEffectiveViewportChanged(FrameworkElement sender, EffectiveViewportChangedEventArgs args)
=> (sender as CalendarPanel)?.OnEffectiveViewportChanged(args);

private void OnEffectiveViewportChanged(EffectiveViewportChangedEventArgs args)
{
if (sender is CalendarPanel that)
_effectiveViewport = args.EffectiveViewport;

if (_host is null || _layoutStrategy is null)
{
that._effectiveViewport = args.EffectiveViewport;
return;
}

if (that._host is null || that._layoutStrategy is null || that.Cols == 0 || that.Rows == 0)
{
return;
}
var needsMeasure = ForceConfigViewport(GetLayoutViewport().Size);
if (needsMeasure || Math.Abs(_effectiveViewport.Y - _lastLayoutedViewport.Y) > (_lastLayoutedViewport.Height / Rows) * .75)
{
InvalidateMeasure();
}
}

// Uno: This SetViewportSize should be done in the CalendarPanel_Partial.ArrangeOverride of the Panel (not the 'base_'),
// but (due to invalid layouting event sequence in uno?) it would cause a second layout pass.
// Also on Android in Year and Decade views, the Arrange would never be invoked if the CellSize is not defined ...
// which is actually set **ONLY** by this SetViewport for Year and Decade host
// (We bypass the SetItemMinimumSize in the CalendarPanel_Partial.MeasureOverride if m_type is **not** CalendarPanelType.Primary)
that._layoutStrategy.SetViewportSize(that.GetLayoutViewport().Size, out var needsMeasure);
private bool ForceConfigViewport(Size viewportSize)
{
// Uno: Those SetViewportSize and SetPanelDimension should be done in the CalendarPanel_Partial.ArrangeOverride of the Panel (not the 'base_'),
// but (due to invalid layouting event sequence in uno?) it would cause a second layout pass.
// Also on Android in Year and Decade views, the Arrange would never be invoked if the CellSize is not defined (0,0) ...
// which is actually set **ONLY** by this SetViewport for Year and Decade host
// (We bypass the SetItemMinimumSize in the CalendarPanel_Partial.MeasureOverride if m_type is **not** CalendarPanelType.Primary)

if (needsMeasure || Math.Abs(that._effectiveViewport.Y - that._lastLayoutedViewport.Y) > (that._lastLayoutedViewport.Height / that.Rows) * .75)
{
that.InvalidateMeasure();
}
if (m_type == CalendarPanelType.Secondary_SelfAdaptive && m_biggestItemSize.Width > 2 && m_biggestItemSize.Height > 2)
{
int effectiveCols = (int)(viewportSize.Width / m_biggestItemSize.Width);
int effectiveRows = (int)(viewportSize.Height / m_biggestItemSize.Height);

effectiveCols = Math.Max(1, Math.Min(effectiveCols, m_suggestedCols));
effectiveRows = Math.Max(1, Math.Min(effectiveRows, m_suggestedRows));

SetPanelDimension(effectiveCols, effectiveRows);
}

if (Rows == 0 || Cols == 0)
{
return false;
}

_layoutStrategy!.SetViewportSize(viewportSize, out var needsMeasure);

return needsMeasure;
}
}

Expand Down

0 comments on commit d4b1a81

Please sign in to comment.