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

Add FXIOS-9055 - Allow toolbar button to be displayed highlighted #20191

Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions BrowserKit/Sources/ToolbarKit/ToolbarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ToolbarButton: UIButton, ThemeApplicable {
var foregroundColorHighlighted: UIColor = .clear
var foregroundColorDisabled: UIColor = .clear
var backgroundColorNormal: UIColor = .clear
private var shouldDisplayAsHighlighted = false

private var onLongPress: (() -> Void)?

Expand All @@ -34,6 +35,7 @@ class ToolbarButton: UIButton, ThemeApplicable {
}
removeAllGestureRecognizers()
configureLongPressGestureRecognizerIfNeeded(for: element)
shouldDisplayAsHighlighted = element.shouldDisplayAsHighlighted

let image = UIImage(named: element.iconName)?.withRenderingMode(.alwaysTemplate)
let action = UIAction(title: element.a11yLabel,
Expand Down Expand Up @@ -66,12 +68,12 @@ class ToolbarButton: UIButton, ThemeApplicable {
}

switch state {
case [.highlighted]:
case .highlighted:
updatedConfiguration.baseForegroundColor = foregroundColorHighlighted
case [.disabled]:
case .disabled:
updatedConfiguration.baseForegroundColor = foregroundColorDisabled
default:
updatedConfiguration.baseForegroundColor = foregroundColorNormal
updatedConfiguration.baseForegroundColor = shouldDisplayAsHighlighted ? foregroundColorHighlighted : foregroundColorNormal
}

updatedConfiguration.background.backgroundColor = backgroundColorNormal
Expand Down Expand Up @@ -109,7 +111,7 @@ class ToolbarButton: UIButton, ThemeApplicable {
// MARK: - ThemeApplicable
public func applyTheme(theme: Theme) {
foregroundColorNormal = theme.colors.iconPrimary
foregroundColorHighlighted = theme.colors.iconPrimary
foregroundColorHighlighted = theme.colors.actionPrimary
foregroundColorDisabled = theme.colors.iconDisabled
backgroundColorNormal = .clear
setNeedsUpdateConfiguration()
Expand Down
5 changes: 5 additions & 0 deletions BrowserKit/Sources/ToolbarKit/ToolbarElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public struct ToolbarElement {
/// Whether the toolbar element can be interacted with
let isEnabled: Bool

/// Indicates if the element should be displayed as highlighted
let shouldDisplayAsHighlighted: Bool

/// Accessibility label of the toolbar element
let a11yLabel: String

Expand All @@ -27,12 +30,14 @@ public struct ToolbarElement {
// can therefor not be used outside of the ToolbarKit
public init(iconName: String,
isEnabled: Bool,
shouldDisplayAsHighlighted: Bool = false,
a11yLabel: String,
a11yId: String,
onSelected: (() -> Void)?,
onLongPress: (() -> Void)? = nil) {
self.iconName = iconName
self.isEnabled = isEnabled
self.shouldDisplayAsHighlighted = shouldDisplayAsHighlighted
self.onSelected = onSelected
self.onLongPress = onLongPress
self.a11yLabel = a11yLabel
Expand Down