简体   繁体   中英

In MVVM + Coordinator, how to deal with sub view?

I'm working on an iOS MVVM + Coordinator/ RxSwift project (non swiftUI).

In the groundViewController, there are multiple items on the screen, and the user can tap on any item to call a detailed view of that item. The detailed view will slide in after tapping on an item, and when the user taps another item, the detailed view will sliding out then sliding in again with updated info. detailedView is half screen size, user can also tap on empty space on groundViewController to dismiss the detailed view (sliding out animation).(So there will be only one detailedView)

I decided to make that detailed view as an UIView, which will have its own coordinator and ViewModel and be added to groundViewControll.view. But I'm now confused about how to communicate between them or event flow.

Question: In MVVM/Coordinator pattern, is it correct to make this flow as:

groundViewController (receive a tap on the object) - > 
groundViewModel - >
groundCoordinator (creat and pass itemID ) - > 
detailedViewCoordinator (creat) - > 
detailedViewModel and detialedView

And who should in charge of detialedView's sliding in/out animation?

When the ground view receives the tap, it tells the ground view model.

  1. The ground view model tells the ground coordinator.
  2. The ground coordinator tells the current detail coordinator (if there is one) to dismiss.
  3. The current detail coordinator dismisses its view.
  4. The ground coordinator creates a new detail coordinator.
  5. The ground coordinator tells the new detail coordinator to present.
  6. The new detail coordinator creates a detail view model and detail view. It passes the detail view model to the detail view.
  7. The detail coordinator presents the detail view.

There are some variations in exactly when items are created and destroyed, but the above is the general idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM