-
-
Save sturdysturge/9c9b6a119f79a4eea125f1ea62d1b441 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 { | |
| let id: Int | |
| } | |
| struct ContentView: View { | |
| @State var items: [Item] = (0...10).map { Item(id: $0) } | |
| var body: some View { | |
| NavigationView { | |
| List { | |
| ForEach(items) { item in | |
| ToggleView(title: "Item \(item.id)") | |
| } | |
| .onMove { from, to in | |
| items.move(fromOffsets: from, toOffset: to) | |
| } | |
| } | |
| .toolbar { | |
| EditButton() | |
| } | |
| } | |
| } | |
| } | |
| struct ToggleView: View { | |
| let title: String | |
| @State var locked = false | |
| var body: some View { | |
| Toggle(title, isOn: $locked) | |
| .moveDisabled(locked) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment