[SwiftUI | macOS] List modifiers are not applied

Originator:flavio
Number:rdar://FB9071516 Date Originated:2021-04-07
Status:Open Resolved:No
Product:SwiftUI Product Version:-
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
 
List-specific modifiers applied to a List view are not applied. Even the generic "background" modifier is ignored.


Please list the steps you took to reproduce the issue:
===
Render the following List:
```
List(0..<10, id: \.self) { idx in
    Text("\(idx)")
}
.listRowBackground(Color.white)
.listStyle(PlainListStyle())
.listItemTint(.blue)
.listRowInsets(EdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20))
.background(Color.purple)
```

What did you expect to happen?
===
1. The list should have a purple background.
2. Each row should be inset with 20px on all edges
3. Each row should have white background overlaid with a green with reduced opacity.
4. Each row text should be tinted blue

What actually happened?
===
All styling is ignored, including the overall background color applied to the component.

An example can be seen in the ListStyleView file in https://github.com/fjcaetano/not-awesome-swiftui

Comments

Example

Check https://github.com/fjcaetano/not-awesome-swiftui

Reporter

Thank you for the reply.

  • If the row modifiers are supposed to be used in the content of the list, then what's the difference between using the list-specific modifiers mentioned (. listRowBackground() and . listRowInsets()) vs. using generic View modifiers (.background() and .padding())?
  • What does .listItemTint() affects, if not the foreground color?
  • Lastly, I cannot access the radar mentioned about list background colors. Is there a fix or workaround for it?

I see that the documentation for the row modifiers have been updated and it clarifies that these should be used at the content level, not at the list. Thank you for that.

From Apple

Thank you for the report.

It appears you've misunderstand of how list modifiers should work. The various listRow modifiers are applied to the content in the list (i.e. the Text). listItemTint does not affect text color.

It is expected that Lists come with a background and that .background simply adds a layer underneath the view it is applied to. rdar://45928055 tracks enabling customization of list backgrounds.

These are consistent across all platforms.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!