Skip to content

Commit

Permalink
Merge pull request #13290 from unoplatform/mergify/bp/legacy/4x/pr-13272
Browse files Browse the repository at this point in the history
  • Loading branch information
agneszitte authored Aug 17, 2023
2 parents cc8bad5 + 8368aa6 commit 6baf414
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ private static void OnIsFullWindowChanged(DependencyObject sender, DependencyPro
{
sender.Maybe<MediaPlayerElement>(mpe =>
{
mpe.ToogleFullScreen((bool)args.NewValue);
mpe.ToggleFullScreen((bool)args.NewValue);
});
}

private void ToogleFullScreen(bool showFullscreen)
private void ToggleFullScreen(bool showFullscreen)
{
try
{
Expand Down Expand Up @@ -191,6 +191,8 @@ private void ToogleFullScreen(bool showFullscreen)
_mediaPlayerPresenter?.ExitFullScreen();
#endif
}
TransportControls.SetMeasureCommandBar();

}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#else
using PointerDeviceType = Windows.Devices.Input.PointerDeviceType;
using Uno.UI.Xaml.Core;

using Uno.UI.Controls.Legacy;
using Windows.UI.ViewManagement;
#endif
#if __IOS__
using UIKit;
Expand All @@ -43,6 +44,7 @@ public partial class MediaTransportControls : Control
private MediaPlayerElement? _mpe;
private readonly SerialDisposable _subscriptions = new();
private bool _isMeasureCommandBarRunning;
private bool _isMeasureCommandBarRequested;

#pragma warning disable CS0649
private bool m_transportControlsEnabled = true; // not-implemented
Expand Down Expand Up @@ -527,29 +529,30 @@ private void OnCommandBarLoaded(object? sender, RoutedEventArgs e)
if (m_tpCommandBar is not null)
{
m_tpCommandBar.Loaded -= OnCommandBarLoaded;
this.LayoutUpdated += MediaTransportControls_LayoutUpdated;
m_tpCommandBar.SizeChanged += Container_SizeChanged;
m_tpCommandBar.DynamicOverflowItemsChanging += M_tpCommandBar_DynamicOverflowItemsChanging;

}
if (_timelineContainer is not null)
{
_timelineContainer.SizeChanged += Container_SizeChanged;
}

HideMoreButtonIfNecessary();
HideCastButtonIfNecessary();
}

private void MediaTransportControls_LayoutUpdated(object? sender, object e)
{
SetMeasureCommandBar();
}
private void M_tpCommandBar_DynamicOverflowItemsChanging(CommandBar sender, DynamicOverflowItemsChangingEventArgs args)
{
SetMeasureCommandBar();
}

private void Container_SizeChanged(object sender, SizeChangedEventArgs args)
{
SetMeasureCommandBar();
}

