Revision control

Copy as Markdown

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import UIKit
public struct ToolbarElement: Equatable {
/// Icon name of the toolbar element
let iconName: String
/// Badge name of the toolbar element
let badgeImageName: String?
/// Mask name of the badge's toolbar element
let maskImageName: String?
/// Number of open tabs
let numberOfTabs: Int?
/// Whether the toolbar element can be interacted with
let isEnabled: Bool
/// Indicates whether the toolbar element's image should be flipped for right-to-left layout direction
let isFlippedForRTL: Bool
/// Indicates if the element should be displayed as highlighted
let shouldDisplayAsHighlighted: Bool
/// Indicates that there is an associated contextual hint
let contextualHintType: String?
/// Accessibility label of the toolbar element
let a11yLabel: String
/// Accessibility hint of the toolbar element
let a11yHint: String?
/// Accessibility identifier of the toolbar element
let a11yId: String
/// Name for the custom accessibility action
let a11yCustomActionName: String?
/// Action to be performed for custom accessibility action
let a11yCustomAction: (() -> Void)?
/// Indicates whether the toolbar element has a long press action or not
/// this is only used to compare for equality as closures can't be compared
let hasLongPressAction: Bool
/// Closure that is executed when the toolbar element is tapped
let onSelected: ((UIButton) -> Void)?
/// Closure that is executed when the toolbar element is long pressed
let onLongPress: ((UIButton) -> Void)?
// We need this init as by default the init generated by the compiler for the struct will be internal and
// can therefor not be used outside of the ToolbarKit
public init(iconName: String,
badgeImageName: String? = nil,
maskImageName: String? = nil,
numberOfTabs: Int? = nil,
isEnabled: Bool,
isFlippedForRTL: Bool = false,
shouldDisplayAsHighlighted: Bool = false,
contextualHintType: String? = nil,
a11yLabel: String,
a11yHint: String?,
a11yId: String,
a11yCustomActionName: String? = nil,
a11yCustomAction: (() -> Void)? = nil,
hasLongPressAction: Bool,
onSelected: ((UIButton) -> Void)?,
onLongPress: ((UIButton) -> Void)? = nil) {
self.iconName = iconName
self.badgeImageName = badgeImageName
self.maskImageName = maskImageName
self.numberOfTabs = numberOfTabs
self.isEnabled = isEnabled
self.isFlippedForRTL = isFlippedForRTL
self.shouldDisplayAsHighlighted = shouldDisplayAsHighlighted
self.contextualHintType = contextualHintType
self.onSelected = onSelected
self.onLongPress = onLongPress
self.a11yLabel = a11yLabel
self.a11yHint = a11yHint
self.a11yId = a11yId
self.a11yCustomActionName = a11yCustomActionName
self.a11yCustomAction = a11yCustomAction
self.hasLongPressAction = hasLongPressAction
}
public static func == (lhs: ToolbarElement, rhs: ToolbarElement) -> Bool {
lhs.iconName == rhs.iconName &&
lhs.badgeImageName == rhs.badgeImageName &&
lhs.maskImageName == rhs.maskImageName &&
lhs.numberOfTabs == rhs.numberOfTabs &&
lhs.isEnabled == rhs.isEnabled &&
lhs.isFlippedForRTL == rhs.isFlippedForRTL &&
lhs.shouldDisplayAsHighlighted == rhs.shouldDisplayAsHighlighted &&
lhs.contextualHintType == rhs.contextualHintType &&
lhs.hasLongPressAction == rhs.hasLongPressAction &&
lhs.a11yLabel == rhs.a11yLabel &&
lhs.a11yHint == rhs.a11yHint &&
lhs.a11yId == rhs.a11yId &&
lhs.a11yCustomActionName == rhs.a11yCustomActionName
}
}