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

[iOS] Scroll with the keyboard to not block entries and editors #13499

Merged
merged 22 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
tj-devel709 marked this conversation as resolved.
Show resolved Hide resolved
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")]
tj-devel709 marked this conversation as resolved.
Show resolved Hide resolved
internal class KeyboardInsetTracker : IDisposable
{
readonly Func<UIWindow> _fetchWindow;
Expand Down
3 changes: 2 additions & 1 deletion src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CoreGraphics;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;
using Microsoft.Maui.Platform;
using ObjCRuntime;
using UIKit;
using Size = Microsoft.Maui.Graphics.Size;
Expand All @@ -17,7 +18,7 @@ public partial class ScrollViewHandler : ViewHandler<IScrollView, UIScrollView>

protected override UIScrollView CreatePlatformView()
{
return new UIScrollView();
return new MauiScrollView();
}

protected override void ConnectHandler(UIScrollView platformView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ static void OnConfigureLifeCycle(IiOSLifecycleBuilder iOS)
.OnPlatformWindowCreated((window) =>
{
window.GetWindow()?.Created();
KeyboardAutoManagerScroll.Init();
tj-devel709 marked this conversation as resolved.
Show resolved Hide resolved
})
.WillTerminate(app =>
{
// By this point if we were a multi window app, the GetWindow would be null anyway
app.GetWindow()?.Destroying();
KeyboardAutoManagerScroll.Destroy();
})
.WillEnterForeground(app =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/KeyboardAutoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static void GoToNextResponderOrResign(UIView view, UIView? customSuperV
return;
}

var superview = customSuperView ?? view.FindResponder<ContainerViewController>()?.View;
var superview = customSuperView ?? view.SetContainerView();
if (superview is null)
{
view.ResignFirstResponder();
Expand Down
Loading