mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-30 18:00:34 +00:00
[ASViewController] Support optional node (#3021)
* ASViewController can be used without a node - If a node isn't provided by developers via -initWithNode:, a default one will be created and used internally. - This allows developers to use ASViewController like a normal UIViewController and as a base class for all view controllers among which some use a node hierarchy and some don't. * Update ASDKgram to use a shared base ASViewController * Minor fixes in ASViewController: - If its node isn't provided by users, don't replace the view controller's view with the default node's view because it might be loaded from a nib. - Init a vanilla ASDisplayNode if a node isn't provided. * Some smaller cleanup * Remove dummy node for ASViewController if it’s used without a node
This commit is contained in:
committed by
GitHub
parent
cd448a105e
commit
aecd36a4df
@@ -21,25 +21,34 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitCollectionBlock)(UITraitCollection *traitCollection);
|
||||
typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(CGSize windowSize);
|
||||
|
||||
/**
|
||||
* ASViewController allows you to have a completely node backed hierarchy. It automatically
|
||||
* handles @c ASVisibilityDepth, automatic range mode and propogating @c ASDisplayTraits to contained nodes.
|
||||
*
|
||||
* You can opt-out of node backed hierarchy and use it like a normal UIViewController.
|
||||
* More importantly, you can use it as a base class for all of your view controllers among which some use a node hierarchy and some don't.
|
||||
* See examples/ASDKgram project for actual implementation.
|
||||
*/
|
||||
@interface ASViewController<__covariant DisplayNodeType : ASDisplayNode *> : UIViewController <ASVisibilityDepth>
|
||||
|
||||
/**
|
||||
* ASViewController Designated initializer.
|
||||
*
|
||||
* @discussion ASViewController allows you to have a completely node backed heirarchy. It automatically
|
||||
* handles @c ASVisibilityDepth, automatic range mode and propogating @c ASDisplayTraits to contained nodes.
|
||||
* ASViewController initializer.
|
||||
*
|
||||
* @param node An ASDisplayNode which will provide the root view (self.view)
|
||||
* @return An ASViewController instance whose root view will be backed by the provided ASDisplayNode.
|
||||
*
|
||||
* @see ASVisibilityDepth
|
||||
*/
|
||||
- (instancetype)initWithNode:(DisplayNodeType)node NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithNode:(DisplayNodeType)node;
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
/**
|
||||
* @return node Returns the ASDisplayNode which provides the backing view to the view controller.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) DisplayNodeType node;
|
||||
@property (nonatomic, strong, readonly, null_unspecified) DisplayNodeType node;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* Set this block to customize the ASDisplayTraits returned when the VC transitions to the given traitCollection.
|
||||
@@ -91,12 +100,4 @@ typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(C
|
||||
|
||||
@end
|
||||
|
||||
@interface ASViewController (Unavailable)
|
||||
|
||||
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil AS_UNAVAILABLE("ASViewController requires using -initWithNode:");
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder AS_UNAVAILABLE("ASViewController requires using -initWithNode:");
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
Reference in New Issue
Block a user