• This repository has been archived on 05/Jan/2024
  • Stars
    star
    644
  • Rank 67,213 (Top 2 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A view controller that uses root views of child view controllers as views in a UIStackView.

ScrollingStackViewController Banner

Warning: This library is not supported by Just Eat Takeaway anymore and therefore considered deprecated. The repository has been archived.

ScrollingStackViewController

Build Status Version License Platform

ScrollingStackViewController is a convenient replacement for the UITableViewController more suitable in situations when you're building a scrolling controller with a limited number or dynamic and rich "cells".

Motivation

UITableViewController is great for situations when we want to display an arbitrary (possibly large) number of relatively simple cells. Sometimes however you just want to partition your view controller into vertically laid out segments. The segments are probably highly heterogenous, complex, their number is well defined, but you still want to be able to show and hide them depending on the situation. You can achieve that with a UITableViewController, but it gets a litte awkward:

  • The Data Source pattern is an overkill here. You might as well just add your segments directly and hide/show them without having to go through cellForRow:at:, table view updates, etc. Juggling indexes when you want to show and hide different cells tends to be bug and crash prone and sometimes difficult to animate nicely. You probably don't care for cell reuse in this case, so the advantages of delegation are missing here.
  • It's difficult to partition the code well. UITableViewCell belongs in the View layer, so you either have to keep the Controller parts in your containing view controller in which case you haven't partioned the Controller layer, or you have to pervert UITableViewCell and stick Controller code there. In either case--not a win.

The solution to the above that ScrollingStackViewController provides is to use child view controllers that can honestly keep their own Controller code while using UIStackView to deal with the layout and UIScrollView for scrolling. It's a simple class that provides all of the scaffolding and aims to deal with all of the UIKit quirks that it likes to throw at you.

ScrollingStackViewController Demo

We invite you to check the Order Details page in the Just Eat UK app where each segment is a child view controller, making the such page a perfect use case for using ScrollingStackViewController. The containing view controller only needs to know how to instantiate, initialise, and add the child controllers.

Usage

Inherit from ScrollingStackViewController. Instantiate and add your child view controllers. Make sure your child view controllers have constraints to self-size vertically.

class ViewController: ScrollingStackViewController {
    
    var viewController1: UIViewController!
    var viewController2: UIViewController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
            
        viewController1 = storyboard.instantiateViewController(withIdentifier: "ChildController1") as! ChildController1
        viewController2 = storyboard.instantiateViewController(withIdentifier: "ChildController2") as! ChildController2
        
        add(viewController: viewController1)
        add(viewController: viewController2)            
    }
}

Insert a child view controller at position.

insert(viewController: viewController3, at: .index(1))

Insert a child view controller with padding (child view is added to a container view). NB: When a child view is added to a padding container view, the show/hide functions should be used.

insert(viewController: viewController4,
           edgeInsets: UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8),
                   at: .after(viewController3))

Remove a child view controller. NB: Might be easier to just add all VCs you were planning to use and then just show and hide them as needed. See below.

remove(viewController: viewController3)

Show and hide the view controllers using show(viewController:) and hide(viewController:). The transition animates.

show(viewController: viewController1)

The default is a spring animation with 0.5 duration and 1 damping. You can override the default animation closure.

animate = { animations, completion in
    UIView.animate(withDuration: 1, animations: animations, completion: completion)
}

Add spacing.

spacingColor = UIColor.lightGray
stackView.spacing = 0.5

Add border.

borderColor = UIColor.darkGray
borderWidth = 1

Programatically scroll to child view controller.

scrollTo(viewController: viewController2, action: { print("Done scrolling!") })

Override scroll animation.

scrollAnimate = { animations, completion in
    UIView.animate(withDuration: 1, animations: animations, completion: completion)
}

You still have access to the stack view, scroll view, and the background view that back the view controller if you need to do something that's not covered quickly.

scrollView.alwaysBounceVertical = false
stackView.spacing = 1
stackViewBackgroundView.alpha = 0

Requirements

ScrollingStackViewController requires iOS 12 or higher.

Installation

CocoaPods

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

pod "ScrollingStackViewController"

Swift Package Manager

ScrollingStackViewController is also available through SPM. Copy the URL for this repo, and add the package in your project settings.

License

ScrollingStackViewController is available under the Apache License Version 2.0, January 2004. See the LICENSE file for more info.

  • Just Eat iOS team

More Repositories

1

JustLog

JustLog brings logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support for logz.io available.
Swift
517
star
2

httpclient-interception

A .NET library for intercepting server-side HTTP requests
C#
246
star
3

JustTweak

JustTweak is a feature flagging framework for iOS apps.
Swift
203
star
4

JustPersist

JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box. It also allows you to migrate to any other persistence framework with minimal effort.
Swift
164
star
5

NavigationEngineDemo

A scalable and robust solution to navigation, deep linking and universal links on iOS ๐Ÿš€
Swift
125
star
6

Shock

