Add a leafier tree with animals and blossoms

This commit is contained in:
Sami Samhuri 2023-02-05 15:39:42 -08:00
parent 79c7432428
commit 07355e8eb5
No known key found for this signature in database
GPG key ID: 4B4195422742FC16
6 changed files with 133 additions and 18 deletions

View file

@ -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
}
}

View file

@ -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
}
}

View file

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

View file

@ -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
}

View file

@ -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)