Skip to content

Commit

Permalink
Add bottom divider to SettingsViewIconCell (needed for accessibility …
Browse files Browse the repository at this point in the history
…statement task) (#1342)

* Add divider to SettingsViewIconCell

* rename HairlineDividerModifier
  • Loading branch information
teddyfahi authored May 6, 2024
1 parent d6e2f47 commit 273af5e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct SettingsViewIconCell: View {
let title: String
let icon: UIImage
let tintColor: Color?
let isLastItem: Bool

var body: some View {
HStack(alignment: .center) {
Expand All @@ -20,12 +21,38 @@ struct SettingsViewIconCell: View {
.frame(width: .spacingM, height: .spacingM)
.foregroundColor(tintColor)
.padding([.trailing], .spacingXL)
}
}.bottomDivider(!isLastItem)
}
}

extension View {
func bottomDivider(
_ isLastItem: Bool,
inset: EdgeInsets = EdgeInsets(top: 0, leading: .spacingM, bottom: 0, trailing: 0)
) -> some View {
modifier(BottomDivider(isLastItem: isLastItem, inset: inset))
}
}

struct SettingsViewIconCell_Previews: PreviewProvider {
static var previews: some View {
SettingsViewIconCell(title: "Personvernerklæring", icon: .init(systemName: "square.and.arrow.up")!, tintColor: .bgSuccess) // swiftlint:disable:this force_unwrapping
SettingsViewIconCell(title: "Personvernerklæring", icon: .init(systemName: "square.and.arrow.up")!, tintColor: .bgSuccess, isLastItem: false) // swiftlint:disable:this force_unwrapping
}
}

struct BottomDivider: ViewModifier {
let isLastItem: Bool
let inset: EdgeInsets

public func body(content: Content) -> some View {
ZStack {
content
if isLastItem {
VStack {
Spacer()
Divider().padding(inset)
}
}
}.listRowInsets(EdgeInsets())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extension SettingsView: UITableViewDataSource {
let (icon, tintColor) = iconModel.icon

cell.contentConfiguration = HostingContentConfiguration(content: {
SettingsViewIconCell(title: iconModel.title, icon: icon, tintColor: tintColor)
SettingsViewIconCell(title: iconModel.title, icon: icon, tintColor: tintColor, isLastItem: isLastItem)
})
return cell
default:
Expand Down

0 comments on commit 273af5e

Please sign in to comment.