Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve alpha button override issues in configuration #7035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading