Skip to content

Commit 683973e

Browse files
Merge pull request #34 from SimformSolutionsPvtLtd/feature/UNT-T9637/set_default_selected_index_for_swiftui
UNT-T9637: Added default selected index for SwiftUI
2 parents c0ec28b + a00f51b commit 683973e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SSCustomTabBar/Classes/SwiftUITabbar.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class SSTabConfiguration {
4242
/// Reverse Curve
4343
public var reverseCurve: Bool
4444

45+
/// Selected index
46+
public var selectedIndex: Int
47+
4548
/// Initializer for Tabbar configuration
4649
/// - Parameters:
4750
/// - barHeight: Bar height
@@ -53,7 +56,21 @@ public class SSTabConfiguration {
5356
/// - shadowColor: Shadow Color
5457
/// - shadowRadius: Shadow Radius
5558
/// - shadowOffset: Shadow Offset
56-
public init(barHeight: CGFloat? = nil, upAnimationPoint: CGFloat? = nil, layerFillColor: UIColor = .white, waveHeight: CGFloat = 17, selectedTabTintColor: UIColor = UIColor.orange, unselectedTabTintColor: UIColor = .black, shadowColor: UIColor = .black, shadowRadius: CGFloat = .zero, shadowOffset: CGSize = CGSize(width: 0, height: -1), reverseCurve: Bool = false) {
59+
/// - reverseCurve: Set reverse curve
60+
/// - selectedIndex: Index of selected tabbar item
61+
public init(
62+
barHeight: CGFloat? = nil,
63+
upAnimationPoint: CGFloat? = nil,
64+
layerFillColor: UIColor = .white,
65+
waveHeight: CGFloat = 17,
66+
selectedTabTintColor: UIColor = UIColor.orange,
67+
unselectedTabTintColor: UIColor = .black,
68+
shadowColor: UIColor = .black,
69+
shadowRadius: CGFloat = .zero,
70+
shadowOffset: CGSize = CGSize(width: 0, height: -1),
71+
reverseCurve: Bool = false,
72+
selectedIndex: Int = 0
73+
) {
5774
self.barHeight = barHeight
5875
self.upAnimationPoint = upAnimationPoint
5976
self.layerFillColor = layerFillColor
@@ -64,6 +81,7 @@ public class SSTabConfiguration {
6481
self.shadowRadius = shadowRadius
6582
self.shadowOffset = shadowOffset
6683
self.reverseCurve = reverseCurve
84+
self.selectedIndex = selectedIndex
6785
}
6886

6987
}
@@ -169,6 +187,10 @@ public struct SwiftUITabBarController: UIViewControllerRepresentable {
169187
tabBar.tintColor = configuration.selectedTabTintColor
170188
tabBar.isHidden = isTabBarHidden
171189
tabBar.reverseCurve = configuration.reverseCurve
190+
if let viewControllers = tabBarVC.viewControllers,
191+
configuration.selectedIndex <= viewControllers.count {
192+
tabBarVC.selectedIndex = configuration.selectedIndex
193+
}
172194
}
173195

174196
public static func refreshViews() {

0 commit comments

Comments
 (0)