Skip to content

Commit

Permalink
Add empty ASViewController initializer to facilitate subclassing (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianselig authored and jparise committed Jan 3, 2020
1 parent 361aa5b commit 80ffcdf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Source/ASViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(C
*/
- (instancetype)initWithNode:(DisplayNodeType)node NS_DESIGNATED_INITIALIZER;

/**
* ASViewController initializer. Useful for interoperability with normal UIViewControllers.
*
* @return An ASViewController instance with a nil node whose root view will be backed by a standard UIView as with a normal UIViewController.
*
* @see ASVisibilityDepth
*/
- (instancetype)init NS_DESIGNATED_INITIALIZER;

NS_ASSUME_NONNULL_END

/**
Expand Down
11 changes: 11 additions & 0 deletions Source/ASViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ - (instancetype)initWithNode:(ASDisplayNode *)node
return self;
}

- (instancetype)init
{
if (!(self = [super initWithNibName:nil bundle:nil])) {
return nil;
}

[self _initializeInstance];

return self;
}

- (void)_initializeInstance
{
if (_node == nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ViewController: ASViewController<ASCollectionNode>, MosaicCollectionViewLa
let _layoutInspector = MosaicCollectionViewLayoutInspector()
let kNumberOfImages: UInt = 14

init() {
override init() {
let layout = MosaicCollectionViewLayout()
layout.numberOfColumns = 3;
layout.headerHeight = 44;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OverviewViewController: ASViewController<ASTableNode> {
let tableNode = ASTableNode()
let layoutExamples: [LayoutExampleNode.Type]

init() {
override init() {
layoutExamples = [
HeaderWithRightAndLeftItems.self,
PhotoWithInsetTextOverlay.self,
Expand Down
2 changes: 1 addition & 1 deletion examples/Swift/Sample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ViewController: ASViewController<ASDisplayNode>, ASTableDataSource,

fileprivate(set) var state: State = .empty

init() {
override init() {
super.init(node: ASTableNode())
tableNode.delegate = self
tableNode.dataSource = self
Expand Down

0 comments on commit 80ffcdf

Please sign in to comment.