Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Question #73

Closed
h36ahmed opened this issue Dec 27, 2018 · 8 comments
Closed

Question #73

h36ahmed opened this issue Dec 27, 2018 · 8 comments
Labels
question Further information is requested

Comments

@h36ahmed
Copy link

Hi, this is not an issue but more of a question of how to use your library.
I have a view controller built in storyboard and it has multiple views that require their own controller. However, because I don't know how to set child view controller properly, I have one massive view controller managing three different views.
I find this library very useful in terms of separating three views into separate view controllers and having a parent controller.

  1. Can I have FamilyViewController as subclass of my parent controller that is built in storyboard?
  2. For the views that I have setup in storyboard using constraints, is it possible for me to have each view have child view controller like, view1 = viewController1.view when I do add addChild(viewController1)?
  3. How does the memory allocation work, do all child and parent view controllers get deallocated as soon as the navigation controller gets dismissed since they are part of navigation controller stack?
@zenangst
Copy link
Owner

Hey @h36ahmed,

Questions are awesome, you can't learn new things without asking a few questions :)

  1. There should be nothing constraining you from using a subclass of a FamilyViewController in a Storyboard.

  2. I haven't tried setting up child view controllers with a storyboard + Family so I'm equally curious how would work but you should be able to have multiple view controllers and the corresponding views as subviews of your container view controller. However, you might have to supply size to your view controllers for Family to know how to lay out the views on screen. We are doing some investigation on how to remove the constraint on having to supply height and have the view controllers be self-sizing etc. You can always provide the size of the view controller inside the view controller itself. But like I said, there shouldn't be anything specific (that I know of) constraining you from using storyboards over writing your view controllers programmatically.

  3. All child view controllers will be deallocated when the container view controller gets pushed of the navigation stack as there is nothing retaining them in memory. Unless your own implementation prevents it or an unknown bug in the framework.

Hope that answers your questions, curious to know how it goes, best of luck!

Cheers!

@h36ahmed
Copy link
Author

h36ahmed commented Dec 29, 2018

Thank you for replying. All are great answers! for 2nd question, is it possible for you guys to implement a similar function as below if you create view controller in storyboard:

private func loadInitialControllerInVideoInfoContainerView(controller: UIViewController) {
        controller.view.translatesAutoresizingMaskIntoConstraints = false
        addChild(controller)
        addSubview(subView: controller.view, toView: videoInfoContainerView)
        controller.view.layoutIfNeeded()
        controller.didMove(toParent: self)
}
internal func addSubview(subView: UIView, toView parentView: UIView) {
        view.layoutIfNeeded()
        parentView.addSubview(subView)
        subView.leadingAnchor.constraint(equalTo: parentView.leadingAnchor).isActive = true
        subView.topAnchor.constraint(equalTo: parentView.topAnchor).isActive = true
        subView.bottomAnchor.constraint(equalTo: parentView.bottomAnchor).isActive = true
        subView.trailingAnchor.constraint(equalTo: parentView.trailingAnchor).isActive  = true
}

What essentially I am doing is having a view in storyboard and then adding view of my child controller inside the view that i constrained in storyboard. This way the autolayout takes care of different screen sizes. If I were to use your library, I have to supply static height which would not be ideal for different screen sizes, right?

@h36ahmed
Copy link
Author

So having an extra parameter, containerView on the function addChild would be a great addition.

@zenangst
Copy link
Owner

Hey @h36ahmed, you should already have these kinds of methods on FamilyViewController.
addChild pretty much does what loadInitialControllerInVideoInfoContainerView is doing.

https://github.com/zenangst/Family/blob/master/Sources/iOS%2BtvOS/Classes/FamilyViewController.swift#L64

As for addSubview, you shouldn't have to constrain your views to the parent view as the layout is handled using FamilyScrollView's layout algorithm that you can find here: https://github.com/zenangst/Family/blob/master/Sources/iOS/FamilyScrollView%2BiOS.swift#L4

The algorithm works in different ways for different types of views. If you have a class that inherits from scroll view, then the content size of the scroll view will determine the height of the view and render it correctly in linear-order. If the content size is larger than the viewport, the size of the view will never exceed it but rather scroll the scroll view by proxy to retain proper dequeuing for table and collection views. Views that don't have a content size will use the view's frame as the source of truth to know what height to use. So the container view controller does not have to know how large the view should be and will respond to updates to those frames using observers.

Using different sizes on different phone sizes (at least for widths and so on) will be handled by the parent giving the children their sizes, and the parent uses auto layout constraints.

Would you mind making an example project and point me in the right direction so that I can grasp the current situation more clearly, then I might be able to come up with a feasible solution to the issue.

Also, pull requests for adding new functionality is always welcome, as long as the changes are inline with the direction of the project.

Cheers!

@zenangst
Copy link
Owner

zenangst commented Jan 5, 2019

@h36ahmed ping pong 🏓

@zenangst
Copy link
Owner

@h36ahmed any updates here?

@zenangst
Copy link
Owner

Closing this due to lack of activity. Feel free to re-open the issue if it is still relevant later.

@h36ahmed
Copy link
Author

Hey man, sorry for the late reply, been busy but I have used a custom solution for now that works but I am sure if I were to use your library, it would be far more simple. But thanks for replying!

@zenangst zenangst added the question Further information is requested label Oct 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants