fakes.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // fakes.h
  3. // FLEX
  4. //
  5. // Created by Kevin Bradley on 12/22/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #import "fakes.h"
  9. #import "NSObject+FLEX_Reflection.h"
  10. @interface UIImage (private)
  11. +(UIImage *)symbolImageNamed:(NSString *)symbolName;
  12. @end
  13. @interface KBSearchButton()
  14. @property UITextField *searchField; //helps us get a keyboard onscreen and acts as a proxy to move text to our UISearchBar
  15. @end
  16. @implementation KBSearchButton
  17. + (instancetype)buttonWithType:(UIButtonType)buttonType {
  18. KBSearchButton *button = [super buttonWithType:buttonType];
  19. [button setImage:[UIImage symbolImageNamed:@"magnifyingglass"] forState:UIControlStateNormal];
  20. button.frame = CGRectMake(0, 0, 150, 70);
  21. UITextField *tf = [[UITextField alloc]init];
  22. tf.clearButtonMode = UITextFieldViewModeAlways;
  23. button.searchField = tf;
  24. tf.delegate = button;
  25. [button addSubview:tf];
  26. [button addTarget:button action:@selector(triggerSearchField) forControlEvents:UIControlEventPrimaryActionTriggered];
  27. [button addListeners];
  28. return button;
  29. }
  30. - (void)textChanged:(NSNotification *)n {
  31. self.searchBar.text = self.searchField.text;
  32. }
  33. - (void)addListeners {
  34. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextFieldTextDidChangeNotification object:nil];
  35. }
  36. - (void)dealloc {
  37. [[NSNotificationCenter defaultCenter] removeObserver:self];
  38. }
  39. - (void)triggerSearchField {
  40. self.searchField.text = self.searchBar.text;
  41. //[self.searchBar becomeFirstResponder];
  42. [self.searchField becomeFirstResponder];
  43. //wait for 0.1 seconds and then decrease the opacity of UISystemInputViewController presenting our UIKeyboard
  44. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  45. UIViewController *vc = [self topViewController];
  46. vc.view.alpha = 0.6;
  47. });
  48. }
  49. @end
  50. @interface UIFakeSwitch() {
  51. BOOL _isOn;
  52. }
  53. @end
  54. @implementation UIFakeSwitch
  55. - (BOOL)isOn {
  56. return _isOn;
  57. }
  58. - (void)setOn:(BOOL)on{
  59. [self setOn:on animated:true];
  60. }
  61. - (NSString *)onTitle {
  62. return @"TRUE";
  63. }
  64. - (NSString *)offTitle {
  65. return @"FALSE";
  66. }
  67. - (void)setOn:(BOOL)on animated:(BOOL)animated {
  68. _isOn = on;
  69. if (_isOn){
  70. [self setTitle:[self onTitle] forState:UIControlStateNormal];
  71. } else {
  72. [self setTitle:[self offTitle] forState:UIControlStateNormal];
  73. }
  74. //[self sendActionsForControlEvents:[self allControlEvents]];
  75. }
  76. + (id)newSwitch {
  77. return [UIFakeSwitch buttonWithType:UIButtonTypeSystem];
  78. }
  79. -(instancetype)initWithFrame:(CGRect)frame {
  80. return [super initWithFrame:frame];
  81. }
  82. - (instancetype)initWithCoder:(id)coder {
  83. return [super initWithCoder:coder];
  84. }
  85. @end
  86. @implementation UIFakeSlider
  87. - (void)setValue:(float)value animated:(BOOL)animated {
  88. }
  89. - (void)setThumbImage:(nullable UIImage *)image forState:(UIControlState)state {
  90. }
  91. - (void)setMinimumTrackImage:(nullable UIImage *)image forState:(UIControlState)state {
  92. }
  93. - (void)setMaximumTrackImage:(nullable UIImage *)image forState:(UIControlState)state {
  94. }
  95. - (nullable UIImage *)thumbImageForState:(UIControlState)state {
  96. return nil;
  97. }
  98. - (nullable UIImage *)minimumTrackImageForState:(UIControlState)state {
  99. return nil;
  100. }
  101. - (nullable UIImage *)maximumTrackImageForState:(UIControlState)state {
  102. return nil;
  103. }
  104. - (CGRect)minimumValueImageRectForBounds:(CGRect)bounds {
  105. return CGRectZero;
  106. }
  107. - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds {
  108. return CGRectZero;
  109. }
  110. - (CGRect)trackRectForBounds:(CGRect)bounds {
  111. return CGRectZero;
  112. }
  113. - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value {
  114. return CGRectZero;
  115. }
  116. @end