FHSViewSnapshot.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // FHSViewSnapshot.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 1/9/20.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FHSViewSnapshot.h"
  9. #import "NSArray+FLEX.h"
  10. @implementation FHSViewSnapshot
  11. + (instancetype)snapshotWithView:(FHSView *)view {
  12. NSArray *children = [view.children flex_mapped:^id(FHSView *v, NSUInteger idx) {
  13. return [self snapshotWithView:v];
  14. }];
  15. return [[self alloc] initWithView:view children:children];
  16. }
  17. - (id)initWithView:(FHSView *)view children:(NSArray<FHSViewSnapshot *> *)children {
  18. NSParameterAssert(view); NSParameterAssert(children);
  19. self = [super init];
  20. if (self) {
  21. _view = view;
  22. _title = view.title;
  23. _important = view.important;
  24. _frame = view.frame;
  25. _hidden = view.hidden;
  26. _snapshotImage = view.snapshotImage;
  27. _children = children;
  28. _summary = view.summary;
  29. }
  30. return self;
  31. }
  32. - (UIColor *)headerColor {
  33. if (self.important) {
  34. return [UIColor colorWithRed: 0.000 green: 0.533 blue: 1.000 alpha: 0.900];
  35. } else {
  36. return [UIColor colorWithRed:0.961 green: 0.651 blue: 0.137 alpha: 0.900];
  37. }
  38. }
  39. - (FHSViewSnapshot *)snapshotForView:(UIView *)view {
  40. if (view == self.view.view) {
  41. return self;
  42. }
  43. for (FHSViewSnapshot *child in self.children) {
  44. FHSViewSnapshot *snapshot = [child snapshotForView:view];
  45. if (snapshot) {
  46. return snapshot;
  47. }
  48. }
  49. return nil;
  50. }
  51. @end