private void HideMoreButtonIfNecessary()
{
if (m_tpCommandBar is { SecondaryCommands.Count: 0 })
Expand Down Expand Up @@ -1447,17 +1450,20 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e) // todo: maybe
Cleanup:
#endif
}
private void SetMeasureCommandBar()
public void SetMeasureCommandBar()
{
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, MeasureCommandBar);
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, MeasureCommandBar);
Thread.Yield();
}
/// <summary>
/// Measure CommandBar to fit the buttons in given width.
/// </summary>
private void MeasureCommandBar()
{
if (_isMeasureCommandBarRunning)
{
_isMeasureCommandBarRequested = true;
return;
}
if (!_isMeasureCommandBarRunning && m_tpCommandBar is { })
{
try
Expand All @@ -1467,22 +1473,40 @@ private void MeasureCommandBar()
AddMarginsBetweenGroups();
var desiredSize = m_tpCommandBar.DesiredSize;

var availableSize = this.ActualWidth;
if (IsCompact && m_tpTHLeftSidePlayPauseButton as FrameworkElement is { } ppElementy && ppElementy.Visibility == Visibility.Visible)
var availableSize = this.ActualWidth - this.Margin.Left - this.Margin.Right;
if (m_tpRightAppBarSeparator as FrameworkElement is { } rightAppBarSeparator && rightAppBarSeparator.Margin.Right > 0)
{
availableSize -= ppElementy.ActualWidth;
if (_timelineContainer as FrameworkElement is { } tlElement)
availableSize -= rightAppBarSeparator.Margin.Right;
}
if (IsCompact)
{
if (m_tpTHLeftSidePlayPauseButton as FrameworkElement is { } ppElementy && ppElementy.Visibility == Visibility.Visible)
{
if (tlElement.Visibility == Visibility.Visible && tlElement.DesiredSize.Width <= ppElementy.ActualWidth)
availableSize -= ppElementy.ActualWidth;
if (_timelineContainer as FrameworkElement is { } tlElement)
{
tlElement.Visibility = Visibility.Collapsed;
}
if (tlElement.Visibility == Visibility.Collapsed && (availableSize - desiredSize.Width) >= ppElementy.ActualWidth)
{
tlElement.Visibility = Visibility.Visible;
if (tlElement.Visibility == Visibility.Visible &&
(
tlElement.DesiredSize.Width <= ppElementy.ActualWidth ||
(availableSize - desiredSize.Width - tlElement.DesiredSize.Width) < 0
))
{
tlElement.Visibility = Visibility.Collapsed;
}
if (tlElement.Visibility == Visibility.Collapsed && (availableSize - desiredSize.Width) >= ppElementy.ActualWidth)
{
tlElement.Visibility = Visibility.Visible;
}
}
}
}
else
{
if (_timelineContainer as FrameworkElement is { } tlElement)
{
_timelineContainer.Visibility = Visibility.Visible;
}
}

DropoutOrder(availableSize, desiredSize);
AddMarginsBetweenGroups();
Expand All @@ -1501,6 +1525,10 @@ private void MeasureCommandBar()
_isMeasureCommandBarRunning = false;
}
}
if (_isMeasureCommandBarRequested)
{
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, MeasureCommandBar);
}
}
private void AddMarginsBetweenGroups()
{
Expand Down Expand Up @@ -1581,12 +1609,12 @@ private void AddMarginsBetweenGroups()
leftGap = rightGap = (totalWidth - (leftWidth + middleWidth + rightWidth)) / 2;
}

if (m_tpLeftAppBarSeparator is { })
if (m_tpLeftAppBarSeparator is { } && leftGap > 0)
{
var extraMargin = new Thickness(leftGap / 2, 0, leftGap / 2, 0);
m_tpLeftAppBarSeparator.Margin(extraMargin);
}
if (m_tpRightAppBarSeparator is { })
if (m_tpRightAppBarSeparator is { } && rightGap > 0)
{
var extraMargin = new Thickness(rightGap / 2, 0, rightGap / 2, 0);
m_tpRightAppBarSeparator.Margin(extraMargin);
Expand Down Expand Up @@ -1616,6 +1644,7 @@ private void ResetMargins()

private void DropoutOrder(double availableSize, Size desiredSize)
{
var reprocess = false;
if (m_tpCommandBar is null)
{
return;
Expand All @@ -1631,18 +1660,23 @@ private void DropoutOrder(double availableSize, Size desiredSize)
widthButton = bt.Width;
}
var infiniteBounds = new Size(double.PositiveInfinity, double.PositiveInfinity);
var difference = availableSize - desiredSize.Width;
//To avoid resize intermittent
if (difference < widthButton && difference > 0)
var limit = (int)Math.Floor(availableSize / widthButton);
if (IsCompact && _mpe?.IsFullWindow == false)
{
return;
}
var limit = availableSize > desiredSize.Width ? buttonsCount : (int)Math.Floor(availableSize / widthButton);
//Just process when have size
if (limit == 0)
{
return;
var difference = availableSize - desiredSize.Width;
//To avoid resize intermittent
if (difference < widthButton && difference > 0)
{
return;
}
limit = availableSize > desiredSize.Width ? buttonsCount : (int)Math.Floor(availableSize / widthButton);
//Just process when have size
if (limit == 0)
{
reprocess = true;
}
}

var listOrder = new List<KeyValuePair<int, UIElement>>();
for (int i = 0; i < buttonsCount; i++)
{
Expand Down Expand Up @@ -1684,7 +1718,7 @@ private void DropoutOrder(double availableSize, Size desiredSize)
}
}
//if the difference is negative, we need to reprocess
if (difference < 0)
if (reprocess)
{
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, MeasureCommandBar);
}
Expand Down

0 comments on commit 6baf414

Please sign in to comment.