using System;
using ElmSharp;
using ELayout = ElmSharp.Layout;
+using EColor = ElmSharp.Color;
namespace Xamarin.Forms.Platform.Tizen.Native
{
public class EditfieldEntry : Native.Entry
{
- public event EventHandler TextBlockFocused;
- public event EventHandler TextBlockUnfocused;
-
- public event EventHandler LayoutFocused;
- public event EventHandler LayoutUnfocused;
-
- public bool IsTextBlockFocused => _isTexstBlockFocused;
-
+ Button _clearButton;
ELayout _editfieldLayout;
+ bool _enableClearButton;
int _heightPadding = 0;
- bool _isTexstBlockFocused = false;
public EditfieldEntry(EvasObject parent) : base(parent)
{
_editfieldLayout.SetTheme("layout", "editfield", style);
}
- public override ElmSharp.Color BackgroundColor
+ public event EventHandler TextBlockFocused;
+ public event EventHandler TextBlockUnfocused;
+
+ public event EventHandler LayoutFocused;
+ public event EventHandler LayoutUnfocused;
+
+ public bool IsTextBlockFocused { get; private set; }
+
+ public override EColor BackgroundColor
{
get
{
}
}
+ public bool EnableClearButton
+ {
+ get => _enableClearButton;
+ set
+ {
+ _enableClearButton = value;
+ UpdateEnableClearButton();
+ }
+ }
+
+ public EColor ClearButtonColor
+ {
+ get => _clearButton?.GetPartColor("icon") ?? EColor.Default;
+ set
+ {
+ if (_clearButton != null)
+ {
+ _clearButton.SetPartColor("icon", value);
+ _clearButton.SetPartColor("icon_pressed", value);
+ }
+ }
+ }
+
public void SetFocusOnTextBlock(bool isFocused)
{
- AllowFocus(isFocused);
SetFocus(isFocused);
- _isTexstBlockFocused = isFocused;
+ IsTextBlockFocused = isFocused;
if (isFocused)
TextBlockFocused?.Invoke(this, EventArgs.Empty);
protected override IntPtr CreateHandle(EvasObject parent)
{
var handle = base.CreateHandle(parent);
- AllowFocus(false);
_editfieldLayout = CreateEditFieldLayout(parent);
// If true, It means, there is no extra layout on the widget handle
return _editfieldLayout;
}
+ protected override void OnTextChanged(string oldValue, string newValue)
+ {
+ base.OnTextChanged(oldValue, newValue);
+ if (EnableClearButton)
+ {
+ var emission = string.IsNullOrEmpty(newValue) ? "elm,action,hide,button" : "elm,action,show,button";
+ _editfieldLayout.SignalEmit(emission, "");
+ }
+ }
+
protected virtual ELayout CreateEditFieldLayout(EvasObject parent)
{
var layout = new ELayout(parent);
};
layout.Focused += (s, e) =>
{
- AllowFocus(false);
layout.SignalEmit("elm,state,focused", "");
LayoutFocused?.Invoke(this, EventArgs.Empty);
};
{
if (e.KeyName == "Return")
{
- if (!_isTexstBlockFocused)
+ if (!IsTextBlockFocused)
{
SetFocusOnTextBlock(true);
e.Flags |= EvasEventFlag.OnHold;
return layout;
}
+
+ protected virtual void UpdateEnableClearButton()
+ {
+ if (EnableClearButton)
+ {
+ _clearButton = new Button(_editfieldLayout)
+ {
+ Style = "editfield_clear"
+ };
+ _clearButton.AllowFocus(false);
+ _clearButton.Clicked += OnClearButtonClicked;
+
+ _editfieldLayout.SetPartContent("elm.swallow.button", _clearButton);
+ _editfieldLayout.SignalEmit("elm,action,show,button", "");
+ }
+ else
+ {
+ _editfieldLayout.SetPartContent("elm.swallow.button", null);
+ _clearButton = null;
+ }
+ }
+
+ void OnClearButtonClicked(object sender, EventArgs e)
+ {
+ Text = string.Empty;
+ }
}
}
\ No newline at end of file
-using System;
using ElmSharp;
-using EButton = ElmSharp.Button;
using EColor = ElmSharp.Color;
-using ELayout = ElmSharp.Layout;
namespace Xamarin.Forms.Platform.Tizen.Native
{
public class SearchBar : Native.EditfieldEntry
{
- EButton _clearButton;
- ELayout _layout;
-
public SearchBar(EvasObject parent) : base(parent)
{
+ EnableClearButton = true;
}
public void SetClearButtonColor(EColor color)
{
- _clearButton.Color = color;
- }
-
- protected override ElmSharp.Layout CreateEditFieldLayout(EvasObject parent)
- {
- _layout = base.CreateEditFieldLayout(parent);
-
- _clearButton = new EButton(_layout)
- {
- Style = "editfield_clear"
- };
- _clearButton.AllowFocus(false);
- _clearButton.Clicked += ClearButtonClicked;
-
- _layout.SetPartContent("elm.swallow.button", _clearButton);
- _layout.SignalEmit("elm,action,show,button", "");
-
- return _layout;
- }
-
- protected override void OnTextChanged(string oldValue, string newValue)
- {
- base.OnTextChanged(oldValue, newValue);
-
- if (String.IsNullOrEmpty(Text))
- {
- _layout.SignalEmit("elm,action,hide,button", "");
- }
- else
- {
- _layout.SignalEmit("elm,action,show,button", "");
- }
- }
-
- void ClearButtonClicked(object sender, EventArgs e)
- {
- Text = string.Empty;
+ ClearButtonColor = color;
}
}
}
\ No newline at end of file
RegisterPropertyHandler(Specific.FontWeightProperty, UpdateFontWeight);
RegisterPropertyHandler(Entry.SelectionLengthProperty, UpdateSelectionLength);
RegisterPropertyHandler(InputView.IsReadOnlyProperty, UpdateIsReadOnly);
+ RegisterPropertyHandler(Entry.ClearButtonVisibilityProperty, UpdateClearButtonVisibility);
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
void OnCompleted(object sender, EventArgs e)
{
- //TODO Consider if any other object should overtake focus
- Control.SetFocus(false);
-
+ if (Element.ReturnType == ReturnType.Next)
+ {
+ FocusSearch(true)?.SetFocus(true);
+ }
+ else
+ {
+ Control.SetFocus(false);
+ }
((IEntryController)Element).SendCompleted();
}
{
Control.IsEditable = !Element.IsReadOnly;
}
+
+ void UpdateClearButtonVisibility(bool init)
+ {
+ if (Element.ClearButtonVisibility == ClearButtonVisibility.WhileEditing)
+ {
+ if (Control is Native.EditfieldEntry editfieldEntry)
+ {
+ editfieldEntry.EnableClearButton = true;
+ }
+ }
+ else if (!init)
+ {
+ if (Control is Native.EditfieldEntry editfieldEntry)
+ {
+ editfieldEntry.EnableClearButton = false;
+ }
+ }
+ }
}
}
\ No newline at end of file