fix(ios-text-base): button textAlignment on IOS (UIButton)#8181
Conversation
When setting the format of a "text view", we need to recover existing values for properties that will get default values otherwise. The "textAlignment" of a UIButton is available through a "titleLabel" object instead of directly on itself (see IOS documentation fo UIButton).
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign the CLA at https://www.nativescript.org/cla. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
test |
| paragraphStyle.lineSpacing = style.lineHeight; | ||
| // make sure a possible previously set text alignment setting is not lost when line height is specified | ||
| paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment; | ||
| if (this.nativeTextViewProtected instanceof UIButton) { |
There was a problem hiding this comment.
Couldn't we extract the logic of this if statement to a separate function or introduce some polymorphic behavior for UIButton as these lines are duplicated thus increasing the maintenance cost?
There was a problem hiding this comment.
I'm not sure it's a good idea in that case. It's only repeated twice and there is a lot of context.
Or maybe there is a bigger picture, but I don't see it.
There was a problem hiding this comment.
Why do you think it's not a good idea and what do you mean by context?
The bigger picture is that, in my opinion, the codebase is starting to have a lot of code duplications and it's getting common to fix a bug at multiple places. To mitigate this problem I think we should be conservative about adding new code duplications and refactor existing ones whenever possible.
There was a problem hiding this comment.
If you are talking about rethinking this whole file to avoid even having this if statement, I agree. But moving just this if statement in a function to avoid repeating 2 lines of code, is a perfect example of over abstraction in my opinion.
However, I do want to say that I have little experience with nativescript, since I almost just discovered this project. So I don't pretend to have a genuine opinion in here. I'm just sharing my "general experience" on what looks like a lot of work for a not so important abstraction.
There was a problem hiding this comment.
Alright then, I'll approve your changes. We'd perhaps refactor this whole file so we'll abstract stuff at a later point. Thank you for the contribution :)
Introduction
When setting the format of a "text view", we need to recover existing values for properties that will get default values otherwise.
What is the current behavior?
The "textAlignment" of a UIButton is available through a "titleLabel" object instead of directly on itself (see IOS documentation fo UIButton).
Currently, when setting a new format on a UIButton, the recovered value for textAlignment would always be
undefined, and therefore the default value for textAlignment would always be applied when instantiating a new paragraphStyling.What is the new behavior?
After this commit, the previously set textAlignment (if any) is properly recovered and reused.
fixes pr #8151