Skip to content

Commit

Permalink
Merge pull request #75 from guardian/aml-fix-disabled-state-icon-button
Browse files Browse the repository at this point in the history
iOS - Update disabled opacity of icon button
  • Loading branch information
aoifemcl15 authored Jul 25, 2024
2 parents 41236dc + 36b37ae commit 444900d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sources/Source/Components/Buttons/IconButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct IconButton: View {
size: ButtonSize,
iconColor: Color,
borderColor: Color,
disabled: Binding<Bool>,
disabled: Binding<Bool> = .constant(false),
action: @escaping () -> Void
) {
self.icon = icon
Expand Down Expand Up @@ -49,18 +49,25 @@ struct IconButtonStyle: ButtonStyle {
let borderColor: Color
let iconColor: Color

init(size: ButtonSize, isDisabled: Binding<Bool>, borderColor: Color, iconColor: Color) {
@Environment(\.colorScheme) private
var colorScheme

init(size: ButtonSize, isDisabled: Binding<Bool> = .constant(false), borderColor: Color, iconColor: Color) {
self.size = size
self._isDisabled = isDisabled
self.borderColor = borderColor
self.iconColor = iconColor
}

private var disabledOpacity: CGFloat {
return colorScheme == .dark ? 0.4 : 0.2
}

func makeBody(configuration: Configuration) -> some View {
configuration.label
.frame(width: size.iconSize, height: size.iconSize)
.foregroundStyle(iconColor)
.opacity(isDisabled ? 0.2 : 1.0)
.opacity(isDisabled ? disabledOpacity : 1.0)
.padding(size.iconPadding)
.background {
if configuration.isPressed, isDisabled == false {
Expand Down

0 comments on commit 444900d

Please sign in to comment.