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 enum ToolbarLongPressBehavior: Equatable {
case none
/// A custom action
case action((UIButton) -> Void)
/// A native UIMenu action
case menu(@MainActor () -> UIMenu?)
public static func == (lhs: ToolbarLongPressBehavior, rhs: ToolbarLongPressBehavior) -> Bool {
// Closures aren't Equatable, so compare behavior cases rather than their implementations.
switch (lhs, rhs) {
case (.none, .none), (.action, .action), (.menu, .menu):
return true
default:
return false
}
}
}
public struct ToolbarElement: Equatable {
/// Icon name of the toolbar element
let iconName: String?
/// Title of the toolbar element
let title: String?
/// Badge name of the toolbar element
let badgeImageName: String?
/// Mask name of the badge's toolbar element
let maskImageName: String?
/// The image for the bottom badge of the toolbar element
let bottomBadgeImage: UIImage?
/// Indicated whether to use template mode or not for an image
let templateModeForImage: Bool
/// TODO: FXIOS-13949 Should investigate if there is a better way to do this
let loadingConfig: LoadingConfig?
/// 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 is in the selected state and should be displayed as highlighted.
let isSelected: Bool
/// Indicates if the element has a custom color
let hasCustomColor: Bool
/// Indicates if the element has a highlighted color when tapping on it
let hasHighlightedColor: Bool
/// Title to display in the large content viewer
let largeContentTitle: String?
/// 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
/// Stable cache key used to reuse the same button instance across visual state changes.
/// When set, the button cache uses this instead of `a11yId`.
let cacheId: String?
/// Name for the custom accessibility action
let a11yCustomActionName: String?
/// Action to be performed for custom accessibility action
let a11yCustomAction: (() -> Void)?
/// Defines how the toolbar element responds to a long press
let longPressBehavior: ToolbarLongPressBehavior
/// Screenshot of the tab preceding the currently selected tab, used to render the stacked tab button.
let previousTabScreenshot: UIImage?
/// Screenshot of the tab following the currently selected tab, used to render the stacked tab button.
let nextTabScreenshot: UIImage?
/// Closure that is executed when the toolbar element is tapped
let onSelected: ((UIButton) -> Void)?
/// Menu actions displayed when the toolbar element is pressed
let menuElements: [ToolbarMenuElement]
// 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? = nil,
title: String? = nil,
badgeImageName: String? = nil,
bottomBadgeImage: UIImage? = nil,
maskImageName: String? = nil,
templateModeForImage: Bool = true,
loadingConfig: LoadingConfig? = nil,
numberOfTabs: Int? = nil,
isEnabled: Bool,
isFlippedForRTL: Bool = false,
isSelected: Bool = false,
hasCustomColor: Bool = false,
hasHighlightedColor: Bool = true,
largeContentTitle: String? = nil,
contextualHintType: String? = nil,
a11yLabel: String,
a11yHint: String?,
a11yId: String,
cacheId: String? = nil,
a11yCustomActionName: String? = nil,
a11yCustomAction: (() -> Void)? = nil,
longPressBehavior: ToolbarLongPressBehavior = .none,
previousTabScreenshot: UIImage? = nil,
nextTabScreenshot: UIImage? = nil,
onSelected: ((UIButton) -> Void)?,
menuElements: [ToolbarMenuElement] = []) {
self.iconName = iconName
self.title = title
self.badgeImageName = badgeImageName
self.bottomBadgeImage = bottomBadgeImage
self.maskImageName = maskImageName
self.templateModeForImage = templateModeForImage
self.loadingConfig = loadingConfig
self.numberOfTabs = numberOfTabs
self.isEnabled = isEnabled
self.isFlippedForRTL = isFlippedForRTL
self.isSelected = isSelected
self.hasCustomColor = hasCustomColor
self.hasHighlightedColor = hasHighlightedColor
self.largeContentTitle = largeContentTitle
self.contextualHintType = contextualHintType
self.previousTabScreenshot = previousTabScreenshot
self.nextTabScreenshot = nextTabScreenshot
self.onSelected = onSelected
self.longPressBehavior = longPressBehavior
self.a11yLabel = a11yLabel
self.a11yHint = a11yHint
self.a11yId = a11yId
self.cacheId = cacheId
self.a11yCustomActionName = a11yCustomActionName
self.a11yCustomAction = a11yCustomAction
self.menuElements = menuElements
}
public static func == (lhs: ToolbarElement, rhs: ToolbarElement) -> Bool {
lhs.iconName == rhs.iconName &&
lhs.title == rhs.title &&
lhs.badgeImageName == rhs.badgeImageName &&
lhs.bottomBadgeImage == rhs.bottomBadgeImage &&
lhs.maskImageName == rhs.maskImageName &&
lhs.templateModeForImage == rhs.templateModeForImage &&
lhs.loadingConfig == rhs.loadingConfig &&
lhs.numberOfTabs == rhs.numberOfTabs &&
lhs.isEnabled == rhs.isEnabled &&
lhs.isFlippedForRTL == rhs.isFlippedForRTL &&
lhs.isSelected == rhs.isSelected &&
lhs.hasCustomColor == rhs.hasCustomColor &&
lhs.hasHighlightedColor == rhs.hasHighlightedColor &&
lhs.largeContentTitle == rhs.largeContentTitle &&
lhs.contextualHintType == rhs.contextualHintType &&
lhs.previousTabScreenshot == rhs.previousTabScreenshot &&
lhs.nextTabScreenshot == rhs.nextTabScreenshot &&
lhs.longPressBehavior == rhs.longPressBehavior &&
lhs.menuElements == rhs.menuElements &&
lhs.a11yLabel == rhs.a11yLabel &&
lhs.a11yHint == rhs.a11yHint &&
lhs.a11yId == rhs.a11yId &&
lhs.a11yCustomActionName == rhs.a11yCustomActionName
}
}