123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //
- // FLEXArgumentInputNumberView.m
- // Flipboard
- //
- // Created by Ryan Olson on 6/15/14.
- // Copyright (c) 2020 FLEX Team. All rights reserved.
- //
- #import "FLEXArgumentInputNumberView.h"
- #import "FLEXRuntimeUtility.h"
- @implementation FLEXArgumentInputNumberView
- - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding {
- self = [super initWithArgumentTypeEncoding:typeEncoding];
- if (self) {
- self.inputTextView.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
- self.targetSize = FLEXArgumentInputViewSizeSmall;
- }
-
- return self;
- }
- - (void)setInputValue:(id)inputValue {
- if ([inputValue respondsToSelector:@selector(stringValue)]) {
- self.inputTextView.text = [inputValue stringValue];
- }
- }
- - (id)inputValue {
- return [FLEXRuntimeUtility valueForNumberWithObjCType:self.typeEncoding.UTF8String fromInputString:self.inputTextView.text];
- }
- + (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value {
- NSParameterAssert(type);
-
- static NSArray<NSString *> *supportedTypes = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- supportedTypes = @[
- @FLEXEncodeClass(NSNumber),
- @FLEXEncodeClass(NSDecimalNumber),
- @(@encode(char)),
- @(@encode(int)),
- @(@encode(short)),
- @(@encode(long)),
- @(@encode(long long)),
- @(@encode(unsigned char)),
- @(@encode(unsigned int)),
- @(@encode(unsigned short)),
- @(@encode(unsigned long)),
- @(@encode(unsigned long long)),
- @(@encode(float)),
- @(@encode(double)),
- @(@encode(long double))
- ];
- });
-
- return type && [supportedTypes containsObject:@(type)];
- }
- @end
|