A HTTP mocking framework written in Swift.
Swift
98
star
7

JustPeek

JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop interactions on devices that do not natively support this kind of interaction.
Shell
69
star
8

Topshelf.Nancy

Nancy endpoint for the Topshelf service host providing additional support around URL reservations. โ€” Edit
C#
65
star
9

ZendeskApiClient

C#ย Client for working with the Zendesk API
C#
62
star
10

JustEat.RecruitmentTest

The recruitment test to apply for an engineering role at Just Eat
Scala
62
star
11

AutomationTools

iOS UI testing framework and guidelines
Swift
53
star
12

NLog.StructuredLogging.Json

Structured logging for NLog using Json (formerly known as JsonFields)
C#
51
star
13

JustTrack

The Just Eat solution to better manage the analytics tracking and improve the relationship with your BI team.
Swift
41
star
14

JustFakeIt

HTTP server faking library
C#
31
star
15

jubako

A small API to help display rich content in a RecyclerView such as a wall of carousels
Kotlin
30
star
16

JustSaying

A light-weight message bus on top of AWS services (SNS and SQS).
C#
30
star
17

PRAssigner

Swift AWS Lambda to automatically assign engineers to pull requests with a Slack integration
Swift
29
star
18

JustBehave

A BDD-influenced C# testing library cooked up by Just Eat
C#
29
star
19

ApplePayJSSample

A sample implementation of Apple Pay JS using ASP.NET Core
C#
23
star
20

kongverge

A desired state configuration tool for Kong
C#
23
star
21

ProcessManager

C#
21
star
22

Android.Samples.Deeplinks

Sample app demonstrating an effective and unit-testable way to handle deep links in Android
Java
20
star
23

JustEat.StatsD

Our library for publishing metrics to statsd
C#
19
star
24

iOS.ErrorUtilities

Just Eat collection of iOS error-related utilities
Swift
19
star
25

JustSupport

JavaScript
18
star
26

AwsWatchman

Because unmonitored infrastructure will bite you
C#
17
star
27

fozzie-components

JavaScript
13
star
28

kubernetes-windows-aws-ovs

Kubernetes on windows in aws using ovn
HCL
13
star
29

applepayjs-polyfill

A polyfill for the Apple Pay JS for use in non-supported browsers
JavaScript
12
star
30

fozzie

Web UI Base Library
SCSS
12
star
31

LocalDynamoDb

C#
11
star
32

JE.IdentityServer.Security

Recaptcha for OpenIdConnect
C#
7
star
33

JustEat.Recruitment.UI

UI Test for interview candidates
7
star
34

OpenRastaSwagger

Swagger / Swagger-UI implementation for OpenRasta
JavaScript
7
star
35

ts-jsonschema-builder

Fluent TypeScript JSON Schema builder.
TypeScript
6
star
36

JustEat.InfoSecRecruitmentTest

C#
4
star
37

gulp-build-fozzie

Gulp build tasks for use across Fozzie modules
JavaScript
4
star
38

JustEat.CWA.RecruitmentTest

Consumer Web Applications recruitment test for roles at JUST EAT
4
star
39

AngularJSWebAPI.Experiment

HTML
3
star
40

JE.EmbeddedChecks

Micro-framework for embedding checks inside applications, so they tell you when they're healthy and how.
C#
3
star
41

JE.TurningPages

C#
3
star
42

JE.ApiValidation

API validation helpers - A standard error response contract and FluentValidation support in .NET web frameworks
C#
3
star
43

JE.ApiExceptions

C#
2
star
44

f-footer

Common footer component for Just Eat websites
SCSS
2
star
45

JustEat.EntryLevel.RecruitmentTest

Recruitment Test for Entry Level Engineers
2
star
46

global-component-library

Global Component Library and Documentation for sharing across UK and International
CSS
2
star
47

f-templates

Locate, compile, and serve HTML from templates.
JavaScript
1
star
48

f-dom

Fozzie JS DOM queries library.
JavaScript
1
star
49

f-toggle

Fozzie vanilla JS toggle library.
JavaScript
1
star
50

PowerShellDSCUtils

Just Eat PowerShell DSC Utilities
PowerShell
1
star
51

f-header

Common header component for Just Eat websites
JavaScript
1
star
52

f-recruit-message

Adds a recruitment message to the browser console
JavaScript
1
star
53

ruby_bootcamp

Code samples for ruby bootcamp show & tells
Ruby
1
star
54

f-serviceworker

JavaScript
1
star
55

mickeydb

Android sqlite db super tool, for migrations and data access code generation
Java
1
star
56

f-copy-assets

NPM package to copy assets from node_modules to a specified directory
JavaScript
1
star
57

JustEat.PublicApi.TestApp

JavaScript
1
star
58

browserslist-config-fozzie

Just Eat's Browserslist Config used in UI packages
JavaScript
1
star
59

openrasta-hosting-owin

OWIN host for OpenRasta
C#
1
star