ASViewController.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // ASViewController.h
  3. // AsyncDisplayKit
  4. //
  5. // Created by Huy Nguyen on 16/09/15.
  6. //
  7. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8. // This source code is licensed under the BSD-style license found in the
  9. // LICENSE file in the root directory of this source tree. An additional grant
  10. // of patent rights can be found in the PATENTS file in the same directory.
  11. //
  12. #import <UIKit/UIKit.h>
  13. #import <AsyncDisplayKit/ASDisplayNode.h>
  14. #import <AsyncDisplayKit/ASVisibilityProtocols.h>
  15. @class ASTraitCollection;
  16. NS_ASSUME_NONNULL_BEGIN
  17. typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitCollectionBlock)(UITraitCollection *traitCollection);
  18. typedef ASTraitCollection * _Nonnull (^ASDisplayTraitsForTraitWindowSizeBlock)(CGSize windowSize);
  19. /**
  20. * ASViewController allows you to have a completely node backed hierarchy. It automatically
  21. * handles @c ASVisibilityDepth, automatic range mode and propogating @c ASDisplayTraits to contained nodes.
  22. *
  23. * You can opt-out of node backed hierarchy and use it like a normal UIViewController.
  24. * 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.
  25. * See examples/ASDKgram project for actual implementation.
  26. */
  27. @interface ASViewController<__covariant DisplayNodeType : ASDisplayNode *> : UIViewController <ASVisibilityDepth>
  28. /**
  29. * ASViewController initializer.
  30. *
  31. * @param node An ASDisplayNode which will provide the root view (self.view)
  32. * @return An ASViewController instance whose root view will be backed by the provided ASDisplayNode.
  33. *
  34. * @see ASVisibilityDepth
  35. */
  36. - (instancetype)initWithNode:(DisplayNodeType)node;
  37. NS_ASSUME_NONNULL_END
  38. /**
  39. * @return node Returns the ASDisplayNode which provides the backing view to the view controller.
  40. */
  41. @property (nonatomic, strong, readonly, null_unspecified) DisplayNodeType node;
  42. NS_ASSUME_NONNULL_BEGIN
  43. /**
  44. * Set this block to customize the ASDisplayTraits returned when the VC transitions to the given traitCollection.
  45. */
  46. @property (nonatomic, copy) ASDisplayTraitsForTraitCollectionBlock overrideDisplayTraitsWithTraitCollection;
  47. /**
  48. * Set this block to customize the ASDisplayTraits returned when the VC transitions to the given window size.
  49. */
  50. @property (nonatomic, copy) ASDisplayTraitsForTraitWindowSizeBlock overrideDisplayTraitsWithWindowSize;
  51. /**
  52. * @abstract Passthrough property to the the .interfaceState of the node.
  53. * @return The current ASInterfaceState of the node, indicating whether it is visible and other situational properties.
  54. * @see ASInterfaceState
  55. */
  56. @property (nonatomic, readonly) ASInterfaceState interfaceState;
  57. // AsyncDisplayKit 2.0 BETA: This property is still being tested, but it allows
  58. // blocking as a view controller becomes visible to ensure no placeholders flash onscreen.
  59. // Refer to examples/SynchronousConcurrency, AsyncViewController.m
  60. @property (nonatomic, assign) BOOL neverShowPlaceholders;
  61. @end
  62. @interface ASViewController (ASRangeControllerUpdateRangeProtocol)
  63. /**
  64. * Automatically adjust range mode based on view events. If you set this to YES, the view controller or its node
  65. * must conform to the ASRangeControllerUpdateRangeProtocol.
  66. *
  67. * Default value is YES *if* node or view controller conform to ASRangeControllerUpdateRangeProtocol otherwise it is NO.
  68. */
  69. @property (nonatomic, assign) BOOL automaticallyAdjustRangeModeBasedOnViewEvents;
  70. @end
  71. @interface ASViewController (Deprecated)
  72. /**
  73. * The constrained size used to measure the backing node.
  74. *
  75. * @discussion Defaults to providing a size range that uses the view controller view's bounds as
  76. * both the min and max definitions. Override this method to provide a custom size range to the
  77. * backing node.
  78. */
  79. - (ASSizeRange)nodeConstrainedSize AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Set the size directly to the view's frame");
  80. @end
  81. NS_ASSUME_NONNULL_END