Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into net8.0 #14025

Merged
merged 9 commits into from
Mar 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@
Style="{StaticResource Headline}"/>
<local:CustomButton
Text="Custom Button" />
<Label
Text="HorizontalOptions"
Style="{StaticResource Headline}"/>
<Button
Text="Start"
HorizontalOptions="Start" />
<Button
Text="Center"
HorizontalOptions="Center" />
<Button
Text="End"
HorizontalOptions="End" />
</VerticalStackLayout>
</ScrollView>
</views:BasePage.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@
<Label
Text="Platform Specifics"
Style="{StaticResource Headline}"/>
<Label
Text="Mixed Content Mode"
Style="{StaticResource Headline}"/>
<Button
Text="Allow MixedContentMode"
Clicked="OnAllowMixedContentClicked"/>
<Label
Text="Zoom Controls"
Style="{StaticResource Headline}"/>
<Button
Text="Enable Zoom Controls"
Clicked="OnEnableZoomControlsClicked"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<views:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.ScrollViewPages.ScrollViewOrientationPage"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
Title="ScrollView">
<views:BasePage.Content>
<Grid Padding="12" ColumnSpacing="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Text="Change Orientation:"
Style="{StaticResource Headline}" VerticalOptions="Center" />

<Picker x:Name="Orientation" Grid.Column="1" SelectedIndex="0" SelectedIndexChanged="OrientationSelectedIndexChanged" VerticalOptions="Start">
<Picker.Items>
<x:String>Vertical</x:String>
<x:String>Horizontal</x:String>
<x:String>Both</x:String>
<x:String>Neither</x:String>
</Picker.Items>
</Picker>
<ScrollView x:Name="ScrollViewer" Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="2">
<Image Source="dotnet_bot.png" HeightRequest="1000" WidthRequest="1000" Aspect="AspectFit" />
</ScrollView>
</Grid>
</views:BasePage.Content>
</views:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages.ScrollViewPages
{
public partial class ScrollViewOrientationPage
{
public ScrollViewOrientationPage()
{
InitializeComponent();
}

public void OrientationSelectedIndexChanged(object sender, EventArgs args)
{
ScrollViewer.Orientation = (ScrollOrientation)Orientation.SelectedIndex;
}

protected override void OnAppearing()
{
Orientation.SelectedIndex = 0;
base.OnAppearing();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
new ScrollViewTemplatePageModel{ Spacing = 200, ScrollViewPadding = new Thickness(25),
ContentBackground = Colors.LightBlue, VerticalAlignment = LayoutOptions.Fill }),

new SectionModel(typeof(ScrollViewOrientationPage), "Orientation",
"Lock the orientation of your ScrollView",
new ScrollViewTemplatePageModel{ VerticalAlignment = LayoutOptions.Fill }),


};
}
Expand Down
4 changes: 3 additions & 1 deletion src/Controls/src/Core/BindableLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class BindableLayoutController
{
readonly WeakReference<IBindableLayout> _layoutWeakReference;
readonly WeakNotifyCollectionChangedProxy _collectionChangedProxy = new();
readonly NotifyCollectionChangedEventHandler _collectionChangedEventHandler;
IEnumerable _itemsSource;
DataTemplate _itemTemplate;
DataTemplateSelector _itemTemplateSelector;
Expand All @@ -220,6 +221,7 @@ class BindableLayoutController
public BindableLayoutController(IBindableLayout layout)
{
_layoutWeakReference = new WeakReference<IBindableLayout>(layout);
_collectionChangedEventHandler = ItemsSourceCollectionChanged;
}

~BindableLayoutController() => _collectionChangedProxy.Unsubscribe();
Expand All @@ -246,7 +248,7 @@ void SetItemsSource(IEnumerable itemsSource)

if (_itemsSource is INotifyCollectionChanged c)
{
_collectionChangedProxy.Subscribe(c, ItemsSourceCollectionChanged);
_collectionChangedProxy.Subscribe(c, _collectionChangedEventHandler);
}

if (!_isBatchUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Views.Animations;
using AndroidX.CardView.Widget;
using AndroidX.Core.View;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using AColor = Android.Graphics.Color;
Expand All @@ -30,7 +28,7 @@ public static IPropertyMapper<Frame, FrameRenderer> Mapper
[Frame.BorderColorProperty.PropertyName] = (h, _) => h.UpdateBorderColor(),
[Microsoft.Maui.Controls.Compatibility.Layout.IsClippedToBoundsProperty.PropertyName] = (h, _) => h.UpdateClippedToBounds(),
[Frame.ContentProperty.PropertyName] = (h, _) => h.UpdateContent(),
[nameof(IView.AutomationId)] = (h, v) => ViewHandler.MapAutomationId(h, v),
[nameof(IView.AutomationId)] = (h, v) => ViewHandler.MapAutomationId(h, v)
};

public static CommandMapper<Frame, FrameRenderer> CommandMapper
Expand All @@ -48,6 +46,9 @@ public static CommandMapper<Frame, FrameRenderer> CommandMapper
IMauiContext? _mauiContext;
ViewHandlerDelegator<Frame> _viewHandlerWrapper;
Frame? _element;
bool _hasContainer;
AView? _wrapperView;

public event EventHandler<VisualElementChangedEventArgs>? ElementChanged;
public event EventHandler<PropertyChangedEventArgs>? ElementPropertyChanged;

Expand Down Expand Up @@ -351,9 +352,31 @@ void UpdateContent()
}

