You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,27 +12,24 @@ Add this Swift package in Xcode using its Github repository url. (File > Swift P
12
12
13
13
## 🚀 How to use
14
14
15
-
You control the view through an instance of `ListService`. The service manages the current state and the items of the list.
16
-
Use it to append, update or remove items and to modify the state of the list. The `AdvancedList`view listens to the service and updates itself if needed.
15
+
The `AdvancedList` view is similar to the `List` and `ForEach` views. You have to pass data (`RandomAccessCollection`) and a view provider (`(Data.Element) -> some View`) to the initializer. In addition to the `List` view the `AdvancedList` expects a list state and corresponding views.
16
+
Modify your data anytime or hide an item through the content block if you like. The view is updated automatically 🎉.
You can define which actions your list should support through the `supportedListActions` property of your `ListService` instance.
91
-
Choose between `delete`, `move`, `moveAndDelete`and `none`. **The default is `none`.**
87
+
You can define which actions your list should support through the `onMoveAction` and `onDeleteAction` initializer parameters.
88
+
**Per default the moveand delete functions are disabled if you skip the parameters.**
92
89
93
90
```swift
94
-
let listService =ListService()
95
-
listService.supportedListActions= .moveAndDelete(onMove: { indexSet, index in
96
-
// move me
97
-
}, onDelete: { indexSet in
98
-
// please delete me
99
-
})
91
+
importAdvancedList
92
+
93
+
@Stateprivatevar listState: ListState = .items
94
+
95
+
AdvancedList(yourData, content: { item in
96
+
Text("Item")
97
+
}, listState: $listState, onMoveAction: { (indexSet, index) in
98
+
// do something
99
+
}, onDeleteAction: { indexSet in
100
+
// do something
101
+
}, emptyStateView: {
102
+
Text("No data")
103
+
}, errorStateView: { error in
104
+
Text(error.localizedDescription)
105
+
.lineLimit(nil)
106
+
}, loadingStateView: {
107
+
Text("Loading ...")
108
+
}, pagination: .noPagination)
100
109
```
101
110
102
111
### 🎛️ Filtering
103
112
104
-
The `AdvancedList` supports filtering (**disabled by default**). You only have to set the closure `excludeItem: (AnyListItem) -> Bool)` on your `ListService` instance.
105
-
`AnyListItem` gives you access to the item (`Any`). **Keep in mind that you have to cast this item to your custom type!**
113
+
**You can hide items in your list through the content block.** Only return a view in the content block if a specific condition is met.
114
+
115
+
## 🎁 Example
116
+
117
+
The following code shows how easy-to-use the view is:
For more examples take a look at [AdvancedList-SwiftUI](https://github.com/crelies/AdvancedList-SwiftUI).
113
145
114
-
The following code shows how easy-to-use the view is:
146
+
## Migration 2.x -> 3.0
147
+
148
+
The `AdvancedList` was dramatically simplified and is now more like the `List` and `ForEach` SwiftUI views.
149
+
150
+
1. Delete your list service instances and directly **pass your data to the list initializer**
151
+
2. Create your views through a content block (**initializer parameter**) instead of conforming your items to `View` directly (removed type erased wrapper `AnyListItem`)
152
+
3. Pass a list state binding to the initializer (**before:** the `ListService` managed the list state)
153
+
4.**Move and delete:** Instead of setting `AdvancedListActions` on your list service just pass a `onMoveAction` and/or `onDeleteAction` block to the initializer
115
154
155
+
**Before:**
116
156
```swift
117
157
importAdvancedList
118
158
119
159
let listService =ListService()
120
-
listService.appendItems(yourItems)
121
-
listService.listState= .items
160
+
listService.supportedListActions= .moveAndDelete(onMove: { (indexSet, index) in
0 commit comments