Workaround[dynamic position]: replace dp: and px: calls with direct find-and-replace
Certain iOS versions don't like when expression tries to call either dp: or px:
This commit is contained in:
1 parent
d6fd6e1f10
commit
54fb8a346d
2 files changed
+18
No files matched your search
@@ -96,6 +96,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)processFunctions:(NSString *)string {
|
||||
NSString *tmpStr;
|
||||
CGFloat screenScale = UIScreen.mainScreen.scale;
|
||||
|
||||
// FIXME: on certain iOS versions, we cannot invoke dp: and px: in _NSPredicateUtilities
|
||||
// we gotta do direct replaces here
|
||||
|
||||
// float dp(float px) => px / screenScale
|
||||
tmpStr = [string stringByReplacingOccurrencesOfString:@"dp(" withString:[NSString stringWithFormat:@"(1.0 / %f * ", screenScale]];
|
||||
|
||||
// float px(float dp) => screenScale * dp
|
||||
tmpStr = [tmpStr stringByReplacingOccurrencesOfString:@"px(" withString:[NSString stringWithFormat:@"(%f * ", screenScale]];
|
||||
return tmpStr;
|
||||
}
|
||||
|
||||
- (CGFloat)calculateDynamicPos:(NSString *)string {
|
||||
CGRect screenBounds = self.superview.bounds;
|
||||
NSAssert(self.superview, @"Why is it null");
|
||||
@@ -119,6 +134,7 @@
|
||||
INSERT_VALUE("margin", ([NSString stringWithFormat:@"%f", 2.0 * screenScale]));
|
||||
INSERT_VALUE("preferred_scale", ([NSString stringWithFormat:@"%f", getPrefFloat(@"control.button_scale")]));
|
||||
|
||||
string = [self processFunctions:string];
|
||||
// NSLog(@"After insert: %@", string);
|
||||
|
||||
// Calculate, since the dynamic position contains some math equations
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
@implementation NSPredicateUtilitiesExternal
|
||||
|
||||
#if 0 // FIXME: doesn't work on certain iOS versions
|
||||
+ (NSNumber *)dp:(NSNumber *)number {
|
||||
return @(number.doubleValue / UIScreen.mainScreen.scale);
|
||||
}
|
||||
+ (NSNumber *)px:(NSNumber *)number {
|
||||
return @(number.doubleValue * UIScreen.mainScreen.scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
+ (NSNumber *)cbrt:(NSNumber *)number {
|
||||
return @(cbrt(number.doubleValue));
|
||||
|
||||
Reference in new issue
Block a user