diff --git a/Natives/customcontrols/ControlButton.m b/Natives/customcontrols/ControlButton.m index 40735120..1703898c 100644 --- a/Natives/customcontrols/ControlButton.m +++ b/Natives/customcontrols/ControlButton.m @@ -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 diff --git a/Natives/customcontrols/NSPredicateUtilitiesExternal.m b/Natives/customcontrols/NSPredicateUtilitiesExternal.m index 3c7a7edd..7b7f0b13 100644 --- a/Natives/customcontrols/NSPredicateUtilitiesExternal.m +++ b/Natives/customcontrols/NSPredicateUtilitiesExternal.m @@ -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));