Skip to content

Commit

Permalink
Removed animation from the custom TabBar, which caused unpredictable …
Browse files Browse the repository at this point in the history
…behavior of the screens
  • Loading branch information
Konstantin Kochetkov committed Nov 9, 2023
1 parent 84c4164 commit 0c5407d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 57 deletions.
4 changes: 4 additions & 0 deletions Expense Tracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
02A8ED1A2A6EB6DF001E5661 /* LottieView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02A8ED192A6EB6DF001E5661 /* LottieView.swift */; };
02A8ED2F2A6FFA76001E5661 /* moon.json in Resources */ = {isa = PBXBuildFile; fileRef = 02A8ED2E2A6FFA76001E5661 /* moon.json */; };
02A8ED312A6FFB60001E5661 /* sun.json in Resources */ = {isa = PBXBuildFile; fileRef = 02A8ED302A6FFB5F001E5661 /* sun.json */; };
C9C27F632AFCB6DA0082800F /* UI Components.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C27F622AFCB6DA0082800F /* UI Components.swift */; };
C9C3B4372ACD4171006041CE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C9C3B4392ACD4171006041CE /* Localizable.strings */; };
C9DD68452ABB0BEB00C6F8D6 /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DD68442ABB0BEB00C6F8D6 /* Onboarding.swift */; };
C9DD68472ABB0C1B00C6F8D6 /* OnboardingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DD68462ABB0C1B00C6F8D6 /* OnboardingViewModel.swift */; };
Expand Down Expand Up @@ -82,6 +83,7 @@
02A8ED192A6EB6DF001E5661 /* LottieView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LottieView.swift; sourceTree = "<group>"; };
02A8ED2E2A6FFA76001E5661 /* moon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = moon.json; sourceTree = "<group>"; };
02A8ED302A6FFB5F001E5661 /* sun.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = sun.json; sourceTree = "<group>"; };
C9C27F622AFCB6DA0082800F /* UI Components.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UI Components.swift"; sourceTree = "<group>"; };
C9C3B4382ACD4171006041CE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
C9C3B43A2ACD4193006041CE /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
C9DD68442ABB0BEB00C6F8D6 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -194,6 +196,7 @@
isa = PBXGroup;
children = (
02A8ECFD2A6D7ACD001E5661 /* Extension.swift */,
C9C27F622AFCB6DA0082800F /* UI Components.swift */,
);
path = Extension;
sourceTree = "<group>";
Expand Down Expand Up @@ -326,6 +329,7 @@
files = (
02A8ED002A6D7B6D001E5661 /* AddProfitView.swift in Sources */,
02A8ECF52A6D79C6001E5661 /* ChartsData.swift in Sources */,
C9C27F632AFCB6DA0082800F /* UI Components.swift in Sources */,
02A8ECE92A6D7891001E5661 /* ProfitView.swift in Sources */,
02A8ECE52A6D7828001E5661 /* TabBar.swift in Sources */,
C9DD68472ABB0C1B00C6F8D6 /* OnboardingViewModel.swift in Sources */,
Expand Down
57 changes: 3 additions & 54 deletions Expense Tracker/Extension/Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ extension DateFormatter {
}()
}

public struct ClearButton: ViewModifier {
@Binding var text: String

public func body(content: Content) -> some View {
HStack {
content
Button(action: {
self.text = ""
}) {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.secondary)
}
}
extension String {
var decimalFormatted: String {
return self.replacingOccurrences(of: ",", with: ".")
}
}

Expand Down Expand Up @@ -53,12 +43,6 @@ extension TextField {
}
}

extension String {
var decimalFormatted: String {
return self.replacingOccurrences(of: ",", with: ".")
}
}

extension Double {
var stringFormat: String {
if self >= 10000 && self < 999999 {
Expand Down Expand Up @@ -101,38 +85,3 @@ extension ObservableObject {
return false
}
}

struct CustomSegmentedControl: View {
@Binding var selectedInterval: Interval
let intervals: [Interval]
let color: LinearGradient

var body: some View {
HStack(spacing: 0) {
ForEach(intervals.indices, id:\.self) { index in
let isSelected = selectedInterval == intervals[index]
ZStack {
Rectangle()
.fill(color.opacity(0.2))

Rectangle()
.fill(color.opacity(0.8))
.cornerRadius(20)
.padding(2)
.opacity(isSelected ? 1 : 0.01)
.onTapGesture {
selectedInterval = intervals[index]
}
}
.overlay(
Text(Interval.intervalToString(intervals[index]))
.font(.system(size: 14))
.fontWeight(isSelected ? .bold : .regular)
.foregroundColor(isSelected ? .white : .gray)
)
}
}
.frame(height: 50)
.cornerRadius(20)
}
}
57 changes: 57 additions & 0 deletions Expense Tracker/Extension/UI Components.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// UI Components.swift
// Expense Tracker
//

import SwiftUI

struct ClearButton: ViewModifier {
@Binding var text: String

public func body(content: Content) -> some View {
HStack {
content
Button(action: {
self.text = ""
}) {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.secondary)
}
}
}
}

struct CustomSegmentedControl: View {
@Binding var selectedInterval: Interval
let intervals: [Interval]
let color: LinearGradient

var body: some View {
HStack(spacing: 0) {
ForEach(intervals.indices, id:\.self) { index in
let isSelected = selectedInterval == intervals[index]
ZStack {
Rectangle()
.fill(color.opacity(0.2))

Rectangle()
.fill(color.opacity(0.8))
.cornerRadius(20)
.padding(2)
.opacity(isSelected ? 1 : 0.01)
.onTapGesture {
selectedInterval = intervals[index]
}
}
.overlay(
Text(Interval.intervalToString(intervals[index]))
.font(.system(size: 14))
.fontWeight(isSelected ? .bold : .regular)
.foregroundColor(isSelected ? .white : .gray)
)
}
}
.frame(height: 50)
.cornerRadius(20)
}
}
2 changes: 1 addition & 1 deletion Expense Tracker/View/Chart/ChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ struct ChartView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
}
.padding(.horizontal)
.navigationBarTitle(Text("График бюджета"), displayMode: .large)
}
Spacer()
.navigationBarTitle(Text("График бюджета"), displayMode: .large)
}
.onAppear {
viewModel.updateChartData()
Expand Down
2 changes: 0 additions & 2 deletions Expense Tracker/View/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ struct MainTabScreen: View {
.font(.subheadline.bold())
.foregroundStyle(selectedTab == tab ? (isDarkMode ? .blue.opacity(0.8) : .blue) : (isDarkMode ? .white.opacity(0.6) : .gray.opacity(0.8)))
.onTapGesture {
withAnimation(.spring(response: 0.3, dampingFraction: 0.8)) {
selectedTab = tab
}
}
.scaleEffect(selectedTab == tab ? 1.0 : 0.85)
.frame(maxWidth: .infinity)
Expand Down

0 comments on commit 0c5407d

Please sign in to comment.