maui icon indicating copy to clipboard operation
maui copied to clipboard

Setting entry text from binding before user interaction sets null on iOS

Open benOnside opened this issue 9 months ago • 1 comments

Description

I have a numeric Entry, I can type in it with no issues. Then I add some buttons which change the value, converting it from string to int then incrementing or decrementing. By debugging I can see that the binding setter is called, and onpropertychanged is called, but I see the value disappear on iOS as soon as I press one of the buttons. If I type in the entry and then press the buttons, no issue.

Steps to Reproduce

  1. Create numeric Entry
  2. Create buttons to change the value bound to the entry (via ViewModel)
  3. Press buttons before interacting with the entry

Expected result:

  • Changed value should appear

Actual result:

  • Text disappears in entry, and stays disappeared.

Link to public reproduction project repository

No response

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

I have written a workaround by using AppendToMapping:

(in Startup.cs) EntryHandler.Mapper.AppendToMapping(nameof(Entry), EntryMapping.Map);

(EntryMapping.cs class)

public partial class EntryMapping
{
    public static void Map(IEntryHandler handler, IEntry view)
    {
        handler.PlatformView.BackgroundColor = UIKit.UIColor.Clear;
        handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
        if (view is Entry entry)
        {
            entry.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(entry.Text))
                {
                    handler.PlatformView.Text = entry.Text;
                }
            };
        }
    }
}

This resolves the issue, but I would prefer not to have this additional complexity.

Relevant log output

No response

benOnside avatar May 12 '24 23:05 benOnside

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar May 12 '24 23:05 github-actions[bot]

Verified on 17.11.0 Preview 1.1 (8.0.40&8.0.21&8.0.7&8.0.3). Can not repro this issue. MauiApp3.zip

kevinxufei avatar Jun 07 '24 02:06 kevinxufei

Hi @benOnside. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.