Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty ASViewController initializer to facilitate subclassing #1754

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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