mirror of
https://github.com/1SecondEveryday/MemoryTree.git
synced 2026-03-25 08:55:47 +00:00
Add a leafier tree with animals and blossoms
This commit is contained in:
parent
79c7432428
commit
07355e8eb5
6 changed files with 133 additions and 18 deletions
38
MemoryTree/Assets.xcassets/Grass.colorset/Contents.json
Normal file
38
MemoryTree/Assets.xcassets/Grass.colorset/Contents.json
Normal 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
|
||||
}
|
||||
}
|
||||
38
MemoryTree/Assets.xcassets/Sky.colorset/Contents.json
Normal file
38
MemoryTree/Assets.xcassets/Sky.colorset/Contents.json
Normal 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
|
||||
}
|
||||
}
|
||||
21
MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/Contents.json
vendored
Normal file
21
MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/TreeLeafierBlossoms.png
vendored
Normal file
BIN
MemoryTree/Assets.xcassets/TreeLeafierBlossoms.imageset/TreeLeafierBlossoms.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 362 KiB |
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue