Code: https://github.com/ZT-UC/traffic-light-v1
See files ButtonUIView, ButtonsUIView and ContentView.
There are some comments in them. I hope what I'm trying to accomplish here is clear from comments in ButtonUIView - line 10-11.
Is this even a good approach?
Thanks in advance for any insight / feedback on this.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Case
Toggle between two modes - night and normal one. They can't be turn on at the same time.
Also, you can turn them off individually - see here -> https://www.dropbox.com/s/6mr7r31556on96j/SR_02.mov?dl=0
class ButtonProperties: ObservableObject {
@Published var PowerButtonDisabled:Bool = true
@Published var NightModeDisabled:Bool = true
@Published var NormalModeDisabled:Bool = true
}
struct ThreeButtonsView: View {
@StateObject var buttonProperties: ButtonProperties = ButtonProperties()
var body: some View {
// MARK: Power button
Button(action: {
buttonProperties.NormalModeDisabled = !true
}, label: {
Image(systemName: "power")
.resizable()
.frame(width: 50, height: 50)
.onTapGesture {
withAnimation(.easeInOut(duration: 0.2)) {
buttonProperties.PowerButtonDisabled.toggle()
}
}
.foregroundColor(buttonProperties.PowerButtonDisabled ? .black : .green)
.scaleEffect(buttonProperties.PowerButtonDisabled ? 1.0 : 0.5)
})
// MARK: Night Mode button
Button(action : {
// code
}, label: {
Image(systemName: "moon.fill")
.resizable()
.frame(width: 50, height: 50)
.onTapGesture {
withAnimation(.easeInOut(duration: 0.2)) {
buttonProperties.NightModeDisabled.toggle()
}
}
})
.disabled(buttonProperties.PowerButtonDisabled)
.foregroundColor(buttonProperties.NightModeDisabled ? .gray.opacity(0.25) : .green)
.scaleEffect(buttonProperties.PowerButtonDisabled ? 0.5 : 1.0)
// MARK: Normal Mode button
Button(action : {
// code
}, label: {
Image(systemName: "sun.max.fill")
.resizable()
.frame(width: 50, height: 50)
.font(.system(size: 50))
.onTapGesture {
withAnimation(.easeInOut(duration: 0.2)) {
buttonProperties.NormalModeDisabled.toggle()
}
}
})
.disabled(buttonProperties.PowerButtonDisabled)
.foregroundColor(buttonProperties.NormalModeDisabled ? .gray.opacity(0.25) : .green)
.scaleEffect(buttonProperties.PowerButtonDisabled ? 0.5 : 1.0)
}
}
Hi good people of the internet.
What's the best approach to code a logic of a real life traffic light in Xcode using SwiftUI? Any repos on GitHub / code snippets / tips / etc.