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] Readonly Editor - Scrolling fix #20505

Merged
merged 17 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue19500.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue19500">
<Editor
HeightRequest="100"
IsReadOnly="True"
AutomationId="editor"
Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla porttitor mauris non ornare ultrices. Ut semper ultrices justo eget semper.
Ut imperdiet dolor ut vestibulum molestie. Duis a libero ex. Etiam mi urna, lobortis sed tincidunt in, tempus eget magna. Aenean quis malesuada eros.
Phasellus felis eros, condimentum et tortor sed, condimentum convallis turpis. Sed in varius metus, at auctor orci. Maecenas luctus nibh nibh,
nec aliquam est fermentum in. Etiam consectetur lectus erat, sed placerat sapien rutrum eu. Suspendisse tincidunt fermentum tempor.
Maecenas egestas neque nec lacinia fringilla."/>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue19500.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19500, "[iOS] Editor is not be able to scroll if IsReadOnly is true", PlatformAffected.iOS)]
public partial class Issue19500 : ContentPage
{
public Issue19500()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue186751 : _IssuesUITest
public class Issue18675 : _IssuesUITest
{
public Issue186751(TestDevice device) : base(device)
public Issue18675(TestDevice device) : base(device)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue19500 : _IssuesUITest
{
public override string Issue => "[iOS] Editor is not be able to scroll if IsReadOnly is true";

public Issue19500(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Editor)]
public void TextInEditorShouldScroll()
{
_ = App.WaitForElement("editor");
App.ScrollDown("editor");

// The test passes if the text inside the editor scrolls down
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions src/Core/src/Platform/iOS/TextViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,24 @@ public static void UpdateFont(this UITextView textView, ITextStyle textStyle, IF

public static void UpdateIsReadOnly(this UITextView textView, IEditor editor)
{
textView.UserInteractionEnabled = !(editor.IsReadOnly || editor.InputTransparent);
textView.UpdateEditable(editor);
}

public static void UpdateIsEnabled(this UITextView textView, IEditor editor)
{
textView.Editable = editor.IsEnabled;
textView.UpdateEditable(editor);
}

internal static void UpdateEditable(this UITextView textView, IEditor editor)
{
var isEditable = editor.IsEnabled && !editor.IsReadOnly;

textView.Editable = isEditable;

// If the input accessory view is set, we need to hide it when the editor is read-only
// otherwise it will appear when the editor recieves focus.
if (textView.InputAccessoryView is {} view)
view.Hidden = !isEditable;
}

public static void UpdateKeyboard(this UITextView textView, IEditor editor)
Expand Down
4 changes: 3 additions & 1 deletion src/Core/src/Platform/iOS/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,9 @@ internal static Size LayoutToMeasuredSize(this IView view, double width, double

public static void UpdateInputTransparent(this UIView platformView, IViewHandler handler, IView view)
{
if (view is ITextInput textInput)
// Interaction should not be disabled for an editor if it is set as read-only
// because this prevents users from scrolling the content inside an editor.
if (view is not IEditor && view is ITextInput textInput)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is all wrong for IEntry too and we should be using the https://learn.microsoft.com/en-us/dotnet/api/uikit.uitextfielddelegate.shouldbeginediting?view=xamarin-ios-sdk-12

But this will still apply for the search bar. So we can do this (investigate at least) later.

{
platformView.UpdateInputTransparent(textInput.IsReadOnly, view.InputTransparent);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ double GetNativeUnscaledFontSize(EditorHandler editorHandler) =>
GetNativeEditor(editorHandler).Font.PointSize;

bool GetNativeIsReadOnly(EditorHandler editorHandler) =>
!GetNativeEditor(editorHandler).UserInteractionEnabled;
!GetNativeEditor(editorHandler).Editable;

bool GetNativeIsTextPredictionEnabled(EditorHandler editorHandler) =>
GetNativeEditor(editorHandler).AutocorrectionType == UITextAutocorrectionType.Yes;
Expand Down
Loading