fix customizing widgets not working
This commit is contained in:
@@ -16,7 +16,7 @@ struct CreateWidgetView: View {
|
|||||||
|
|
||||||
@State private var mouth: CustomWidgetMouthOptions = CustomWidgetMouthOptions.defaultOption
|
@State private var mouth: CustomWidgetMouthOptions = CustomWidgetMouthOptions.defaultOption
|
||||||
|
|
||||||
@State var widgetView: CustomWidgetView
|
var widgetView: CustomWidgetView
|
||||||
|
|
||||||
private var randomElements: [AnyView]
|
private var randomElements: [AnyView]
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ struct CreateWidgetView: View {
|
|||||||
|
|
||||||
_customWidget = StateObject(wrappedValue: customWidget)
|
_customWidget = StateObject(wrappedValue: customWidget)
|
||||||
|
|
||||||
_widgetView = State(initialValue:CustomWidgetView(customWidgetModel: customWidget))
|
widgetView = CustomWidgetView(customWidgetModel: customWidget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(eye: CustomWidgetEyes, eyeOption: CustomWidgetEyeOptions) {
|
func update(eye: CustomWidgetEyes, eyeOption: CustomWidgetEyeOptions) {
|
||||||
@@ -48,8 +48,6 @@ struct CreateWidgetView: View {
|
|||||||
case .right:
|
case .right:
|
||||||
customWidget.rightEye = eyeOption
|
customWidget.rightEye = eyeOption
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetView = CustomWidgetView(customWidgetModel: customWidget)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRandom() {
|
func createRandom() {
|
||||||
@@ -66,18 +64,14 @@ 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 {
|
||||||
|
|||||||
@@ -79,21 +79,32 @@ class CustomWidgetModel: ObservableObject, Codable, NSCopying {
|
|||||||
@Published var isSaved: Bool
|
@Published var isSaved: Bool
|
||||||
@Published var createdDate: Date
|
@Published var createdDate: Date
|
||||||
|
|
||||||
|
private var oldBackground: CustomWidgetBackGroundOptions?
|
||||||
|
private var oldBackgroundImages: [(Image, String)]?
|
||||||
|
|
||||||
public var backgroundImages : [(Image, String)] {
|
public var backgroundImages : [(Image, String)] {
|
||||||
|
if let oldBackgroundImages = oldBackgroundImages,
|
||||||
|
oldBackground == background {
|
||||||
|
return oldBackgroundImages
|
||||||
|
}
|
||||||
|
|
||||||
|
oldBackground = background
|
||||||
|
|
||||||
if background == .random {
|
if background == .random {
|
||||||
var blah = [(Image, String)]()
|
var blah = [(Image, String)]()
|
||||||
for _ in 0...CustomWidgetModel.numberOfBGItems {
|
for _ in 0...CustomWidgetModel.numberOfBGItems {
|
||||||
let image = CustomWidgetBackGroundOptions.selectable.randomElement()?.image ?? CustomWidgetBackGroundOptions.defaultOption.image
|
let image = CustomWidgetBackGroundOptions.selectable.randomElement()?.image ?? CustomWidgetBackGroundOptions.defaultOption.image
|
||||||
blah.append((image, UUID().uuidString))
|
blah.append((image, UUID().uuidString))
|
||||||
}
|
}
|
||||||
return blah
|
oldBackgroundImages = blah
|
||||||
} else {
|
} else {
|
||||||
var blah = [(Image, String)]()
|
var blah = [(Image, String)]()
|
||||||
for _ in 0...CustomWidgetModel.numberOfBGItems {
|
for _ in 0...CustomWidgetModel.numberOfBGItems {
|
||||||
blah.append((background.image, UUID().uuidString))
|
blah.append((background.image, UUID().uuidString))
|
||||||
}
|
}
|
||||||
return blah
|
oldBackgroundImages = blah
|
||||||
}
|
}
|
||||||
|
return oldBackgroundImages!
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: CodingKey {
|
enum CodingKeys: CodingKey {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct CustomWidgetView: View {
|
struct CustomWidgetView: View {
|
||||||
@State public var customWidgetModel: CustomWidgetModel
|
@StateObject public var customWidgetModel: CustomWidgetModel
|
||||||
|
|
||||||
private let facePercSize = 0.6
|
private let facePercSize = 0.6
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user