Skip to content

Commit bed21f5

Browse files
kubaflojsuarezruiz
authored andcommitted
Add a done button to Entry
1 parent a11555b commit bed21f5

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

src/Core/src/Handlers/Editor/EditorHandler.iOS.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,10 @@ public partial class EditorHandler : ViewHandler<IEditor, MauiTextView>
1414
protected override MauiTextView CreatePlatformView()
1515
{
1616
var platformEditor = new MauiTextView();
17-
18-
#if !MACCATALYST
19-
var accessoryView = new MauiDoneAccessoryView();
20-
accessoryView.SetDataContext(this);
21-
accessoryView.SetDoneClicked(OnDoneClicked);
22-
platformEditor.InputAccessoryView = accessoryView;
23-
#endif
24-
17+
platformEditor.AddMauiDoneAccessoryView(this);
2518
return platformEditor;
2619
}
2720

28-
#if !MACCATALYST
29-
static void OnDoneClicked(object sender)
30-
{
31-
if (sender is IEditorHandler handler)
32-
{
33-
handler.PlatformView.ResignFirstResponder();
34-
handler.VirtualView.Completed();
35-
}
36-
}
37-
#endif
38-
3921
public override void SetVirtualView(IView view)
4022
{
4123
base.SetVirtualView(view);

src/Core/src/Handlers/Entry/EntryHandler.iOS.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ public partial class EntryHandler : ViewHandler<IEntry, MauiTextField>
1111
{
1212
readonly MauiTextFieldProxy _proxy = new();
1313

14-
protected override MauiTextField CreatePlatformView() =>
15-
new MauiTextField
14+
protected override MauiTextField CreatePlatformView()
15+
{
16+
var platformEntry = new MauiTextField
1617
{
1718
BorderStyle = UITextBorderStyle.RoundedRect,
1819
ClipsToBounds = true
1920
};
2021

22+
platformEntry.AddMauiDoneAccessoryView(this);
23+
return platformEntry;
24+
}
25+
2126
public override void SetVirtualView(IView view)
2227
{
2328
base.SetVirtualView(view);

src/Core/src/Platform/iOS/TextFieldExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,24 @@ internal static void UpdateClearButtonColor(this UITextField textField, IEntry e
244244

245245
return tintedImage;
246246
}
247+
248+
internal static void AddMauiDoneAccessoryView(this UITextField textField, IViewHandler handler)
249+
{
250+
#if !MACCATALYST
251+
var accessoryView = new MauiDoneAccessoryView();
252+
accessoryView.SetDataContext(handler);
253+
accessoryView.SetDoneClicked(OnDoneClicked);
254+
textField.InputAccessoryView = accessoryView;
255+
#endif
256+
}
257+
258+
static void OnDoneClicked(object sender)
259+
{
260+
if (sender is IEntryHandler entryHandler)
261+
{
262+
entryHandler.PlatformView.ResignFirstResponder();
263+
entryHandler.VirtualView.Completed();
264+
}
265+
}
247266
}
248267
}

src/Core/src/Platform/iOS/TextViewExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,24 @@ static UITextPosition GetSelectionEnd(UITextView textView, IEditor editor, UITex
177177

178178
return end;
179179
}
180+
181+
internal static void AddMauiDoneAccessoryView(this UITextView textView, IViewHandler handler)
182+
{
183+
#if !MACCATALYST
184+
var accessoryView = new MauiDoneAccessoryView();
185+
accessoryView.SetDataContext(handler);
186+
accessoryView.SetDoneClicked(OnDoneClicked);
187+
textView.InputAccessoryView = accessoryView;
188+
#endif
189+
}
190+
191+
static void OnDoneClicked(object sender)
192+
{
193+
if (sender is IEditorHandler entryHandler)
194+
{
195+
entryHandler.PlatformView.ResignFirstResponder();
196+
entryHandler.VirtualView.Completed();
197+
}
198+
}
180199
}
181200
}

0 commit comments

Comments
 (0)