Skip to content

Commit

Permalink
Add hoursOffsetGMT var as a property of BeatTimeView struct
Browse files Browse the repository at this point in the history
TvOS App:
Add press gesture to toggle display of background circle
Add long press gestures to toggle change timezone to change follow the sun circle color
  • Loading branch information
mulot committed Feb 28, 2024
1 parent eeeacc8 commit 09a19dc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
65 changes: 56 additions & 9 deletions TvOS/BeatTimeTvOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,60 @@

import SwiftUI

//var hoursOffsetGMT = -4

@main
struct BeatTimeTvOSApp: App {
@State var hoursOffsetGMT = BeatTime.hoursOffsetWithGMT()

var body: some Scene {
WindowGroup {
ContentView()

//VStack (alignment: .trailing) {
ZStack (alignment: .topTrailing) {
GMTView(hoursOffsetGMT: $hoursOffsetGMT)
//.background(.green)
ContentView(hoursOffsetGMT: $hoursOffsetGMT)
//.background(.orange)
}
}
}
}

struct ContentView: View {
struct GMTView: View {

@Binding var hoursOffsetGMT: Int

var tap: some Gesture {
TapGesture(count: 1)
.onEnded { print("Tap")}
var body: some View {
HStack {
if hoursOffsetGMT > 0 {
Text("GMT: +\(hoursOffsetGMT)")
.gradientLinear(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient], startPoint: .leading, endPoint: .trailing)
.font(.headline)
}
else {
Text("GMT: \(hoursOffsetGMT)")
.gradientLinear(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient], startPoint: .leading, endPoint: .trailing)
.font(.headline)
}
}
}
}

struct ContentView: View {

@Binding var hoursOffsetGMT: Int
@State var bgCircle: Bool = true

var longPress: some Gesture {
LongPressGesture(minimumDuration: 1.0)
.onEnded { _ in
hoursOffsetGMT += 1
if hoursOffsetGMT == 13 {
hoursOffsetGMT = -12
}
print("longpress > GMT: \(hoursOffsetGMT)")
}
}

var body: some View {
ZStack {
Expand All @@ -39,8 +77,13 @@ struct ContentView: View {
.gradientForeground(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient])
*/
if #available(tvOS 16.0, *) {
BeatTimeView(lineWidth: 40)
.gesture(tap)
BeatTimeView(lineWidth: 40, fullCircleBg: bgCircle, hoursOffsetGMT: hoursOffsetGMT)
.focusable(true)
.highPriorityGesture(longPress)
.onLongPressGesture(minimumDuration: 0.01, pressing: { _ in }) {
print("short press")
bgCircle = !bgCircle
}
}
else {
BeatTimeView(lineWidth: 40)
Expand All @@ -50,12 +93,16 @@ struct ContentView: View {
}

struct BeatTimeTvOSApp_Previews: PreviewProvider {
var hoursOffsetGMT = BeatTime.hoursOffsetWithGMT()

static var previews: some View {
/*
BeatTimeView(lineWidth: 40)
.foregroundColor(.orange)
.font(.largeTitle)
*/
ContentView()
ZStack {
BeatTimeView(lineWidth: 40)
}
}
}
4 changes: 2 additions & 2 deletions View/BeatTImeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct BeatTimeView: View {
var fullCircleBg: Bool = true
var followSun: Bool = true
var bgCircleColor: Color = Color.circleLine
var hoursOffsetGMT: Int = BeatTime.hoursOffsetWithBMT()

var body: some View {
GeometryReader { geometry in
Expand Down Expand Up @@ -86,8 +87,7 @@ struct BeatTimeView: View {

func gradientPosition(date: Date = Date(), frame: CGRect, lenght: CGFloat, followSun: Bool = true) -> (UnitPoint, UnitPoint)
{
let nbHour = BeatTime.hoursOffsetWithBMT()
let angle = -(2 * Double.pi) / 24 * Double(nbHour)
let angle = -(2 * Double.pi) / 24 * Double(hoursOffsetGMT)
let r = lenght / 2
let startCircle = UnitPoint(x: 0.5, y: (1 - (lenght / frame.height)) / 2)
let endCircle = UnitPoint(x: 0.5, y: 1 - ((1 - (lenght / frame.height)) / 2))
Expand Down
8 changes: 1 addition & 7 deletions iOS/BeatTimeiOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,7 @@ struct AlarmSetView: View {
}
}
}

func notificationTitle2beats(title: String) -> String {
var notifBeats = title.replacingOccurrences(of: "@", with: "")
notifBeats = notifBeats.replacingOccurrences(of: " .beats", with: "")
return (notifBeats)
}


var body: some View {
VStack (alignment: .leading) {
NavigationView {
Expand Down

0 comments on commit 09a19dc

Please sign in to comment.