uber / RIBs

Uber's cross-platform mobile architecture framework.
https://eng.uber.com/tag/ribs/
Apache License 2.0
7.74k stars 903 forks source link

[iOS] How Uber create a viewable RIB based on UIView not UIViewController ? #362

Open qhhonx opened 4 years ago

qhhonx commented 4 years ago

As documentation mentioned that a RIB can be viewable or viewless, it is found that viewable RIB must be associated with UIViewController. However, I think it is not possible and most viewable RIB should be UIView-based as RIBs framework encouraging us to make reusable and micro components.

As the below image shown, are those viewable RIBs (Confirmation, Location Refinements, Menu) UIViewController based? image

dangthaison91 commented 4 years ago

My idea is that we can recursive to get parent viewcontroller from a UIView:

extension UIView {
    func findViewController() -> UIViewController? {
        if let nextResponder = self.next as? UIViewController {
            return nextResponder
        } else if let nextResponder = self.next as? UIView {
            return nextResponder.findViewController()
        } else {
            return nil
        }
    }
}

But not sure if actually does Uber team are having UIView with RIB instead of UIViewController.

kovpas commented 4 years ago

All viewable RIBs on the diagram above (Confirmation, Location Refinements, Menu) are UIViewController based.

theangelperalta commented 4 years ago

@qhhonx, Why would you like to use a UIView vs. UIViewController? A common misconception in iOS development is that UIViewController needs to represent a single "screen" in application; however, this is not the case. UIViewController can be composed of subsequent child UIViewControllers. These child UIViewControllers can represent something as small as a button. Hence, why it seems why these examples stick to using UIViewControllers instead of UIViews. What's the use case for just using a UIView?

aurelienp commented 1 year ago

Some thoughts about this topic:

Before diving into the details of the RIBs internals, I'd like to turn the question around and ask what is the strong reason for RIBS to force the usage of UIViewController? Is it because it needs to track things such as appearance, disappearance?