Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
Style="{StaticResource Headline}" />
<Editor
Text="Text"/>
<Label
Text="FontSize"
Style="{StaticResource Headline}" />
<Editor
FontSize="Large"
Placeholder="FontSize (Large)"
Text="FontSize (Large)"/>
<Label
Text="CharacterSpacing"
Style="{StaticResource Headline}" />
<Editor
CharacterSpacing="4"
Placeholder="CharacterSpacing (4)"
Text="CharacterSpacing (4)"/>
<Label
Text="ClearButtonVisibility = Never"
Style="{StaticResource Headline}" />
Expand Down
5 changes: 4 additions & 1 deletion src/Core/src/Handlers/Editor/EditorHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ public static void MapText(IEditorHandler handler, IEditor editor)
public static void MapTextColor(IEditorHandler handler, IEditor editor) =>
handler.PlatformView?.UpdateTextColor(editor);

public static void MapPlaceholder(IEditorHandler handler, IEditor editor) =>
public static void MapPlaceholder(IEditorHandler handler, IEditor editor)
{
handler.PlatformView?.UpdatePlaceholder(editor);
handler.UpdateValue(nameof(IEditor.CharacterSpacing));
}

public static void MapPlaceholderColor(IEditorHandler handler, IEditor editor) =>
handler.PlatformView?.UpdatePlaceholderColor(editor);
Expand Down
21 changes: 16 additions & 5 deletions src/Core/src/Platform/iOS/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class MauiTextView : UITextView
public MauiTextView()
{
_placeholderLabel = InitPlaceholderLabel();
UpdatePlaceholderLabelFrame();
Changed += OnChanged;
}

public MauiTextView(CGRect frame)
: base(frame)
{
_placeholderLabel = InitPlaceholderLabel();
UpdatePlaceholderLabelFrame();
Changed += OnChanged;
}

Expand Down Expand Up @@ -112,6 +114,8 @@ public override NSAttributedString AttributedText
public override void LayoutSubviews()
{
base.LayoutSubviews();

UpdatePlaceholderLabelFrame();
ShouldCenterVertically();
}

Expand All @@ -126,13 +130,20 @@ UILabel InitPlaceholderLabel()

AddSubview(placeholderLabel);

var edgeInsets = TextContainerInset;
var lineFragmentPadding = TextContainer.LineFragmentPadding;
return placeholderLabel;
}

placeholderLabel.TextInsets = new UIEdgeInsets(edgeInsets.Top, edgeInsets.Left + lineFragmentPadding,
edgeInsets.Bottom, edgeInsets.Right + lineFragmentPadding);
void UpdatePlaceholderLabelFrame()
{
if (Bounds != CGRect.Empty && _placeholderLabel is not null)
{
var x = TextContainer.LineFragmentPadding;
var y = TextContainerInset.Top;
var width = Bounds.Width - (x * 2);
var height = Frame.Height - (TextContainerInset.Top + TextContainerInset.Bottom);

return placeholderLabel;
_placeholderLabel.Frame = new CGRect(x, y, width, height);
}
}

void HidePlaceholderIfTextIsPresent(string? value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ public async Task PlaceholderHiddenWhenControlHasAttributedText()
Assert.True(isHidden);
}

[Fact(DisplayName = "Placeholder CharacterSpacing Initializes Correctly")]
public async Task PlaceholderCharacterSpacingInitializesCorrectly()
{
string originalText = "Test";
var xplatCharacterSpacing = 4;

var editor = new EditorStub()
{
CharacterSpacing = xplatCharacterSpacing,
Placeholder = originalText
};

var values = await GetValueAsync(editor, (handler) =>
{
return new
{
ViewValue = editor.CharacterSpacing,
PlatformViewValue = GetNativePlaceholderCharacterSpacing(handler)
};
});

Assert.Equal(xplatCharacterSpacing, values.ViewValue);
Assert.Equal(xplatCharacterSpacing, values.PlatformViewValue);
}

[Fact(DisplayName = "CharacterSpacing Initializes Correctly")]
public async Task CharacterSpacingInitializesCorrectly()
{
Expand Down Expand Up @@ -222,6 +247,11 @@ double GetNativeCharacterSpacing(EditorHandler editorHandler)
return editor.AttributedText.GetCharacterSpacing();
}

double GetNativePlaceholderCharacterSpacing(EditorHandler editorHandler)
{
return GetNativePlaceholder(editorHandler).AttributedText.GetCharacterSpacing();
}

double GetNativeUnscaledFontSize(EditorHandler editorHandler) =>
GetNativeEditor(editorHandler).Font.PointSize;

Expand Down