Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(ios-text-base): button textAlignment on IOS (UIButton) #8181

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

Merged
merged 5 commits into from
Jan 21, 2020

Conversation

sylann
Copy link
Contributor

@sylann sylann commented Dec 8, 2019

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

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).
@cla-bot
Copy link

cla-bot bot commented Dec 8, 2019

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 has not been signed by users: @romain20100.
After signing the CLA, you can ask me to recheck this PR by posting @cla-bot check as a comment to the PR.

@romain20100-rwigo
Copy link
Contributor

@cla-bot check

@cla-bot cla-bot bot added the cla: yes label Dec 8, 2019
@cla-bot
Copy link

cla-bot bot commented Dec 8, 2019

The cla-bot has been summoned, and re-checked this pull request!

@vmutafov
Copy link
Contributor

test

@@ -192,7 +197,12 @@ export class TextBase extends TextBaseCommon {
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants