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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Tibet binding on a iOS UILabel AttributedText property gives weird results in comparison to Fluent binding #4799

Open
1 of 7 tasks
Digifais opened this issue Jan 17, 2024 · 1 comment
Labels
t/bug Bug type

Comments

@Digifais
Copy link
Contributor

Digifais commented Jan 17, 2024

馃悰 Bug Report

As discussed in Discord with @Cheesebaron regarding re-triggering value converters in Fluent bindings, I've tried using a Tibet binding instead with AttributedText and got very strange results. Instead of getting my attributed string as returned in my value converter with the correct text, it gets returned with { postfixed.

Also spans are not working anymore as in my value converter, I possibly return an attributed string with the original text, or an attributed string with a * prefixed and a foreground color span on that character. The text that shows is then *{ in all black instead of * Behaald diploma with the * in red for example.

With Fluent binding, I just get * Behaald diploma with the * in red as expected.

Expected behavior

Tibet binding returns the correct attributed string.

Reproduction steps

public class RequiredAttributedStringValueConverter : MvxValueConverter<string, NSMutableAttributedString>
{
    protected override NSMutableAttributedString Convert(string value, Type targetType, object parameter,
        CultureInfo culture)
    {
        var required = (bool?)parameter;

        var mutableString = new NSMutableAttributedString(value);
        if (required.HasValue && !required.Value)
        {
            return mutableString;
        }

        value = $"* {value}";
        mutableString = new NSMutableAttributedString(value);
        mutableString.AddAttribute(UIStringAttributeKey.ForegroundColor, Colors.Red.ToPlatformColor(),
                new NSRange(0, 1));

        return mutableString;
    }
}

Fluent binding:
set.Bind(_lblEducationYear).For(v => v.AttributedText).To(model => model.LblEducationYear).WithConversion<RequiredAttributedStringValueConverter>(((OnboardingEducationInputListItem)DataContext).ShouldValidateFields)

Tibet binding:
set.Bind(_lblEducationName, "AttributedText RequiredAttributedString(LblEducationName, ShouldValidateFields)")

Configuration

Version: 8.0.2 (can't migrate yet since project is still not on .NET)

Platform:

  • 馃摫 iOS
  • 馃 Android
  • 馃弫 WPF
  • 馃寧 UWP
  • 馃崕 MacOS
  • 馃摵 tvOS
  • 馃悞 Xamarin.Forms
@Digifais Digifais added the t/bug Bug type label Jan 17, 2024
@Digifais Digifais changed the title Using Tibet binding on a iOS UILabel AttributedText property gives weird results in comparison to Fluent binding. Using Tibet binding on a iOS UILabel AttributedText property gives weird results in comparison to Fluent binding Jan 17, 2024
@entdark
Copy link
Contributor

entdark commented Jan 17, 2024

Try

this.AddBindings(_lblEducationName, "AttributedText RequiredAttributedString(LblEducationName, ShouldValidateFields)");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Bug type
Development

No branches or pull requests

2 participants