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
Nibel supports result-based navigation that allows screens to return typed data to the previous screen. This feature integrates with Android's Activity Result API pattern while maintaining Nibel's type-safe approach.
251
+
252
+
### Declaring a result screen
253
+
254
+
To create a screen that can return a result, specify the `result` parameter in your annotation with a `Parcelable` result type:
255
+
256
+
```kotlin
257
+
@Parcelize
258
+
data classPhotoResult(
259
+
valphotoUrl:String,
260
+
valphotoName:String,
261
+
valtimestamp:Long = System.currentTimeMillis()
262
+
) : Parcelable
263
+
264
+
@UiEntry(
265
+
type =ImplementationType.Composable,
266
+
args =PhotoArgs::class,
267
+
result =PhotoResult::class// This screen can return PhotoResult
268
+
)
269
+
@Composable
270
+
funPhotoPickerScreen(
271
+
args:PhotoArgs,
272
+
navigator:NavigationController
273
+
) {
274
+
// Your screen content
275
+
Button(onClick = {
276
+
val selectedPhoto =PhotoResult("url", "name")
277
+
navigator.setResultAndNavigateBack(selectedPhoto)
278
+
}) {
279
+
Text("Select Photo")
280
+
}
281
+
282
+
// Or cancel without result
283
+
Button(onClick = {
284
+
navigator.cancelResultAndNavigateBack()
285
+
}) {
286
+
Text("Cancel")
287
+
}
288
+
}
289
+
```
290
+
291
+
When you build the code, the generated entry class will implement both `ComposableEntry` and `ResultEntry<PhotoResult>` interfaces.
292
+
293
+
### Navigating for a result
294
+
295
+
To navigate to a result-returning screen and receive the result:
296
+
297
+
```kotlin
298
+
@UiEntry(type =ImplementationType.Composable)
299
+
@Composable
300
+
funHomeScreen(navigator:NavigationController) {
301
+
var selectedPhoto by remember { mutableStateOf<PhotoResult?>(null) }
0 commit comments