Skip to content

Commit

Permalink
[iOS] Readonly Editor - Scrolling fix (dotnet#20505)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Javier Suárez <[email protected]>
Co-authored-by: Matthew Leibowitz <[email protected]>
  • Loading branch information
3 people authored Aug 24, 2024
1 parent d951f76 commit c156658
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 6 deletions.
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)
{
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

0 comments on commit c156658

Please sign in to comment.