kiwicom / orbit-swiftui

Kiwi.com Orbit design system library
MIT License
132 stars 23 forks source link

`Text` modifiers applied directly do not react to updates #714

Closed Parabak closed 11 months ago

Parabak commented 1 year ago

Tested with iOS 17

For some reason Content is not fully updated on a change. ViewModel's isSelected is @Published var isSelected: Bool. On a tap I would expect that Text color will be changed however it's not.

ChoiceTile(
    "Title"
    badgeOverlay: hint
    isSelected: viewModel.isSelected,
    alignment: .center
) {
    viewModel.isSelected.toogle()
} content: {
    Text("Price")
        .textColor(viewModel.isSelected ? .blueNormal : .inkDark)
}

Update:

sjavora commented 1 year ago

@Parabak it would help to have a minimum reproducible case - I suspect the viewModel is not needed at all and this could reproduce with a @State as well.

Since it works with SwiftUI.Text, I'd expect it's tied to the fact that textColor here is a custom Orbit modifier...

PavelHolec commented 12 months ago

The issue is in a missing re-evaluation when the textColor is applied directly to the Text like here (and not using environment). It applies to other chainable modifiers as well.

Workaround: Wrapping the Text in a a Group (or a stack) works, because it uses a different way to modify the color (not the chainable and concatenable version).