#region IPlatformViewHandler
bool IViewHandler.HasContainer { get => false; set { } }

object? IViewHandler.ContainerView => null;
bool IViewHandler.HasContainer
{
get => _hasContainer;
set
{
if (_hasContainer == value)
return;

_hasContainer = value;

if (value)
SetupContainer();
else
RemoveContainer();
}
}

void SetupContainer() =>
WrapperView.SetupContainer(this, Context, _wrapperView, (cv) => _wrapperView = cv);

void RemoveContainer() =>
WrapperView.RemoveContainer(this, Context, _wrapperView, () => _wrapperView = null);

object? IViewHandler.ContainerView => _wrapperView;

IView? IViewHandler.VirtualView => Element;

Expand All @@ -365,7 +388,7 @@ void UpdateContent()

AView IPlatformViewHandler.PlatformView => this;

AView? IPlatformViewHandler.ContainerView => this;
AView? IPlatformViewHandler.ContainerView => _wrapperView;

void IViewHandler.PlatformArrange(Graphics.Rect rect) =>
this.PlatformArrangeHandler(rect);
Expand Down Expand Up @@ -396,6 +419,7 @@ void IElementHandler.DisconnectHandler()
{
_viewHandlerWrapper.DisconnectHandler();
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class ListViewRenderer : ViewRenderer<ListView, UITableView>
IPlatformViewHandler _headerRenderer;
IPlatformViewHandler _footerRenderer;

KeyboardInsetTracker _insetTracker;
RectangleF _previousFrame;
ScrollToRequestedEventArgs _requestedScroll;

Expand Down Expand Up @@ -65,7 +64,6 @@ public ListViewRenderer() : base(Mapper, CommandMapper)

public override void LayoutSubviews()
{
_insetTracker?.OnLayoutSubviews();
base.LayoutSubviews();

double height = Bounds.Height;
Expand All @@ -88,10 +86,7 @@ public override void LayoutSubviews()
}

if (_previousFrame != Frame)
{
_previousFrame = Frame;
_insetTracker?.UpdateInsets();
}
}

protected override void SetBackground(Brush brush)
Expand Down Expand Up @@ -138,12 +133,6 @@ protected override void Dispose(bool disposing)

if (disposing)
{
if (_insetTracker != null)
{
_insetTracker.Dispose();
_insetTracker = null;
}

if (Element != null)
{
var templatedItems = TemplatedItemsView.TemplatedItems;
Expand Down Expand Up @@ -242,13 +231,6 @@ protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
_tableViewController.TableView.SectionHeaderTopPadding = new nfloat(0);

_backgroundUIView = _tableViewController.TableView.BackgroundView;

_insetTracker = new KeyboardInsetTracker(_tableViewController.TableView, () => Control.Window, insets => Control.ContentInset = Control.ScrollIndicatorInsets = insets, point =>
{
var offset = Control.ContentOffset;
offset.Y += point.Y;
Control.SetContentOffset(offset, true);
}, this);
}

var listView = e.NewElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Microsoft.Maui.Controls.Handlers.Compatibility
{
[Obsolete("Scrolling is now handled by KeyboardAutoManagerScroll.")]
public class ShellScrollViewTracker : IDisposable, IShellContentInsetObserver
{
#region IShellContentInsetObserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Microsoft.Maui.Controls.Handlers.Compatibility
public class TableViewRenderer : ViewRenderer<TableView, UITableView>
{
const int DefaultRowHeight = 44;
KeyboardInsetTracker _insetTracker;
UIView _originalBackgroundView;
RectangleF _previousFrame;

Expand All @@ -28,23 +27,16 @@ protected override Size MinimumSize()

public override void LayoutSubviews()
{
_insetTracker?.OnLayoutSubviews();
base.LayoutSubviews();

if (_previousFrame != Frame)
{
_previousFrame = Frame;
_insetTracker?.UpdateInsets();
}
}

protected override void Dispose(bool disposing)
{
if (disposing && _insetTracker != null)
if (disposing)
{
_insetTracker.Dispose();
_insetTracker = null;

var viewsToLookAt = new Stack<UIView>(Subviews);
while (viewsToLookAt.Count > 0)
{
Expand Down Expand Up @@ -82,23 +74,13 @@ protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
if (Control == null || Control.Style != style)
{
if (Control != null)
{
_insetTracker.Dispose();
Control.Dispose();
}

var tv = CreateNativeControl();
_originalBackgroundView = tv.BackgroundView;

SetNativeControl(tv);
tv.CellLayoutMarginsFollowReadableWidth = false;

_insetTracker = new KeyboardInsetTracker(tv, () => Control.Window, insets => Control.ContentInset = Control.ScrollIndicatorInsets = insets, point =>
{
var offset = Control.ContentOffset;
offset.Y += point.Y;
Control.SetContentOffset(offset, true);
}, this);
}

SetSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Microsoft.Maui.Controls.Handlers.Compatibility
{
[Obsolete("Scrolling is now handled by KeyboardAutoManagerScroll.")]
internal class KeyboardInsetTracker : IDisposable
{
readonly Func<UIWindow> _fetchWindow;
Expand Down
Loading