Improve handling in LiveObject and ObjectSnapshot when objects are deleted

This commit is contained in:
John Estropia
2019-10-17 19:27:03 +09:00
parent bd066f0cef
commit 6e3e540d0a
9 changed files with 194 additions and 118 deletions

View File

@@ -75,24 +75,6 @@ extension Palette {
}
}
extension LiveObject where ObjectType == Palette {
var color: UIColor {
return UIColor(
hue: CGFloat(self.hue) / 360.0,
saturation: CGFloat(self.saturation),
brightness: CGFloat(self.brightness),
alpha: 1.0
)
}
var colorText: String {
return "H: \(self.hue)˚, S: \(round(self.saturation * 100.0))%, B: \(round(self.brightness * 100.0))%"
}
}
extension Palette {
func setInitialValues(in transaction: BaseDataTransaction) {

View File

@@ -116,10 +116,10 @@ struct ColorCell: View {
var body: some View {
HStack {
Color(palette.color)
Color(palette.color ?? UIColor.clear)
.cornerRadius(5)
.frame(width: 30, height: 30, alignment: .leading)
Text(palette.colorText)
Text(palette.colorText ?? "<Deleted>")
}
}
}
@@ -140,18 +140,18 @@ struct DetailView: View {
init(palette: LiveObject<Palette>) {
self.palette = palette
self.hue = Float(palette.hue)
self.saturation = palette.saturation
self.brightness = palette.brightness
self.hue = Float(palette.hue ?? 0)
self.saturation = palette.saturation ?? 0
self.brightness = palette.brightness ?? 0
}
var body: some View {
ZStack {
Color(palette.color)
Color(palette.color ?? UIColor.clear)
.cornerRadius(20)
.padding(20)
VStack {
Text(palette.colorText)
Text(palette.colorText ?? "<Deleted>")
.navigationBarTitle(Text("Color"))
Slider(value: $hue, in: 0.0 ... 359.0 as ClosedRange<Float>)
Slider(value: $saturation, in: 0.0 ... 1.0 as ClosedRange<Float>)