Commit 70a108e
committed
docs: Enhance README with Android and iOS implementation examples
This commit significantly updates the README.md to provide more detailed and practical usage examples for integrating the PollingEngine into Android and iOS applications.
**Key Changes to README.md:**
* **Android Implementation Section:**
* Added a new "Android Implementation" section.
* Provides a complete `ViewModel` example demonstrating how to:
* Use `Polling.startPolling` within a `viewModelScope`.
* Define `fetch`, `isTerminalSuccess`, and `backoff` policies.
* Collect the resulting `Flow<PollingOutcome>` and update a `MutableStateFlow` for UI observation.
* Retrieve the polling session ID using `Polling.listActiveIds()`.
* Implement `cancelPolling()` using `Polling.cancel(id)`.
* Properly cancel polling in `onCleared()` to prevent leaks.
* Includes a `PollingUiState` sealed class example for managing UI states (Idle, Loading, Success, Error).
* **iOS (Swift) Implementation Section:**
* Added a new "iOS (Swift) Implementation" section.
* Demonstrates creating a helper object (`IosPollingHelper`) in the shared Kotlin module to bridge to Swift.
* The helper exposes a `startStatusPolling` function that takes Swift closures for updates (`onUpdate`) and completion (`onComplete`).
* It uses `CoroutineScope(Dispatchers.Main)` and `launchIn` for flow collection.
* Provides a SwiftUI `PollingViewModel` example:
* Uses `@Published` to expose status to the UI.
* Calls the shared Kotlin helper's `startStatusPolling` function.
* Handles different `PollingOutcome` types in the `onComplete` closure to update the UI.
* Shows how to cancel the `Kotlinx_coroutines_coreJob`.
* Includes a basic SwiftUI `ContentView` example with buttons to start and cancel polling.
* **Removed Sections:**
* Removed the generic "Usage" section with basic shared code, as the new platform-specific examples are more comprehensive.
* Removed the "Control APIs and Runtime Updates" section as its content is implicitly covered or better suited for more advanced documentation.
* Removed the "RetryPredicates examples" section, as common predicates are often shown within the configuration examples.
* Removed the "More documentation" section that linked to internal docs, simplifying the main README.
* **Minor Adjustments:**
* Platform-specific notes regarding `expect/actual` and coroutines were removed as they are general KMP concepts and the examples implicitly demonstrate their usage.
* API reference generation instructions were removed.
**Overall Improvement:**
The README now offers clearer, step-by-step guidance for developers looking to integrate the PollingEngine into their Android (Jetpack Compose with ViewModel) and iOS (SwiftUI with ObservableObject) projects, focusing on common patterns and best practices for each platform.1 parent c3cdaa6 commit 70a108e
1 file changed
Lines changed: 140 additions & 103 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
| 117 | + | |
117 | 118 | | |
| 119 | + | |
118 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
119 | 170 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
126 | 175 | | |
127 | 176 | | |
128 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
129 | 183 | | |
130 | 184 | | |
131 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
132 | 188 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
143 | 193 | | |
144 | | - | |
145 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
146 | 215 | | |
147 | 216 | | |
148 | 217 | | |
149 | 218 | | |
150 | | - | |
| 219 | + | |
151 | 220 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
159 | 253 | | |
160 | 254 | | |
161 | 255 | | |
162 | 256 | | |
| 257 | + | |
163 | 258 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
170 | 274 | | |
171 | 275 | | |
172 | 276 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | 277 | | |
185 | 278 | | |
186 | 279 | | |
| |||
258 | 351 | | |
259 | 352 | | |
260 | 353 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| |||
0 commit comments