Forked from softlion/TextViewImeActionBinding.axml
Last active
January 2, 2016 07:39
-
-
Save slodge/8270923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TextViewImeActionBinding : MvxAndroidTargetBinding | |
{ | |
private bool subscribed; | |
private ICommand _command; | |
protected TextView TextView | |
{ | |
get { return Target as TextView; } | |
} | |
public static void Register(IMvxTargetBindingFactoryRegistry registry) | |
{ | |
registry.RegisterCustomBindingFactory<TextView>("ImeAction", view => new TextViewImeActionBinding(view)); | |
} | |
public TextViewImeActionBinding(TextView view) : base(view) | |
{ | |
if (view == null) | |
Mvx.Trace(MvxTraceLevel.Error, "TextViewImeActionBinding : view is null"); | |
if (view != null) | |
{ | |
TextView.EditorAction += ViewOnEditorAction; | |
subscribed = true; | |
} | |
} | |
private void ViewOnEditorAction(object sender, TextView.EditorActionEventArgs args) | |
{ | |
FireValueChanged(args.ActionId); | |
//args.ActionId | |
args.Handled = true; | |
if (_command == null) | |
return; | |
_command.Execute(((TextView)sender).Text); | |
} | |
public override Type TargetType | |
{ | |
get { return typeof(ICommand); } | |
} | |
public override MvxBindingMode DefaultMode | |
{ | |
get { return MvxBindingMode.OneWay; } | |
} | |
protected override void SetValueImpl(object target, object value) | |
{ | |
_command = (ICommand)value; | |
} | |
protected override void Dispose(bool isDisposing) | |
{ | |
if (isDisposing) | |
{ | |
var view = TextView; | |
if (view != null && subscribed) | |
{ | |
view.EditorAction -= ViewOnEditorAction; | |
} | |
} | |
base.Dispose(isDisposing); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TextView | |
local:MvxBind="Text PasswordConfirm; ImeAction RegisterCommand" | |
android:textAppearance="?android:attr/textAppearanceLarge" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="Password" | |
android:inputType="textPassword" | |
android:imeOptions="actionSend" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh ! It works !!
I checked value in the debugger, but was not able to find an ICommand in it. Should be caused by an "incorrect" binding mode.
But should'nt it be a OneWayToSource binding ? (from target view to source viewmodel ?)
And because the binding mode is set to OneWay, SubscribeToEvents is not called anymore. That's why you removed it :)
I update the gist, as i fixed other errors. You can put the code in vnext if you want.