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 4 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
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>
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();
}
}
}
27 changes: 27 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19500.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.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]
public void TextInEditorShouldScroll()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.Windows });

_ = App.WaitForElement("editor");
App.ScrollDown("editor");

// The test passes if the text inside the editor scrolls down
VerifyScreenshot();
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
4 changes: 2 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,12 @@ 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.Editable = editor.IsEnabled && !editor.IsReadOnly;
}

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

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 @@ -505,7 +505,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