You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[TNS 3] Wrapped text in Button not properly centered (iOS) #4266
There seems to be a regression with the way wrapped text is centered in a NativeScript button on iOS.
Pre-TNS3, if you set style="text-align:center;" on a Button with textWrap="true", the text would be both A) centered in the Button, and B) any wrapped text would be centered on the new wrapped line.
With TNS3 (confirmed in 3.0.1 on iOS), those same style settings will center the text in the Button, BUT wrapped text on new lines will not be centered. Instead, wrapped text is left aligned.
The problem should be easy to reproduce using any button with style settings that cause the text to wrap. For example:
<Button text="This is a test of a Button text wrapping" textWrap="true" style="text-align:center;width:100;" />
Does not apply to Android or Label widgets. Text is properly centered when wrapped.
I'd submit a PR directly, but not sure if there are reasons that using this approach was avoided in the first place. In my local tests, this does fix the text centering problem. Not sure if it creates other problems I'm missing.
@toddanglin we've discussed this case and it would be great to use the wrapping as you have suggested. Let me now when you have a PR ready or let me know if you want for us to take care of it.
Okay. Let me test with Icon + Text scenario to make sure this new approach doesn't cause any problems. If it doesn't, I'll go ahead and submit a quick PR for the file mentioned above with the new alignment code for iOS.
EDIT
RE: The screenshots above. The second image ("Todd's Code") is also how text centering behaved in buttons on iOS pre-TNS3. Not sure what changed to trigger the current behavior, but this PR should "restore" the old layout behavior and make iOS consistent with Android again. Just adding context for future review to clarify that this PR would not introduce "new" behavior to iOS Button text alignment.
Okay. Confirmed that the new text alignment approach seems to work fine in iOS, including scenarios where the text includes unicode icons (see image below).
<Buttontext="This a test of a wrapping button [CENTER]"textWrap="true"style="text-align:center;width:100;margin-bottom:60;" />
<Buttontext="This a test of a wrapping button [RIGHT]"textWrap="true"style="text-align:right;width:100;margin-bottom:60;" />
<Buttontext="This a test of a wrapping button [LEFT]"textWrap="true"style="text-align:left;width:100;margin-bottom:60;" />
<Buttontext=" This a test of a wrapping button [CENTER ICON]"textWrap="true"style="text-align:center;width:100;margin-bottom:60;" />
Layout with new text alignment applied
Layout with current un-patched behavior
While testing, I did notice that the height of a button with wrapped text does not seem to be properly calculated in our layout system. When I change the margin from 60 to 20 in the above code snippet, it produces overlapping buttons like this:
This occurs both with and without my proposed PR, so it is probably a separate issue that needs to be investigated. Just flagging here for future follow-up.
Meanwhile, will prepare the official PR and submit shortly.
I'm on TNS 3.4.0 and am seeing the same problem with a label. Wrapped text is ignoring horizontalAlignment="center" and left aligns. Should i submit a new issue or is there a quick fix for it?
Activity
toddanglin commentedon May 25, 2017
Based on my limited mastery of the underlying native iOS properties, I think this issue can be fixed by making a small change in this file: https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/ui/button/button.ios.ts#L146
In this
textAlignmentPropertyimplementation, you should be able to change this:To this:
I'd submit a PR directly, but not sure if there are reasons that using this approach was avoided in the first place. In my local tests, this does fix the text centering problem. Not sure if it creates other problems I'm missing.
NickIliev commentedon May 26, 2017
@toddanglin to demonstrate what is the difference between the original implementation and your suggestion I am attaching two screenshots.
Original implementation

Todd's code

NickIliev commentedon May 26, 2017
@toddanglin we've discussed this case and it would be great to use the wrapping as you have suggested. Let me now when you have a PR ready or let me know if you want for us to take care of it.
toddanglin commentedon May 26, 2017
Okay. Let me test with Icon + Text scenario to make sure this new approach doesn't cause any problems. If it doesn't, I'll go ahead and submit a quick PR for the file mentioned above with the new alignment code for iOS.
EDIT
RE: The screenshots above. The second image ("Todd's Code") is also how text centering behaved in buttons on iOS pre-TNS3. Not sure what changed to trigger the current behavior, but this PR should "restore" the old layout behavior and make iOS consistent with Android again. Just adding context for future review to clarify that this PR would not introduce "new" behavior to iOS Button text alignment.
toddanglin commentedon May 26, 2017
Okay. Confirmed that the new text alignment approach seems to work fine in iOS, including scenarios where the text includes unicode icons (see image below).
Layout with new text alignment applied

Layout with current un-patched behavior

While testing, I did notice that the height of a button with wrapped text does not seem to be properly calculated in our layout system. When I change the
marginfrom60to20in the above code snippet, it produces overlapping buttons like this:This occurs both with and without my proposed PR, so it is probably a separate issue that needs to be investigated. Just flagging here for future follow-up.
Meanwhile, will prepare the official PR and submit shortly.
toddanglin commentedon May 26, 2017
PR created: #4273
Do you want me to create a new issue for the "overlapping button" problem?
NickIliev commentedon May 29, 2017
@toddanglin I have opened this issue for the overlapping problem in iOS.
toddanglin commentedon May 31, 2017
Thanks @NickIliev.
I think we can close this issue now since the PR with the fix has been merged (#4273).
SvetoslavTsenov commentedon May 31, 2017
Hey @toddanglin, the fix is already available in tns-core-modules@next and will also be released with tns-core-modules@3.1.0
BearOutThere commentedon Mar 15, 2018
I'm on TNS 3.4.0 and am seeing the same problem with a label. Wrapped text is ignoring horizontalAlignment="center" and left aligns. Should i submit a new issue or is there a quick fix for it?
lock commentedon Aug 27, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.