This commit is contained in:
Trey t
2022-02-26 12:33:06 -06:00
parent b1d3704e9f
commit 8b15c60f0c

View File

@@ -12,17 +12,11 @@ struct CreateWidgetView: View {
@Environment(\.dismiss) var dismiss
@StateObject private var customWidget: CustomWidgetModel
static var iconViewBGs: [(CustomWidgetBackGroundOptions, UUID)] = {
var blah = [(CustomWidgetBackGroundOptions, UUID)]()
for _ in 0...99 {
blah.append((CustomWidgetBackGroundOptions.selectable.randomElement()!, UUID()))
}
return blah
}()
@State private var mouth: CustomWidgetMouthOptions = CustomWidgetMouthOptions.defaultOption
@State var widgetView: CustomWidgetView
private var randomElements: [AnyView]
init(customWidget: CustomWidgetModel, randomElements: [AnyView] = [AnyView]()) {
@@ -42,6 +36,8 @@ struct CreateWidgetView: View {
]
_customWidget = StateObject(wrappedValue: customWidget)
_widgetView = State(initialValue:CustomWidgetView(customWidgetModel: customWidget))
}
func update(eye: CustomWidgetEyes, eyeOption: CustomWidgetEyeOptions) {
@@ -51,6 +47,8 @@ struct CreateWidgetView: View {
case .right:
customWidget.rightEye = eyeOption
}
widgetView = CustomWidgetView(customWidgetModel: customWidget)
}
func createRandom() {
@@ -67,14 +65,18 @@ struct CreateWidgetView: View {
update(mouthOption: CustomWidgetMouthOptions.allCases.randomElement()!)
update(background: CustomWidgetBackGroundOptions.allCases.randomElement()!)
widgetView = CustomWidgetView(customWidgetModel: customWidget)
}
func update(mouthOption: CustomWidgetMouthOptions) {
customWidget.mouth = mouthOption
widgetView = CustomWidgetView(customWidgetModel: customWidget)
}
func update(background: CustomWidgetBackGroundOptions) {
customWidget.background = background
widgetView = CustomWidgetView(customWidgetModel: customWidget)
}
var mixBG: some View {
@@ -90,10 +92,6 @@ struct CreateWidgetView: View {
}
}
var widgetView: some View {
CustomWidgetView(customWidgetModel: customWidget)
}
var body: some View {
VStack(spacing: 0) {
widgetView
@@ -245,13 +243,13 @@ struct CreateWidgetView: View {
Button(action: {
createRandom()
}, label: {
Text("Random")
Image(systemName: "shuffle")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color(UIColor.white))
})
.frame(minWidth: 0, maxWidth: .infinity)
.frame(height: 40)
.background(.blue)
Button(action: {
@@ -267,24 +265,10 @@ struct CreateWidgetView: View {
})
.frame(minWidth: 0, maxWidth: .infinity)
.frame(height: 40)
.background(.green)
if customWidget.isSaved {
Button(action: {
UserDefaultsStore.deleteCustomWidget(withUUID: customWidget.uuid)
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
impactMed.impactOccurred()
dismiss()
}, label: {
Text("Delete")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color(UIColor.white))
})
.frame(minWidth: 0, maxWidth: .infinity)
.background(.orange)
Button(action: {
UserDefaultsStore.makeWidgetCurrent(withUUID: customWidget.uuid)
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
@@ -297,8 +281,25 @@ struct CreateWidgetView: View {
.foregroundColor(Color(UIColor.white))
})
.frame(height: 40)
.frame(minWidth: 0, maxWidth: .infinity)
.background(.pink)
Button(action: {
UserDefaultsStore.deleteCustomWidget(withUUID: customWidget.uuid)
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
impactMed.impactOccurred()
dismiss()
}, label: {
Image(systemName: "trash")
.font(.title)
.foregroundColor(Color(UIColor.white))
})
.frame(height: 40)
.frame(minWidth: 0, maxWidth: .infinity)
.background(.orange)
}
}
}
@@ -307,9 +308,15 @@ struct CreateWidgetView: View {
}
struct CreateIconView_Previews: PreviewProvider {
static var widget: CustomWidgetModel {
let _widget = CustomWidgetModel.randomWidget
_widget.isSaved = true
return _widget
}
static var previews: some View {
Group {
CreateWidgetView(customWidget: CustomWidgetModel.randomWidget)
CreateWidgetView(customWidget: CreateIconView_Previews.widget)
CreateWidgetView(customWidget: CustomWidgetModel.randomWidget)
.preferredColorScheme(.dark)