Skip to content

Commit

Permalink
fix: Bottom padding depends of safe area
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Jun 6, 2023
1 parent 51b9304 commit 133d3b8
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions Mail/Components/BottomBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,26 @@
import MailResources
import SwiftUI

struct BottomSafeAreaKey: PreferenceKey {
static var defaultValue: CGFloat = .zero

static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}

struct BottomBar<Items: View>: ViewModifier {
let isVisible: Bool

@ViewBuilder var items: () -> Items

func body(content: Content) -> some View {
content
.safeAreaInset(edge: .bottom) {
if isVisible {
BottomBarView(items: items)
}
VStack {
content
Spacer(minLength: 0)
if isVisible {
BottomBarView(items: items)
}
}
}
}

Expand All @@ -41,29 +49,40 @@ extension View {
}

struct BottomBarView<Items: View>: View {
@State private var hasBottomSafeArea = true

@ViewBuilder var items: () -> Items

var body: some View {
VStack {
HStack {
Spacer(minLength: 8)
items()
Spacer(minLength: 8)
}
.padding(.top, 8)
.padding(.bottom, hasBottomSafeArea ? 4 : 8)
.background(MailResourcesAsset.backgroundTabBarColor.swiftUIColor)
.overlay(alignment: .top) {
Divider()
.frame(height: 1)
.overlay(Color(uiColor: .systemGray3))

HStack {
Spacer(minLength: 8)
items()
Spacer(minLength: 8)
}
.overlay {
GeometryReader { proxy in
Color.clear
.preference(key: BottomSafeAreaKey.self, value: proxy.safeAreaInsets.bottom)
}
.padding(.vertical, 4)
}
.background(MailResourcesAsset.backgroundTabBarColor.swiftUIColor)
.onPreferenceChange(BottomSafeAreaKey.self) { value in
hasBottomSafeArea = value > 0
}
}
}

struct BottomBarView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
VStack {
List {
Text("View #1")
}
.navigationTitle("Title")
Expand Down

0 comments on commit 133d3b8

Please sign in to comment.