Skip to content

Commit

Permalink
🌲 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Sep 18, 2022
1 parent 76934e2 commit 59c3980
Show file tree
Hide file tree
Showing 10 changed files with 636 additions and 0 deletions.
377 changes: 377 additions & 0 deletions _WrapLayoutDemo/WrapLayoutDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions _WrapLayoutDemo/WrapLayoutDemo/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
137 changes: 137 additions & 0 deletions _WrapLayoutDemo/WrapLayoutDemo/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import SwiftUI
import WrapLayout

struct ContentView: View {
var body: some View {
BookWrapLayout()
}
}

#if DEBUG
@available(iOS 16, *)
struct BookWrapLayout_Previews: PreviewProvider {
static var previews: some View {
BookWrapLayout()
}
}

extension String {
static func randomEmoji() -> String {
let range = 0x1F601...0x1F64F
let ascii = range.lowerBound + Int(arc4random_uniform(UInt32(range.count)))

var view = UnicodeScalarView()
view.append(UnicodeScalar(ascii)!)

let emoji = String(view)

return emoji
}

}

func makeRandom() -> BookWrapLayout.Element {

let count = (0..<20).map { $0 }
.randomElement()!

let text = (0..<count)
.map { _ in
String.randomEmoji()
}
.joined()

return .init(text: text)
}

/// very beginning
@available(iOS 16, *)
struct BookWrapLayout: View {

struct Element: Equatable, Identifiable {
let id: UUID = .init()
var text: String
}

private func content(_ e: Element) -> some View {
Text(e.text)
.padding(4)
.background(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(.blue)
)
}

@State var elements: [Element] = []

var body: some View {

HStack {
VStack {

ScrollView {
WrapLayout {

ForEach(elements) { element in
content(element)
.onTapGesture {
withAnimation(.interactiveSpring()) {
elements.removeAll {
$0.id == element.id
}
}
}
.transition(
.scale.animation(.interactiveSpring())
)
}

content(.init(text: "🐵"))
.animation(.interactiveSpring(), value: elements)

}
.background(.black.opacity(0.1))

}

Spacer()

HStack {
Button {
elements.append(makeRandom())
} label: {
Text("Add")
}

Button {
for _ in (0..<10) {
elements.append(makeRandom())
}
} label: {
Text("Batch")
}


Button {
guard elements.isEmpty == false else { return }
elements.removeLast()
} label: {
Text("Remove")
}

Button {
guard elements.isEmpty == false else { return }
elements.removeAll()
} label: {
Text("Clear")
}
}
.font(.caption)
.padding(16)

}

}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions _WrapLayoutDemo/WrapLayoutDemo/WrapLayoutDemo.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
11 changes: 11 additions & 0 deletions _WrapLayoutDemo/WrapLayoutDemo/WrapLayoutDemoApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import SwiftUI

@main
struct WrapLayoutDemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

0 comments on commit 59c3980

Please sign in to comment.