Skip to content

Commit

Permalink
allow custom name and bundle for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-skyscanner committed Dec 19, 2024
1 parent 72ac694 commit f77eded
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Backpack-SwiftUI/Icons/Classes/BPKIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Backpack_Common

public struct BPKIcon {
public let name: String
let bundle: Bundle

init (name: String, bundle: Bundle = BPKCommonBundle.iconsBundle) {
self.name = name
self.bundle = bundle
}

public enum Size {
case large, small
Expand Down
5 changes: 2 additions & 3 deletions Backpack-SwiftUI/Icons/Classes/BPKIconView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ private extension BPKIcon.Size {
private extension Image {
init(icon: BPKIcon, size: BPKIcon.Size = .small, shouldEnableAccessibility: Bool) {
let iconName = "\(icon.name)-\(size.suffix)"
let bundle = BPKCommonBundle.iconsBundle
if shouldEnableAccessibility {
self.init(iconName, bundle: bundle)
self.init(iconName, bundle: icon.bundle)
} else {
self.init(decorative: iconName, bundle: bundle)
self.init(decorative: iconName, bundle: icon.bundle)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Backpack-SwiftUI/Icons/Classes/Generated/BPKIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ public extension BPKIcon {

public extension BPKIcon {
// swiftlint:disable function_body_length cyclomatic_complexity
static func named(_ iconName: String) -> BPKIcon? {
static func named(_ iconName: String, bundle: Bundle? = nil) -> BPKIcon? {

if let bundle {
return BPKIcon(name: iconName, bundle: bundle)
}

switch iconName {
case "accessibility": return .accessibility
case "account--add": return .accountAdd
Expand Down

0 comments on commit f77eded

Please sign in to comment.