-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update backstack record screen when returning value #295
Conversation
ea0e339
to
b6a7c86
Compare
Instead of adding an
Users would only need to provide a reducer when bootstrapping Circuit if/when they expect one screen to return data to another |
b6a7c86
to
dbf497a
Compare
Maintaining initial description here:
|
@ZacSweers I circled back to this over the holidays and added a demo (as requested). There's still some more work to be done (cleanup, docs, tests, etc). Interested in your thoughts as I'm sure there is room for improvement. |
@ZacSweers and I chatted and agree that we don't have enough info yet to say for certain whether or not we actually need the ability to return data from one screen to another. Closing this until we find a compelling reason to revisit. |
This PR adds support for returning results from one screen to another, or - if an interceptor is set - to the activity or fragment managing the Circuit environment. This addresses #8.
Details
This PR adds several new concepts to assist returning values:
ScreenResult
- new marker interface that must be implemented by result objectsScreenResultHandler
- used by screen presenters when returning a valueScreenResultInterceptor
- optional callback (provided when callingNavigableCircuitContent
) to intercept screen results for processing in an activity or fragment.ScreenReducer
- new SAM interface that accepts aScreen
andScreenResult
, and returnsScreen?
How does it work?
To support situations where Circuit is running next to activities and fragments, there are two possible execution paths.
Screen-to-Screen
Child screen wishes to return a result to a parent screen, all within a single Circuit environment:
ScreenResultHandler
with a sub-class ofScreenResult
BasicNavigableCircuitContent
:a. extracts the parent screen and pending result from the top backstack record
b. attempts to create a new screen using any
ScreenReducer
's registered with theCircuitConfig
c. recreates the backstack record using the new screen
BasicNavigableCircuitContent
updates the composition as before but now using the new screen instance (created at 4b) containing data from processed screen resultScreen-to-[Activity/Fragment]
The Activity or Fragment managing the Circuit environment wishes to intercept a specific
ScreenResult
sub-typeScreenResultInterceptor
callback when callingNavigableCircuitContent
ScreenResultHandler
with a sub-class ofScreenResult
ScreenResultInterceptor
allowing the host to intercept resultsa. intercepted, execution stops
b. otherwise, execution mirrors step 4 above
Demo
To better demonstrate how both use cases work, I have added a new sample application at
samples/navigation
navigator-demo.mp4
Remaining work
Some minor cleanup, KDocs and comments, tests, etc