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

🚸 A child view controller framework that makes setting up your parent controllers as easy as pie.

License

Notifications You must be signed in to change notification settings

zenangst/Family

Repository files navigation

Family logo

CI Status Version Carthage Compatible codecov License Platform Swift

Description

Family Icon

Family is a child view controller framework that makes setting up your parent controllers as easy as pie. With a simple yet powerful public API, you can build complex layouts without losing maintainability, leaving you to focus on what matters: making your applications pop and your business logic shine.

This framework was built to make it easier to build and maintain parent controllers, also known as flow controllers. Using child view controllers can make your code more modular, flexible and testable. It addresses one of the biggest shortcomings of the vanilla approach: how do you get a continuous scrolling experience while keeping dequeuing intact?

This is where Family framework comes in. With the help of its layout algorithm, all your regular- and scroll views get stacked in the same linear vertical order you add them to the hierarchy. To achieve a continuous scrolling view, your child scroll views no longer scroll themselves, but get their new content offset passed to them by the parent scroll view, which the framework handles for you. The framework also modifies the views' frames on the fly, constraining the height to the window.

The story behind Family

If you are interested in the origin story behind Family, then you can read this Medium article.

Features

  • 🍩Animation support.
  • 🤳🏻Continuous scrolling with multiple scroll views.
  • 📏Margins between child view controllers.
  • 🌀Table view and collection view dequeuing.
  • 🍭Supports custom spacing between views.
  • 📱iOS support.
  • 💻macOS support.
  • 📺tvOS support.

Supporting the project

If you want to support the development of this framework, you can do so by becoming a sponsor. ❤️

Usage

The new public API:

body(withDuration: 0) {
  add(detailViewController)
  .background(.view(backgroundView))
  .padding(.init(top: 20, left: 20, bottom: 20, right: 20))
  .margin(.init(top: 20, left: 0, bottom: 20, right: 0))
}

Add a regular child view controller:

let familyController = FamilyViewController()
let viewController = UIViewController()

familyController.addChild(viewController)

Add a child view controller constrained by height:

let familyController = FamilyViewController()
let viewController = UIViewController()

familyController.addChild(viewController, height: 175)

Add a child view controller with a custom view on the controller:

let familyController = FamilyViewController()
let customController = CustomViewController()

// This will add the scroll view of the custom controller
// instead of the controllers view.
familyController.addChild(customController, view: { $0.scrollView })

Move a view controller:

familyController.moveChild(customController, to: 1)

Perform batch updates (it is encouraged to use performBatchUpdates when updaing more than one view controller):

familyController.performBatchUpdates({ controller in
  controller.addChild(controller1)
  controller.addChild(controller2)
  controller.moveChild(controller2, to: 0)
  controller3.removeFromParent()
})

Adding animations

When adding animations, not that you have to give them a key.

let basicAnimation = CABasicAnimation()
basicAnimation.duration = 0.5
controller.view.layer.add(springAnimation, forKey: "Basic Animations")

let springAnimation = CASpringAnimation()
springAnimation.damping = 0.6
springAnimation.initialVelocity = 0.6
springAnimation.mass = 0.4
springAnimation.duration = 0.6
springAnimation.isRemovedOnCompletion = false
controller.view.layer.add(springAnimation, forKey: "Spring Animations")

Installation

Family is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Family'

and then run

pod install

Family is also available through Carthage. To install just write into your Cartfile:

github "zenangst/Family"

and then run

carthage install

When it's finished, install the built framework (which can be found in the Carthage/Build folder) into your Xcode project.

Family can also be installed manually. Just download and drop Sources folders in your project.

Author

Christoffer Winterkvist, christoffer@winterkvist.com

Contributing

We would love you to contribute to Family, check the CONTRIBUTING file for more info.

Credits

License

Family is available under the MIT license. See the LICENSE file for more info.

About

🚸 A child view controller framework that makes setting up your parent controllers as easy as pie.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages