Last active
January 24, 2025 14:37
-
-
Save Koshimizu-Takehito/7fe0e27b5c4df930c9c5c622db1325d2 to your computer and use it in GitHub Desktop.
逆向きのリスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct Item: Identifiable, Hashable { | |
| var id = UUID() | |
| } | |
| struct ContentView: View { | |
| @State var items = [Item()] | |
| var body: some View { | |
| NavigationStack { | |
| List(items) { item in | |
| RowContent(item: item) | |
| .listRowSeparator(.hidden) | |
| .rotationEffect(.radians(.pi)) | |
| } | |
| .rotationEffect(.radians(.pi)) | |
| .scrollIndicators(.hidden) | |
| .animation(.default, value: items) | |
| .listStyle(.plain) | |
| .toolbar { | |
| Button("plus", systemImage: "plus") { | |
| items.insert(Item(), at: 0) | |
| } | |
| Button("minus", systemImage: "minus") { | |
| if !items.isEmpty { | |
| items.removeFirst() | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| struct RowContent: View { | |
| var item: Item | |
| var color: Color { | |
| Color( | |
| hue: Double(abs(item.hashValue)) / Double(Int.max), | |
| saturation: 0.8, | |
| brightness: 0.8 | |
| ) | |
| } | |
| var body: some View { | |
| HStack { | |
| Image(systemName: "globe") | |
| .imageScale(.large) | |
| .foregroundStyle(color) | |
| Text("Hello, world!") | |
| } | |
| .frame(maxWidth: .infinity, alignment: .leading) | |
| .padding() | |
| .background(color.secondary) | |
| .clipShape(.rect(cornerRadius: 10)) | |
| .font(.title) | |
| .fontWeight(.bold) | |
| } | |
| } | |
| #Preview { | |
| ContentView() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment