Skip to content

Commit

Permalink
Fix alpha button override issues in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Oct 22, 2024
1 parent 081f9ab commit 507ae07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ios/MullvadVPN/Extensions/UIImage+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ extension UIImage {

return resizedImage.withRenderingMode(renderingMode)
}

func withAlpha(_ alpha: CGFloat) -> UIImage? {
return UIGraphicsImageRenderer(size: size, format: imageRendererFormat).image { _ in
draw(in: CGRect(origin: .zero, size: size), blendMode: .normal, alpha: alpha)
}
}
}
13 changes: 10 additions & 3 deletions ios/MullvadVPN/Views/AppButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,23 @@ class AppButton: CustomButton {
return updatedAttributeContainer
}

let configurationHandler: UIButton.ConfigurationUpdateHandler = { button in
button.alpha = !button.isEnabled ? 0.5 : 1.0
let configurationHandler: UIButton.ConfigurationUpdateHandler = { [weak self] button in
guard let self else { return }
button.configuration?.baseForegroundColor = button.state.customButtonTitleColor
updateButtonBackground()
}
configuration = config
configurationUpdateHandler = configurationHandler
}

/// Set background image based on current style.
private func updateButtonBackground() {
configuration?.background.image = style.backgroundImage
if isEnabled {
// Load the normal image and set it as the background
configuration?.background.image = style.backgroundImage
} else {
// Adjust the image for the disabled state
configuration?.background.image = style.backgroundImage.withAlpha(0.5)
}
}
}
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Views/CustomButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension UIControl.State {
case .normal:
return UIColor.AppButton.normalTitleColor
case .disabled:
return UIColor.AppButton.disabledTitleColor
return UIColor.AppButton.disabledTitleColor.withAlphaComponent(0.5)
case .highlighted:
return UIColor.AppButton.highlightedTitleColor
default:
Expand Down

0 comments on commit 507ae07

Please sign in to comment.