2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.4 KiB

  1. //
  2. // SCFeatureCoordinator.m
  3. // SCCamera
  4. //
  5. // Created by Kristian Bauer on 1/4/18.
  6. //
  7. #import "SCFeatureCoordinator.h"
  8. #import "SCFeature.h"
  9. #import "SCFeatureProvider.h"
  10. #import <SCFoundation/SCAssertWrapper.h>
  11. #import <SCFoundation/SCTraceODPCompatible.h>
  12. typedef NSString SCFeatureDictionaryKey;
  13. @interface SCFeatureCoordinator ()
  14. @property (nonatomic, weak) UIView<SCFeatureContainerView> *containerView;
  15. @property (nonatomic, strong) id<SCFeatureProvider> provider;
  16. @end
  17. @implementation SCFeatureCoordinator
  18. - (instancetype)initWithFeatureContainerView:(UIView<SCFeatureContainerView> *)containerView
  19. provider:(id<SCFeatureProvider>)provider
  20. {
  21. SCTraceODPCompatibleStart(2);
  22. SCAssert(containerView, @"SCFeatureCoordinator containerView must be non-nil");
  23. SCAssert(provider, @"SCFeatureCoordinator provider must be non-nil");
  24. self = [super init];
  25. if (self) {
  26. _containerView = containerView;
  27. _provider = provider;
  28. [self reloadFeatures];
  29. }
  30. return self;
  31. }
  32. - (void)reloadFeatures
  33. {
  34. SCTraceODPCompatibleStart(2);
  35. [_provider resetInstances];
  36. NSMutableArray *features = [NSMutableArray array];
  37. for (id<SCFeature> feature in _provider.supportedFeatures) {
  38. if ([feature respondsToSelector:@selector(configureWithView:)]) {
  39. [feature configureWithView:_containerView];
  40. }
  41. if (feature) {
  42. [features addObject:feature];
  43. }
  44. }
  45. }
  46. - (void)forwardCameraTimerGesture:(UIGestureRecognizer *)gestureRecognizer
  47. {
  48. SCTraceODPCompatibleStart(2);
  49. for (id<SCFeature> feature in _provider.supportedFeatures) {
  50. if ([feature respondsToSelector:@selector(forwardCameraTimerGesture:)]) {
  51. [feature forwardCameraTimerGesture:gestureRecognizer];
  52. }
  53. }
  54. }
  55. - (void)forwardCameraOverlayTapGesture:(UIGestureRecognizer *)gestureRecognizer
  56. {
  57. SCTraceODPCompatibleStart(2);
  58. for (id<SCFeature> feature in _provider.supportedFeatures) {
  59. if ([feature respondsToSelector:@selector(forwardCameraOverlayTapGesture:)]) {
  60. [feature forwardCameraOverlayTapGesture:gestureRecognizer];
  61. }
  62. }
  63. }
  64. - (void)forwardLongPressGesture:(UIGestureRecognizer *)gestureRecognizer
  65. {
  66. SCTraceODPCompatibleStart(2);
  67. for (id<SCFeature> feature in _provider.supportedFeatures) {
  68. if ([feature respondsToSelector:@selector(forwardLongPressGesture:)]) {
  69. [feature forwardLongPressGesture:gestureRecognizer];
  70. }
  71. }
  72. }
  73. - (void)forwardPinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer
  74. {
  75. SCTraceODPCompatibleStart(2);
  76. for (id<SCFeature> feature in _provider.supportedFeatures) {
  77. if ([feature respondsToSelector:@selector(forwardPinchGesture:)]) {
  78. [feature forwardPinchGesture:gestureRecognizer];
  79. }
  80. }
  81. }
  82. - (void)forwardPanGesture:(UIPanGestureRecognizer *)gestureRecognizer
  83. {
  84. SCTraceODPCompatibleStart(2);
  85. for (id<SCFeature> feature in _provider.supportedFeatures) {
  86. if ([feature respondsToSelector:@selector(forwardPanGesture:)]) {
  87. [feature forwardPanGesture:gestureRecognizer];
  88. }
  89. }
  90. }
  91. - (BOOL)shouldBlockTouchAtPoint:(CGPoint)point
  92. {
  93. SCTraceODPCompatibleStart(2);
  94. for (id<SCFeature> feature in _provider.supportedFeatures) {
  95. if ([feature respondsToSelector:@selector(shouldBlockTouchAtPoint:)] &&
  96. [feature shouldBlockTouchAtPoint:point]) {
  97. return YES;
  98. }
  99. }
  100. return NO;
  101. }
  102. @end