FLEXArgumentInputNumberView.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // FLEXArgumentInputNumberView.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 6/15/14.
  6. // Copyright (c) 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXArgumentInputNumberView.h"
  9. #import "FLEXRuntimeUtility.h"
  10. @implementation FLEXArgumentInputNumberView
  11. - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding {
  12. self = [super initWithArgumentTypeEncoding:typeEncoding];
  13. if (self) {
  14. self.inputTextView.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  15. self.targetSize = FLEXArgumentInputViewSizeSmall;
  16. }
  17. return self;
  18. }
  19. - (void)setInputValue:(id)inputValue {
  20. if ([inputValue respondsToSelector:@selector(stringValue)]) {
  21. self.inputTextView.text = [inputValue stringValue];
  22. }
  23. }
  24. - (id)inputValue {
  25. return [FLEXRuntimeUtility valueForNumberWithObjCType:self.typeEncoding.UTF8String fromInputString:self.inputTextView.text];
  26. }
  27. + (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value {
  28. NSParameterAssert(type);
  29. static NSArray<NSString *> *supportedTypes = nil;
  30. static dispatch_once_t onceToken;
  31. dispatch_once(&onceToken, ^{
  32. supportedTypes = @[
  33. @FLEXEncodeClass(NSNumber),
  34. @FLEXEncodeClass(NSDecimalNumber),
  35. @(@encode(char)),
  36. @(@encode(int)),
  37. @(@encode(short)),
  38. @(@encode(long)),
  39. @(@encode(long long)),
  40. @(@encode(unsigned char)),
  41. @(@encode(unsigned int)),
  42. @(@encode(unsigned short)),
  43. @(@encode(unsigned long)),
  44. @(@encode(unsigned long long)),
  45. @(@encode(float)),
  46. @(@encode(double)),
  47. @(@encode(long double))
  48. ];
  49. });
  50. return type && [supportedTypes containsObject:@(type)];
  51. }
  52. @end