Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] AutoFitLabel #1164

Closed

Conversation

felipebaltazar
Copy link
Contributor

Description of Change

Bugs Fixed

API Changes

Added:

public  class AutoFitLabel {
   AutoFitTextMode Label.AutoSizeMode{ get; set; } //Bindable Property
   double Label.MaxAutoFitSize { get; set;} //Bindable Property
   double Label.MinAutoFitSize {get; set;} //Bindable Property
}

Behavioral Changes

Ive implemented a label that adjusts font size according of the label`s size

(I will include some images about this feature)

PR Checklist

  • Has a linked Issue, and the Issue has been approved
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

if (Element is null)
return;

#pragma warning disable 618 // We will need to update this when .Font goes away
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add // TODO:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And do we actually need to use obsolete API? Can we use new props?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that we don't want to use Obsolete APIs

Copy link
Contributor

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felipebaltazar thanks for this PR. I know this is still a draft PR, so I just did comments regarding the current code, to win time.

Comment on lines +33 to +44
static BuildVersionCodes? sdkInt;
static bool? isLollipopOrNewer;
static bool? isNougatOrNewer;

static BuildVersionCodes SdkInt =>
sdkInt ??= Build.VERSION.SdkInt;

static bool IsNougatOrNewer =>
isNougatOrNewer ??= SdkInt >= BuildVersionCodes.N;

static bool IsLollipopOrNewer =>
isLollipopOrNewer ??= SdkInt >= BuildVersionCodes.Lollipop;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move those bits into another file


bool hasLayoutOccurred;
bool wasFormatted;
bool disposed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool disposed;
bool isDisposed;

var oldElement = element;
element = value;

if (oldElement != null && element != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we create the control for the first time, the oldElement will be null and the OnElementChanged will not be triggered, and it should be triggered because the element changed.


result.Minimum = new Size(Math.Min(Context.ToPixels(10), result.Request.Width), result.Request.Height);

var measureIsChanged = !lastSizeRequest.HasValue ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's store the lastSizeRequest.HasValue and lastSizeRequest.Value into a local variable and reuse it.

void IVisualElementRenderer.SetElement(VisualElement element)
{
if (element is not AutoFitLabel label)
throw new ArgumentException("Element must be of type Label");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new ArgumentException("Element must be of type Label");
throw new ArgumentException($"{nameof(element)} must be of type Label");

}
}

void SetLineBreakMode(Label label)
Copy link
Contributor

@pictos pictos Apr 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the Forms methods? For this and other methods below

Please create an extension file with those methods, just like Forms did
https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.Android/Extensions/TextViewExtensions.cs

}
}

static class BackgroundManager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this class to another file?

UpdateBackgroundColor(control, element);
}

Performance.Stop(reference);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove this and any other call to Performance member?

{
}

[Obsolete]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to implement these Obsolete members?

void UpdateAutoFitMode()
{
#if __MOBILE__
if (Element is AutoFitLabel autoFitLabel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you invert this if?

@brminnick brminnick linked an issue May 6, 2021 that may be closed by this pull request
2 tasks
@pictos
Copy link
Contributor

pictos commented May 9, 2021

@felipebaltazar are you able to move this PR foward?

@felipebaltazar
Copy link
Contributor Author

@felipebaltazar are you able to move this PR foward?

Oh, yeah! Sorry for the delayed response...

I'm a little busy this month...
So if anyone knows how to proceed, feel free to commit to this PR...
I will back to work on this feature soon as possible

@brminnick
Copy link
Contributor

Thanks! However, we are no longer adding new features to Xamarin Community Toolkit, focusing on the .NET MAUI Community Toolkit.

Please open a New Feature Discussion to implement this feature in the .NET MAUI Community Toolkit.

I've posted more information about the Future Of Xamarin Community Toolkit here: https://devblogs.microsoft.com/xamarin/the-future-of-xamarin-community-toolkit/?WT.mc_id=mobile-0000-bramin

@brminnick brminnick closed this Nov 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Autofit Label
5 participants