Hi All,
Currently reading the RxSwift book and stumbling on an issue which has to do with passing data back from a presented view controller. Here’s what I would like to do.
I have a list of items; when I click on an item, I modally present a view controller with a new navigationController which shows details of the item. After performing a service call I would like to
- Dismiss the latest presented view controller and return to the list
- Present a snackbar to the user indicating a success.
In order to dismiss the latest presented view controller I use the SceneCoordinator class.
The presenting view model has an observable onReservationSuccess which the view controller has been subscribed to in order to present the snackbar.
The view model of the details screen is constructed by passing an Action like so:
let detailViewModel = ItemDetailsViewModel(sceneCoordinator: sceneCoordinator, item: item, onItemReservedAction: self.onItemReserved(item: item))
The onItemReserved action is a CocoaAction that should only send a .next event in the onReservationSuccess Observable.
func onItemReserved(item: Item) -> CocoaAction { return CocoaAction { // Present the snackbar self.onReservationSuccess.onNext("\(item.name) successfully reserved.") return Observable.empty() } }
The modally presented view controller gets dismissed, but I never see the snackbar.
I assume the dismissal of the presented view controller is done in the view modal of the presented view controller by calling pop() on the SceneCoordinator.
My questions are:
-
Do I have a correct definition of the onItemReserved Action?
-
What is the correct sequence of 1) the dismissal and 2) the CocoaAction to present the snackbar?
Any help is greatly appreciated.
Regards, Raoul.