Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not rerender tab on navigate #26

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "TabBar",
platforms: [
.iOS(.v13)
.iOS("14")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use .v14 value here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Am I missing a point?

],
products: [
.library(
Expand Down
7 changes: 2 additions & 5 deletions Sources/TabBar/Common/Preferences/TabBarViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ struct TabBarViewModifier<TabItem: Tabbable>: ViewModifier {

func body(content: Content) -> some View {
Group {
if self.item == self.selectionObject.selection {
content
} else {
Color.clear
}
content
.opacity(self.item == self.selectionObject.selection ? 1 : 0)
}
.preference(key: TabBarPreferenceKey.self, value: [self.item])
}
Expand Down
48 changes: 25 additions & 23 deletions Sources/TabBar/View/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,32 @@ public struct TabBar<TabItem: Tabbable, Content: View>: View {
.frame(maxWidth: .infinity)
}
}


public var body: some View {
ZStack {
self.content
.frame(maxWidth: .infinity, maxHeight: .infinity)
.environmentObject(self.selectedItem)

GeometryReader { geometry in
VStack {
Spacer()

self.tabBarStyle.tabBar(with: geometry) {
.init(self.tabItems)
}
}
.edgesIgnoringSafeArea(.bottom)
.visibility(self.visibility)
}
}
.onPreferenceChange(TabBarPreferenceKey.self) { value in
self.items = value
}
}

public var body: some View {
GeometryReader { geometry in
ZStack {
self.content
.environmentObject(self.selectedItem)
.padding(.bottom, 50)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why we need this padding here, and what does value of 50 points mean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Child view of TabBar collides with TabBar without this. 50 is the DefaultTabBarStyle tabbar height. Bottom 50px of view is not visible without this padding.

.frame(maxWidth: .infinity, maxHeight: .infinity)

VStack {
Spacer()

self.tabBarStyle.tabBar(with: geometry) {
.init(self.tabItems)
}
}
.edgesIgnoringSafeArea(.bottom)
.visibility(self.visibility)
}
.onPreferenceChange(TabBarPreferenceKey.self) { value in
self.items = value
}
}
.ignoresSafeArea(.keyboard)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we need this here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use a keyboard inside a child view of tabbar. The tabbar moves up with keyboard without this modifier. This is the reason I increased iOS version from 13 to 14.

}
}

extension TabBar {
Expand Down