Skip to content

Commit

Permalink
Merge pull request #144 from skyefreeman/skye/telephone-fix
Browse files Browse the repository at this point in the history
[Fix]: Telephone layout + Telephone deletion
  • Loading branch information
NickCulbertson authored Jan 4, 2024
2 parents 3b8f606 + 22b6b06 commit cdc782e
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SwiftUI
class TelephoneConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()

@Published var last10Digits = " "
@Published var last10Digits = ""

let dialTone = OperationGenerator {
let dialTone1 = Operation.sineWave(frequency: 350)
Expand Down Expand Up @@ -165,7 +165,7 @@ struct Phone: View {
Image(systemName: "phone.fill").font(.largeTitle)
}
.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local).onChanged { _ in
if conductor.last10Digits.count > 1 {
if conductor.last10Digits.count > 0 {
conductor.doit(key: "CALL", state: "down")
}
}.onEnded { _ in
Expand All @@ -191,16 +191,18 @@ struct Phone: View {
Image(systemName: "delete.left.fill").font(.largeTitle)
}
.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local).onEnded { _ in
if conductor.last10Digits.count > 1 {
if conductor.last10Digits.count > 0 {
conductor.last10Digits.removeLast()
}
})
}

var body: some View {
VStack {
Text(conductor.last10Digits).font(.largeTitle)
VStack {
Text(formattedPhoneNumber(conductor.last10Digits))
.font(.largeTitle)

VStack(spacing: 20) {
HStack(spacing: 20) {
NumberKey(mainDigit: "1")
NumberKey(mainDigit: "2", alphanumerics: "A B C")
Expand Down Expand Up @@ -230,6 +232,12 @@ struct Phone: View {
}
.padding()
}

// MARK: - Phone - Private

private func formattedPhoneNumber(_ digits: String) -> String {
return digits == "" ? " " : digits
}
}

struct Telephone: View {
Expand Down

0 comments on commit cdc782e

Please sign in to comment.