closed #104
This commit is contained in:
@@ -12,17 +12,11 @@ struct CreateWidgetView: View {
|
|||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
@StateObject private var customWidget: CustomWidgetModel
|
@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 private var mouth: CustomWidgetMouthOptions = CustomWidgetMouthOptions.defaultOption
|
||||||
|
|
||||||
|
@State var widgetView: CustomWidgetView
|
||||||
|
|
||||||
private var randomElements: [AnyView]
|
private var randomElements: [AnyView]
|
||||||
|
|
||||||
init(customWidget: CustomWidgetModel, randomElements: [AnyView] = [AnyView]()) {
|
init(customWidget: CustomWidgetModel, randomElements: [AnyView] = [AnyView]()) {
|
||||||
@@ -42,6 +36,8 @@ struct CreateWidgetView: View {
|
|||||||
]
|
]
|
||||||
|
|
||||||
_customWidget = StateObject(wrappedValue: customWidget)
|
_customWidget = StateObject(wrappedValue: customWidget)
|
||||||
|
|
||||||
|
_widgetView = State(initialValue:CustomWidgetView(customWidgetModel: customWidget))
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(eye: CustomWidgetEyes, eyeOption: CustomWidgetEyeOptions) {
|
func update(eye: CustomWidgetEyes, eyeOption: CustomWidgetEyeOptions) {
|
||||||
@@ -51,6 +47,8 @@ struct CreateWidgetView: View {
|
|||||||
case .right:
|
case .right:
|
||||||
customWidget.rightEye = eyeOption
|
customWidget.rightEye = eyeOption
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widgetView = CustomWidgetView(customWidgetModel: customWidget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRandom() {
|
func createRandom() {
|
||||||
@@ -67,14 +65,18 @@ struct CreateWidgetView: View {
|
|||||||
update(mouthOption: CustomWidgetMouthOptions.allCases.randomElement()!)
|
update(mouthOption: CustomWidgetMouthOptions.allCases.randomElement()!)
|
||||||
|
|
||||||
update(background: CustomWidgetBackGroundOptions.allCases.randomElement()!)
|
update(background: CustomWidgetBackGroundOptions.allCases.randomElement()!)
|
||||||
|
|
||||||
|
widgetView = CustomWidgetView(customWidgetModel: customWidget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(mouthOption: CustomWidgetMouthOptions) {
|
func update(mouthOption: CustomWidgetMouthOptions) {
|
||||||
customWidget.mouth = mouthOption
|
customWidget.mouth = mouthOption
|
||||||
|
widgetView = CustomWidgetView(customWidgetModel: customWidget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(background: CustomWidgetBackGroundOptions) {
|
func update(background: CustomWidgetBackGroundOptions) {
|
||||||
customWidget.background = background
|
customWidget.background = background
|
||||||
|
widgetView = CustomWidgetView(customWidgetModel: customWidget)
|
||||||
}
|
}
|
||||||
|
|
||||||
var mixBG: some View {
|
var mixBG: some View {
|
||||||
@@ -90,10 +92,6 @@ struct CreateWidgetView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var widgetView: some View {
|
|
||||||
CustomWidgetView(customWidgetModel: customWidget)
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
widgetView
|
widgetView
|
||||||
@@ -245,13 +243,13 @@ struct CreateWidgetView: View {
|
|||||||
Button(action: {
|
Button(action: {
|
||||||
createRandom()
|
createRandom()
|
||||||
}, label: {
|
}, label: {
|
||||||
Text("Random")
|
Image(systemName: "shuffle")
|
||||||
.font(.title)
|
.font(.title)
|
||||||
.fontWeight(.bold)
|
|
||||||
.foregroundColor(Color(UIColor.white))
|
.foregroundColor(Color(UIColor.white))
|
||||||
|
|
||||||
})
|
})
|
||||||
.frame(minWidth: 0, maxWidth: .infinity)
|
.frame(minWidth: 0, maxWidth: .infinity)
|
||||||
|
.frame(height: 40)
|
||||||
.background(.blue)
|
.background(.blue)
|
||||||
|
|
||||||
Button(action: {
|
Button(action: {
|
||||||
@@ -267,24 +265,10 @@ struct CreateWidgetView: View {
|
|||||||
|
|
||||||
})
|
})
|
||||||
.frame(minWidth: 0, maxWidth: .infinity)
|
.frame(minWidth: 0, maxWidth: .infinity)
|
||||||
|
.frame(height: 40)
|
||||||
.background(.green)
|
.background(.green)
|
||||||
|
|
||||||
if customWidget.isSaved {
|
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: {
|
Button(action: {
|
||||||
UserDefaultsStore.makeWidgetCurrent(withUUID: customWidget.uuid)
|
UserDefaultsStore.makeWidgetCurrent(withUUID: customWidget.uuid)
|
||||||
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
|
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
|
||||||
@@ -297,8 +281,25 @@ struct CreateWidgetView: View {
|
|||||||
.foregroundColor(Color(UIColor.white))
|
.foregroundColor(Color(UIColor.white))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
.frame(height: 40)
|
||||||
.frame(minWidth: 0, maxWidth: .infinity)
|
.frame(minWidth: 0, maxWidth: .infinity)
|
||||||
.background(.pink)
|
.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 {
|
struct CreateIconView_Previews: PreviewProvider {
|
||||||
|
static var widget: CustomWidgetModel {
|
||||||
|
let _widget = CustomWidgetModel.randomWidget
|
||||||
|
_widget.isSaved = true
|
||||||
|
return _widget
|
||||||
|
}
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
Group {
|
||||||
CreateWidgetView(customWidget: CustomWidgetModel.randomWidget)
|
CreateWidgetView(customWidget: CreateIconView_Previews.widget)
|
||||||
|
|
||||||
CreateWidgetView(customWidget: CustomWidgetModel.randomWidget)
|
CreateWidgetView(customWidget: CustomWidgetModel.randomWidget)
|
||||||
.preferredColorScheme(.dark)
|
.preferredColorScheme(.dark)
|
||||||
|
|||||||
Reference in New Issue
Block a user