Skip to content

Commit

Permalink
Merge pull request #1 from vuinguyen/pair-program-with-adam
Browse files Browse the repository at this point in the history
Bring UI changes to be in line with UIKit Version
  • Loading branch information
vuinguyen authored Mar 21, 2022
2 parents c359e37 + ecf306c commit 50beaf0
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 43 deletions.
38 changes: 35 additions & 3 deletions TipperSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
529D206F27A7537C00793317 /* TipperSwiftUIUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529D206E27A7537C00793317 /* TipperSwiftUIUITestsLaunchTests.swift */; };
529D207C27A75EC800793317 /* TipperViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529D207B27A75EC800793317 /* TipperViewModel.swift */; };
529D208027A9A39B00793317 /* SwiftUIExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529D207F27A9A39B00793317 /* SwiftUIExtensions.swift */; };
52A6DCB327E3C9DD000C3194 /* CalculatedAmountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52A6DCB227E3C9DD000C3194 /* CalculatedAmountView.swift */; };
52A6DCB527E3CA73000C3194 /* TipAmountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52A6DCB427E3CA73000C3194 /* TipAmountView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -48,6 +50,8 @@
529D206E27A7537C00793317 /* TipperSwiftUIUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipperSwiftUIUITestsLaunchTests.swift; sourceTree = "<group>"; };
529D207B27A75EC800793317 /* TipperViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TipperViewModel.swift; sourceTree = "<group>"; };
529D207F27A9A39B00793317 /* SwiftUIExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIExtensions.swift; sourceTree = "<group>"; };
52A6DCB227E3C9DD000C3194 /* CalculatedAmountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatedAmountView.swift; sourceTree = "<group>"; };
52A6DCB427E3CA73000C3194 /* TipAmountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipAmountView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -99,9 +103,9 @@
isa = PBXGroup;
children = (
529D205127A7537B00793317 /* TipperSwiftUIApp.swift */,
529D205327A7537B00793317 /* ContentView.swift */,
529D207B27A75EC800793317 /* TipperViewModel.swift */,
529D207F27A9A39B00793317 /* SwiftUIExtensions.swift */,
52A6DCAF27E3C904000C3194 /* Views */,
52A6DCB027E3C931000C3194 /* ViewModel */,
52A6DCB127E3C94A000C3194 /* Extensions */,
529D205527A7537C00793317 /* Assets.xcassets */,
529D205727A7537C00793317 /* Preview Content */,
);
Expand Down Expand Up @@ -133,6 +137,32 @@
path = TipperSwiftUIUITests;
sourceTree = "<group>";
};
52A6DCAF27E3C904000C3194 /* Views */ = {
isa = PBXGroup;
children = (
529D205327A7537B00793317 /* ContentView.swift */,
52A6DCB227E3C9DD000C3194 /* CalculatedAmountView.swift */,
52A6DCB427E3CA73000C3194 /* TipAmountView.swift */,
);
path = Views;
sourceTree = "<group>";
};
52A6DCB027E3C931000C3194 /* ViewModel */ = {
isa = PBXGroup;
children = (
529D207B27A75EC800793317 /* TipperViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
52A6DCB127E3C94A000C3194 /* Extensions */ = {
isa = PBXGroup;
children = (
529D207F27A9A39B00793317 /* SwiftUIExtensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -265,6 +295,8 @@
files = (
529D205427A7537B00793317 /* ContentView.swift in Sources */,
529D208027A9A39B00793317 /* SwiftUIExtensions.swift in Sources */,
52A6DCB527E3CA73000C3194 /* TipAmountView.swift in Sources */,
52A6DCB327E3C9DD000C3194 /* CalculatedAmountView.swift in Sources */,
529D205227A7537B00793317 /* TipperSwiftUIApp.swift in Sources */,
529D207C27A75EC800793317 /* TipperViewModel.swift in Sources */,
);
Expand Down
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions TipperSwiftUI/Views/CalculatedAmountView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// CalculatedAmountView.swift
// TipperSwiftUI
//
// Created by Vui Nguyen on 3/17/22.
//

import SwiftUI

struct CalculatedAmountView: View {
let amountLabel: String
let amount: String

var body: some View {
HStack(alignment: .center) {
Text(amountLabel)
.primaryStyle()
Spacer(minLength: 100)
Text(amount)
.font(.title2)
.fontWeight(.bold)
// Color in hex #323A56
.foregroundColor(Color(red: 0.19607843137254902, green: 0.22745098039215686, blue: 0.33725490196078434))
Spacer()
.frame(width: 20)
}
}
}

struct CalculatedAmountView_Previews: PreviewProvider {
static var previews: some View {
CalculatedAmountView(amountLabel: "Tip Amount", amount: "$0.00")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,15 @@ struct ContentView: View {
Spacer()
.frame(height: 30)
VStack {
HStack(alignment: .center) {
Text("Tip Amount")
.primaryStyle()
Spacer(minLength: 100)
Text(viewModel.getTipAmountStringFormatted(tipPercent: selectedTipPercentage, billAmount: billAmount))
.font(.subheadline)
.fontWeight(.regular)
// Color in hex #323A56
.foregroundColor(Color(red: 0.19607843137254902, green: 0.22745098039215686, blue: 0.33725490196078434))
Spacer()
.frame(width: 20)
}

CalculatedAmountView(amountLabel: "Tip Amount", amount: viewModel.getTipAmountStringFormatted(tipPercent: selectedTipPercentage, billAmount: billAmount))

Divider()
.padding(.horizontal)

HStack(alignment: .center) {
Text("Bill Total")
.primaryStyle()
Spacer(minLength: 100)
Text(viewModel.getBillTotalStringFormatted(tipPercent: selectedTipPercentage, billAmount: billAmount))
.font(.title2)
.fontWeight(.bold)
// Color in hex #323A56
.foregroundColor(Color(red: 0.19607843137254902, green: 0.22745098039215686, blue: 0.33725490196078434))
Spacer()
.frame(width: 20)
}
// for bill total, make font = .title2, and fontWeight = .bold
// for tip amount, make font = .subheadline, and fontWeight = .regular
CalculatedAmountView(amountLabel: "Bill Total", amount: viewModel.getBillTotalStringFormatted(tipPercent: selectedTipPercentage, billAmount: billAmount))
}
// Color in hex #E4ECFA
.background(Color(red: 0.8941176470588236, green: 0.9254901960784314, blue: 0.9803921568627451))
Expand Down
44 changes: 44 additions & 0 deletions TipperSwiftUI/Views/TipAmountView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// TipAmountView.swift
// TipperSwiftUI
//
// Created by Vui Nguyen on 3/17/22.
//

import SwiftUI

// Note: This view is deprecated, but keeping it in this file for
// documentation. This view was used before it was refactored into
// the CalculatedAmountView.
// CalculatedAmountView now displays the tip amount AND the bill total views
struct TipAmountView: View {
@Binding var selectedTipPercentage: TipPercent
@Binding var billAmount: Float
let viewModel: TipperViewModel

var body: some View {
HStack(alignment: .center) {
Text("Tip Amount")
.primaryStyle()
Spacer(minLength: 100)
Text(viewModel.getTipAmountStringFormatted(tipPercent: selectedTipPercentage, billAmount: billAmount))
.font(.subheadline)
.fontWeight(.regular)
// Color in hex #323A56
.foregroundColor(Color(red: 0.19607843137254902, green: 0.22745098039215686, blue: 0.33725490196078434))
Spacer()
.frame(width: 20)
}
}
}

// According to a StackOverflow post, we have to set up the binding variables
// into the preview this work for it to work:
// https://stackoverflow.com/a/60105482
struct TipAmountView_Previews: PreviewProvider {
@State static var selectedTipPercentage = TipPercent.fifteen
@State static var billAmount = Float(10.00)
static var previews: some View {
TipAmountView(selectedTipPercentage: $selectedTipPercentage, billAmount: $billAmount, viewModel: TipperViewModel())
}
}
16 changes: 0 additions & 16 deletions TipperSwiftUITests/TipperSwiftUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ class TipperSwiftUITests: XCTestCase {

let tipperViewModel = TipperViewModel()

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testGetBillAmount() throws {
let billText = "10.50"
let billAmount = Float(10.50)
Expand Down Expand Up @@ -63,12 +55,4 @@ class TipperSwiftUITests: XCTestCase {
let billAmount = Float(23.0)
XCTAssertEqual(tipperViewModel.getBillTotalStringFormatted(tipPercent: tipPercent, billAmount: billAmount), "$28.75")
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}

0 comments on commit 50beaf0

Please sign in to comment.