diff --git a/MemoryTree/Assets.xcassets/Grass.colorset/Contents.json b/MemoryTree/Assets.xcassets/Grass.colorset/Contents.json new file mode 100644 index 0000000..951da38 --- /dev/null +++ b/MemoryTree/Assets.xcassets/Grass.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x78", + "green" : "0xB1", + "red" : "0x7A" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x78", + "green" : "0xB1", + "red" : "0x7A" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MemoryTree/Assets.xcassets/Sky.colorset/Contents.json b/MemoryTree/Assets.xcassets/Sky.colorset/Contents.json new file mode 100644 index 0000000..1923d1a --- /dev/null +++ b/MemoryTree/Assets.xcassets/Sky.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x9E", + "green" : "0x95", + "red" : "0x4F" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x9E", + "green" : "0x95", + "red" : "0x4F" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/Contents.json b/MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/Contents.json new file mode 100644 index 0000000..61c23af --- /dev/null +++ b/MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "TreeLeafierBlossoms.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/TreeLeafierBlossoms.png b/MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/TreeLeafierBlossoms.png new file mode 100644 index 0000000..ff6d38f Binary files /dev/null and b/MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/TreeLeafierBlossoms.png differ diff --git a/MemoryTree/CloudView.swift b/MemoryTree/CloudView.swift index 795a9b0..068117e 100644 --- a/MemoryTree/CloudView.swift +++ b/MemoryTree/CloudView.swift @@ -41,7 +41,7 @@ struct CloudView: View { .padding() .frame(maxWidth: .infinity, maxHeight: .infinity) .edgesIgnoringSafeArea(.bottom) - .background(Color.blue) + .background(Color("Sky")) .foregroundColor(.white) .toolbar { ToolbarItem(placement: .destructiveAction) { @@ -70,6 +70,7 @@ struct CloudView: View { .map(\.text) .flatMap { $0.split(separator: " ") } .map(String.init) + .filter { $0.count >= 3 } return words.reduce(into: [:]) { partialResult, word in partialResult[word, default: 0] += 1 } diff --git a/MemoryTree/ContentView.swift b/MemoryTree/ContentView.swift index bd82918..7f2cfe2 100644 --- a/MemoryTree/ContentView.swift +++ b/MemoryTree/ContentView.swift @@ -25,24 +25,28 @@ struct ContentView: View { @State var entryText = "" var treeImageName: String { - if entries.isEmpty { + switch entries.count { + case 0: return "TreeBare" - } else if entries.count < 3 { // 1-2 + case 1: return "TreeLeafy" - } else if entries.count < 5 { // 3-4 + case 2: return "TreeLeafier" - } else { // 5+ + case 3: return "TreeLeafierAnimals" + default: + return "TreeLeafierBlossoms" } } var treeHeight: Double { - if entries.isEmpty { - return 100 - } else if entries.count < 3 { - return 300 - } else { - return 400 + switch entries.count { + case 0: + return 100 // bare + case 1: + return 300 // leafy + default: + return 400 // leafier } } @@ -59,7 +63,7 @@ struct ContentView: View { } .frame(maxWidth: .infinity, maxHeight: .infinity) .edgesIgnoringSafeArea(isEditing ? [] : .bottom) - .background(Color.blue) + .background(Color("Sky")) } } @@ -79,14 +83,13 @@ struct ContentView: View { isEditing.toggle() } label: { Image(treeImageName) - .renderingMode(entries.count > 0 ? .original : .template) .resizable() .scaledToFit() .foregroundColor(.white) } .frame(maxHeight: treeHeight) - Color.green + Color("Grass") .frame(height: 80) } @@ -95,10 +98,13 @@ struct ContentView: View { TextField("What are you grateful for today?", text: $entryText) .background(Color.white) .tint(Color.blue) + .submitLabel(.done) } .onSubmit { if !entryText.isEmpty { - entries.append(Entry(text: entryText)) + withAnimation { + entries.append(Entry(text: entryText)) + } } entryText = "" isEditing = false @@ -126,18 +132,29 @@ struct ContentView_Previews: PreviewProvider { ContentView(entries: [ Entry(text: "Coffee"), Entry(text: "Burritos"), - Entry(text: "Mountains"), ]) .previewDisplayName("Leafier") + ContentView(entries: [ + Entry(text: "Coffee"), + Entry(text: "Burritos"), + ]) + .previewDisplayName("Leafier - Adding Entry") + ContentView(entries: [ Entry(text: "Coffee"), Entry(text: "Burritos"), Entry(text: "Mountains"), - Entry(text: "Trees"), - Entry(text: "Clean Water"), ]) .previewDisplayName("Leafier with Animals") + + ContentView(entries: [ + Entry(text: "Coffee"), + Entry(text: "Burritos"), + Entry(text: "Mountains"), + Entry(text: "Trees"), + ]) + .previewDisplayName("Leafier with Blossoms") } .tint(.white) .previewLayout(.sizeThatFits)