inloop / Styles

Styling iOS apps made easy
MIT License
18 stars 2 forks source link

Setting UILabel's paragraph style linespacing resets alignment to left #83

Open VilemKurz opened 5 years ago

VilemKurz commented 5 years ago

Set a textstyle like this to a UILabel

TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

The label has alignment set to center in storyboard. BUG: The label has aligment left after applying the text style. In other words, setting line spacing has a side effect, it resets alignment to left. EXPECTED BEHAVIOUR: After setting linespacing, the label should keep its alignment setting without any change.

And vice versa. If you set alignment only, line spacing is reset. So, it is not possible to do this: TextStyle(.paragraphStyle([.alignment(.center)])) + TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

jakubpetrik commented 5 years ago

You have to provide also alignment. This is intended behaviour.

TextStyle(
    .paragraphStyle([
         .lineSpacing(2.0), 
         .alignment(.natural)
     ])
)
VilemKurz commented 5 years ago

I understand, this is how UIKit works. You set UILabel's alignment center, then attributed string with paragraph without alignment specified and boom, you have alignment left. But, shouldn't Styles shield us from these low level hassles?

jakubpetrik commented 5 years ago

No. This is about single source of truth. You set the style and expect it no side effects. In other words it should clear out everything and apply only the properties which are defined in the style. That way you can reason about it more easily. If this is not the case than its a bug that needs to be fixed.

Sent from my iPhone

On 9 Nov 2018, at 14:40, Vilém Kurz notifications@github.com wrote:

I understand, this is how UIKit works. You set UILabel's alignment center, then attributed string with paragraph without alignment specified and boom, you have alignment left. But, shouldn't Styles shield us from these low level hassles?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

VilemKurz commented 5 years ago

Ok, forget about mixing storyboard settings with Styles (although I think we agreed that Styles should preserve storyboard settings - in other words Styles should not change other values than set through Styles). You even can not do this, in a pure Styles fashion TextStyle(.paragraphStyle([.alignment(.center)])) + TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

btw read twice what did you write: "You set the style and expect it no side effects. In other words it should clear out everything and apply only the properties which are defined in the style"

"expect it no side effects" is mutually exclusive with "it should clear out everything"

jakubpetrik commented 5 years ago

:D you are correct. I misworded that one. What I meant was in that second sentence: In other words it should clear out everything and apply only the properties which are defined in the style.

Anyway. I personally don't like that idea of preserving settings from storyboard since it can cause lot of confusion, but I will look into it.

You even can not do this, in a pure Styles fashion TextStyle(.paragraphStyle([.alignment(.center)])) + TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

this is a bug that needs to be fixed. 👍