Skip to content

Commit

Permalink
Merge pull request #34 from SimformSolutionsPvtLtd/feature/UNT-T9637/…
Browse files Browse the repository at this point in the history
…set_default_selected_index_for_swiftui

UNT-T9637: Added default selected index for SwiftUI
  • Loading branch information
mobile-simformsolutions authored Nov 29, 2022
2 parents c0ec28b + a00f51b commit 683973e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion SSCustomTabBar/Classes/SwiftUITabbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class SSTabConfiguration {
/// Reverse Curve
public var reverseCurve: Bool

/// Selected index
public var selectedIndex: Int

/// Initializer for Tabbar configuration
/// - Parameters:
/// - barHeight: Bar height
Expand All @@ -53,7 +56,21 @@ public class SSTabConfiguration {
/// - shadowColor: Shadow Color
/// - shadowRadius: Shadow Radius
/// - shadowOffset: Shadow Offset
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) {
/// - reverseCurve: Set reverse curve
/// - selectedIndex: Index of selected tabbar item
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,
selectedIndex: Int = 0
) {
self.barHeight = barHeight
self.upAnimationPoint = upAnimationPoint
self.layerFillColor = layerFillColor
Expand All @@ -64,6 +81,7 @@ public class SSTabConfiguration {
self.shadowRadius = shadowRadius
self.shadowOffset = shadowOffset
self.reverseCurve = reverseCurve
self.selectedIndex = selectedIndex
}

}
Expand Down Expand Up @@ -169,6 +187,10 @@ public struct SwiftUITabBarController: UIViewControllerRepresentable {
tabBar.tintColor = configuration.selectedTabTintColor
tabBar.isHidden = isTabBarHidden
tabBar.reverseCurve = configuration.reverseCurve
if let viewControllers = tabBarVC.viewControllers,
configuration.selectedIndex <= viewControllers.count {
tabBarVC.selectedIndex = configuration.selectedIndex
}
}

public static func refreshViews() {
Expand Down

0 comments on commit 683973e

Please sign in to comment.