Skip to content

Commit

Permalink
Merge pull request #6 from MichaelNeas/feature/selected-image
Browse files Browse the repository at this point in the history
Unselected and Selected Tab initializers
  • Loading branch information
NicholasBellucci authored Nov 24, 2020
2 parents c8aebfe + 577daed commit c7ce860
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ContentView: View {

var body: some View {
StatefulTabView {
Tab(title: "Tab 1", systemImageName: "circle.fill", badgeValue: $badgeValue1) {
Tab(title: "Tab 1", systemImageName: "circle.fill", badgeValue: badgeValue1) {
NavigationView {
List {
Section {
Expand Down Expand Up @@ -60,7 +60,7 @@ struct ContentView: View {
}
.prefersLargeTitle(true)

Tab(title: "Tab 4", systemImageName: "shield.fill") {
Tab(title: "Tab 4", systemImageName: "shield", selectedSystemImageName: "shield.fill") {
List {
Section {
ForEach(0..<20, id: \.self) { index in
Expand Down
26 changes: 23 additions & 3 deletions Sources/StatefulTabView/Helpers/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,55 @@ public struct Tab {

let badgeValue: String?

// MARK: Asset Image Names
public init<T>(title: String,
imageName: String,
selectedImageName: String? = nil,
badgeValue: String? = nil,
@ViewBuilder content: @escaping () -> T) where T: View {

self.badgeValue = badgeValue
barItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage: nil)

var selectedImage: UIImage?
if let selectedImageName = selectedImageName {
selectedImage = UIImage(named: selectedImageName)
}

barItem = UITabBarItem(title: title, image: UIImage(named: imageName), selectedImage: selectedImage)

self.view = AnyView(content())
}

// MARK: System Image Names
public init<T>(title: String,
systemImageName: String,
selectedSystemImageName: String? = nil,
badgeValue: String? = nil,
@ViewBuilder content: @escaping () -> T) where T: View {

self.badgeValue = badgeValue
barItem = UITabBarItem(title: title, image: UIImage(systemName: systemImageName), selectedImage: nil)

var selectedImage: UIImage?
if let selectedSystemImageName = selectedSystemImageName {
selectedImage = UIImage(systemName: selectedSystemImageName)
}


barItem = UITabBarItem(title: title, image: UIImage(systemName: systemImageName), selectedImage: selectedImage)

self.view = AnyView(content())
}

// MARK: UIImages
public init<T>(title: String,
image: UIImage?,
selectedImage: UIImage? = nil,
badgeValue: String? = nil,
@ViewBuilder content: @escaping () -> T) where T: View {

self.badgeValue = badgeValue
barItem = UITabBarItem(title: title, image: image, selectedImage: nil)

barItem = UITabBarItem(title: title, image: image, selectedImage: selectedImage)

self.view = AnyView(content())
}
Expand Down

0 comments on commit c7ce860

Please sign in to comment.