Android EditText Binding is broken after MvvmCross update from 4.2.3 to 4.4.0 with Linker enabled
Asked Answered
M

1

5

My MvvmCross Android app which was working before now is broken because of MvvmCross update from 4.2.3 to 4.4.0

<EditText
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   local:MvxBind="Text Login" />

public string Login
{
    get { return _login; }
    set { SetProperty(ref _login, value); }
}

LinkerPleaseInclude if of course there:

public void Include(EditText text)
        {
            text.Enabled = !text.Enabled;
            text.TextChanged += (sender, args) => text.Text = "" + text.Text;
            text.Hint = "" + text.Hint;
            text.Click += (s, e) => text.Visibility = text.Visibility - 1;
        }

        public void Include(TextView text)
        {
            text.TextChanged += (sender, args) => text.Text = "" + text.Text;
            text.Hint = "" + text.Hint;
            text.Click += (s, e) => text.Text = text.Text + "";
        }

Linker "SDK Only" enabled. For disabled linker it works fine. Other bindings works fine as well (button clicks, visibilities, etc).

How to tell linker to handle this properly? What could be wrong here?

Menagerie answered 4/11, 2016 at 22:48 Comment(3)
The binding is using the AfterTextChanged event and not TextChangedResiniferous
it was actually related to TargetPlatform update from 6 to 7 which brought some changes in linker and as a result broken binding for EditText. Adding AfterTextChanged to LinkerPleaseInclude fixed the issue. Thanks! Please post your comment as a response and I'll mark it as an answer.Menagerie
@AlexeyStrakh - is there a list in Mvvmcross documentation of what properties were broken as a result of the linker changes, or is this the only one?Leroylerwick
R
14

The binding target for EditText and TextView uses the AfterTextChanged event, which probably gets linked away. Add that to your Include methods instead of TextChanged and it should work:

public void Include(TextView text)
{
    text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
    text.Hint = "" + text.Hint;
    text.Click += (s, e) => text.Text = text.Text + "";
}

I don't think you need a separate method for EditText as EditText inherits from TextView.

Resiniferous answered 4/11, 2016 at 23:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.