Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberBox.NumberFormatter is not used on Android #18308

Closed
borjafdezgauna opened this issue Sep 26, 2024 · 5 comments · Fixed by #18532
Closed

NumberBox.NumberFormatter is not used on Android #18308

borjafdezgauna opened this issue Sep 26, 2024 · 5 comments · Fixed by #18532
Assignees
Labels
difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/input ⌨️ Categorizes an issue or PR as relevant to input (Button, CheckBox, Toggle, Scroll, Map, Numeric,...)

Comments

@borjafdezgauna
Copy link

borjafdezgauna commented Sep 26, 2024

Current behavior

I am binding a custom number formatter to a NumberBox component. Something like this:

public class FloatNumberRounder : INumberFormatter2, INumberParser
{
    public string FormatDouble(double value)
    {
        return number.ToString("F1", CultureInfo.InvariantCulture); //only one fraction digit
    }

    public string FormatInt(long value)
    {
        return value.ToString();
    }

    public string FormatUInt(ulong value)
    {
        return value.ToString();
    }

    public double? ParseDouble(string text)
    {
        if (Numbers.TryParseDouble(text, out double parsedNumber))
            return parsedNumber;
        return null;
    }

    public long? ParseInt(string text)
    {
        if (Numbers.TryParseInteger(text, out int parsedNumber))
            return parsedNumber;
        return null;
    }

    public ulong? ParseUInt(string text)
    {
        if (Numbers.TryParseInteger(text, out int parsedNumber))
            return (ulong) parsedNumber;
        return null;
    }
}

, which I instantiate on my class:

public INumberFormatter2 Formatter => new FloatNumberRounder ();

I then bind it in a DataTemplate:

<DataTemplate x:DataType="local:ValueHandlerModel">
  <StackPanel Orientation="Vertical">
    <NumberBox Value="{Binding Number, Mode=TwoWay}"
       SpinButtonPlacementMode="Inline"
       NumberFormatter="{x:Bind Formatter}"
       Style="{ThemeResource NumberBox}"/>
  </StackPanel>
</DataTemplate>

On Windows, it works as I expected: no matter what values I give to SmallChange and LargeChange (NumberBox), my formatter shows only one fraction digit.

On Android, an instance of FloatNumberRounder is actually instantiated, but then, when I click the arrows, none of the methods are called and, depending on the values of SmallChange/LargeChange, values show with 2 fraction digits. It is curious that, in the absence of a formatter, no random number of digits is shown due to imprecision (as it is on Windows)

Expected behavior

I would expect the instance of NumberFormatter to be used also on Android

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

No response

Affected platforms

Android

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@borjafdezgauna borjafdezgauna added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Sep 26, 2024
@MartinZikmund MartinZikmund self-assigned this Sep 30, 2024
@MartinZikmund MartinZikmund added project/input ⌨️ Categorizes an issue or PR as relevant to input (Button, CheckBox, Toggle, Scroll, Map, Numeric,...) difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI and removed triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Sep 30, 2024
@jeromelaban
Copy link
Member

Thanks for the report.

It should be supported by this portion:

var value = AcceptsExpression
? NumberBoxParser.Compute(text, numberParser)
: ApiInformation.IsTypePresent(numberParser?.GetType().FullName)
? numberParser.ParseDouble(text)

You may to try and see if other platforms are using it.

@borjafdezgauna
Copy link
Author

I have been trying to build and test it on MacOS, but no luck so far... Will let you know when I manage to build it

Thanks for the response!

@borjafdezgauna
Copy link
Author

Same behaviour on MacOS (as on Android, the custom formatter is not used)

Maybe I can try to debug that portion of the code to find out what is wrong on Android... could you please guide me? What project should I open on Windows to debug Uno on Android?

@jeromelaban
Copy link
Member

Thanks for the update. You can find debugging information in our docs and you can join our discord, the community can help as well.

@morning4coffe-dev
Copy link
Member

I was able to reproduce the same issue on Android on my side (works on WinUI, Skia, Wasm), I will try to get more details on why the calls are not being executed. My repro:

Formatting.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/input ⌨️ Categorizes an issue or PR as relevant to input (Button, CheckBox, Toggle, Scroll, Map, Numeric,...)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants