fakes.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. /*
  9. Feel like this class requires some documentation / commentary.
  10. there are a variaty of classes that are either forbidden or non-existant on tvOS. Initially to get things building
  11. to find out what i needed to fix outside of missing classes i figured i'd be easiet to stub out "fake' versions
  12. of the classes that responded to the bare minimum for API complaince to have them appear as empty elements
  13. rather than preventing building or creating crashes.
  14. */
  15. #import <UIKit/UIKit.h>
  16. #import "FLEXMacros.h"
  17. #import "KBSlider.h"
  18. #import "KBDatePickerView.h"
  19. /**
  20. PREFACE:
  21. Doing UISearchController integration on tvOS is a nightmare. as is ANY integration with the keyboard or having it presented to the end user.
  22. I made an attempt to get a more native UI/UX to tvOS for this part but couldn't wrap my head around a way to get it to work in a reasonable amount of time
  23. so i came up with this kludge to get search working in a reasonable sense as quickly as possible for tvOS.
  24. IMPLEMENTATION:
  25. This UIButton is added as the view of a UITabBarButtonItem as the left bar button item & there is a zero rect text field embedded in this button,
  26. this is the chicnary necessary to get a keyboard to appear reliably when the text field becomes the first responder.
  27. the drawback to this approach is the view appears in a mostly opaque and newly minted UISystemInputViewController with a UIKeyboard on it.
  28. to make this approach workable I wait for 0.1 seconds and then decrease the alpha value of the 'topViewController' which happens to be
  29. our UISystemInputViewController. this allows the user to see the changes update underneath the view while the search is executed!
  30. */
  31. /// some of the iOS versions of these values are at different indexes - reused the same names and just replaced UI->TV images of these are available in tvOSAccessoryImages
  32. typedef NS_ENUM(NSInteger, TVTableViewCellAccessoryType) {
  33. TVTableViewCellAccessoryNone,
  34. TVTableViewCellAccessoryDisclosureIndicator,
  35. TVTableViewCellAccessoryCheckmark = 3,
  36. TVTableViewCellAccessoryChevron = 5,
  37. TVTableViewCellAccessoryChevronOpen,
  38. TVTableViewCellAccessoryChevronDisclosureButton,
  39. TVTableViewCellAccessoryChevronOpenDisclosureButton,
  40. TVTableViewCellAccessoryDetailDisclosureButton = 10,
  41. TVTableViewCellAccessoryDetailButton = 12
  42. };
  43. @interface KBSearchButton: UIButton <UITextFieldDelegate>
  44. @property UISearchBar * _Nullable searchBar; //keep a reference to the search bar to add our text value to the search bar field immediately.
  45. - (void)triggerSearchField;
  46. @end
  47. //UIFakeSwitch is actually just a UIButton that says TRUE/FALSE and responds to UISwitch API calls.
  48. @interface UIFakeSwitch : UIButton <NSCoding>
  49. @property(nullable, nonatomic, strong) UIColor *onTintColor;
  50. @property(nullable, nonatomic, strong) UIColor *thumbTintColor;
  51. @property(nullable, nonatomic, strong) UIImage *onImage;
  52. @property(nullable, nonatomic, strong) UIImage *offImage;
  53. @property(nonatomic,getter=isOn) BOOL on;
  54. - (instancetype _Nonnull )initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER; // This class enforces a size appropriate for the control, and so the frame size is ignored.
  55. - (nullable instancetype)initWithCoder:(NSCoder *_Nonnull)coder NS_DESIGNATED_INITIALIZER;
  56. - (void)setOn:(BOOL)on animated:(BOOL)animated; // does not send action
  57. + (id _Nonnull )newSwitch;
  58. @end
  59. //Stub slider, any instances that still use this are only in the snapshot baesd views which dont work yet, this will be pruned once that update is made.
  60. @interface UIFakeSlider: UIControl <NSCoding>
  61. @property(nonatomic) float value;
  62. @property(nonatomic) float minimumValue;
  63. @property(nonatomic) float maximumValue;
  64. @property(nonatomic) float minValue;
  65. @property(nonatomic) float maxValue;
  66. @property(nonatomic) float allowedMinValue;
  67. @property(nonatomic) float allowedMaxValue;
  68. @property(nullable, nonatomic,strong) UIImage *minimumValueImage;
  69. @property(nullable, nonatomic,strong) UIImage *maximumValueImage;
  70. @property(nonatomic,getter=isContinuous) BOOL continuous;
  71. @property(nullable, nonatomic,strong) UIColor *minimumTrackTintColor;
  72. @property(nullable, nonatomic,strong) UIColor *maximumTrackTintColor;
  73. @property(nullable, nonatomic,strong) UIColor *thumbTintColor;
  74. - (void)setValue:(float)value animated:(BOOL)animated;
  75. - (void)setThumbImage:(nullable UIImage *)image forState:(UIControlState)state;
  76. - (void)setMinimumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
  77. - (void)setMaximumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
  78. - (nullable UIImage *)thumbImageForState:(UIControlState)state;
  79. - (nullable UIImage *)minimumTrackImageForState:(UIControlState)state;
  80. - (nullable UIImage *)maximumTrackImageForState:(UIControlState)state;
  81. @property(nullable,nonatomic,readonly) UIImage *currentThumbImage;
  82. @property(nullable,nonatomic,readonly) UIImage *currentMinimumTrackImage;
  83. @property(nullable,nonatomic,readonly) UIImage *currentMaximumTrackImage;
  84. // lets a subclass lay out the track and thumb as needed
  85. - (CGRect)minimumValueImageRectForBounds:(CGRect)bounds;
  86. - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds;
  87. - (CGRect)trackRectForBounds:(CGRect)bounds;
  88. - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value;
  89. @end