Skip to content

Commit

Permalink
[iOS] Simplify the code used to set the same font size for Editor/Ent…
Browse files Browse the repository at this point in the history
…ry. (#13150)

PR #13140 landed with a property
implementation that is more complicatd than needed (also a little
unsafe).

Changes in this PR:

1. Use a nullable nfloat to ensure that we do not use a magic number as
the default value of the variable.
2. Simplify the if nests. There is no needed to have that many nested
code to achiecve the same. This implementation does the same with a much
simpler approach.

Please follow the logic of the changes in the comment review I gave to
the original PR:
#13140 (review)
  • Loading branch information
rmarinho authored Feb 7, 2023
2 parents 50e2891 + 85dc8f6 commit 2cba96c
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/Core/src/Platform/iOS/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Maui.Platform
public class MauiTextView : UITextView
{
readonly UILabel _placeholderLabel;
nfloat _defaultPlaceholderSize = -1;
nfloat? _defaultPlaceholderSize;

public MauiTextView()
{
Expand Down Expand Up @@ -176,18 +176,9 @@ void ShouldCenterVertically()

void UpdatePlaceholderFontSize(UIFont? value)
{
if (value != null)
{
if (_defaultPlaceholderSize == -1)
{
_defaultPlaceholderSize = _placeholderLabel.Font.PointSize;
}
_placeholderLabel.Font = _placeholderLabel.Font.WithSize(value.PointSize);
}
else if (_defaultPlaceholderSize != -1)
{
_placeholderLabel.Font = _placeholderLabel.Font.WithSize(_defaultPlaceholderSize);
}
_defaultPlaceholderSize ??= _placeholderLabel.Font.PointSize;
_placeholderLabel.Font = _placeholderLabel.Font.WithSize (
value?.PointSize ?? _defaultPlaceholderSize.Value);
}
}
}
}

0 comments on commit 2cba96c

Please sign in to comment.