def unmaskView(viewOrLayer): window = fb.evaluateExpression( "(UIWindow *)[[UIApplication sharedApplication] keyWindow]") mask = fb.evaluateExpression("(UIView *)[%s viewWithTag:(NSInteger)%s]" % (window, viewOrLayer)) fb.evaluateEffect("[%s removeFromSuperview]" % mask) flushCoreAnimationTransaction()
def run(self, arguments, options): if options.set: fb.evaluateEffect("[CKComponentDebugController setDebugMode:YES]") print("Debug mode for ComponentKit has been set.") elif options.unset: fb.evaluateEffect("[CKComponentDebugController setDebugMode:NO]") print("Debug mode for ComponentKit has been unset.") else: print("No option for ComponentKit Debug mode specified.")
def forceStartAccessibilityServer(): # We try to start accessibility server only if we don't have needed method active if not fb.evaluateBooleanExpression( "[UIView instancesRespondToSelector:@selector(_accessibilityElementsInContainer:)]" # noqa B950 ): # Starting accessibility server is different for simulator and device if isRunningInSimulator(): fb.evaluateEffect( "[[UIApplication sharedApplication] accessibilityActivate]") else: fb.evaluateEffect( "[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]" # noqa B950 )
def _showColor(color): color = "(" + color + ")" colorToUse = color isCF = _colorIsCGColorRef(color) if isCF: colorToUse = "[[UIColor alloc] initWithCGColor:(CGColorRef){}]".format( color) else: isCI = objectHelpers.isKindOfClass(color, "CIColor") if isCI: colorToUse = "[UIColor colorWithCIColor:(CIColor *){}]".format( color) imageSize = 58 fb.evaluateEffect( "UIGraphicsBeginImageContextWithOptions((CGSize)CGSizeMake({imageSize}, {imageSize}), NO, 0.0)" .format(imageSize=imageSize)) fb.evaluateEffect("[(id){} setFill]".format(colorToUse)) fb.evaluateEffect( "UIRectFill((CGRect)CGRectMake(0.0, 0.0, {imageSize}, {imageSize}))". format(imageSize=imageSize)) result = fb.evaluateExpressionValue( "(UIImage *)UIGraphicsGetImageFromCurrentImageContext()") if result.GetError() is not None and str(result.GetError()) != "success": print("got error {}".format(result)) print(result.GetError()) else: image = result.GetValue() _showImage(image) fb.evaluateEffect("UIGraphicsEndImageContext()")
def dismissViewController(viewController): vc = "(%s)" % (viewController) if fb.evaluateBooleanExpression( "%s != nil && ((BOOL)[(id)%s isKindOfClass:(Class)[UIViewController class]])" % (vc, vc)): isPresented = fb.evaluateBooleanExpression( "[%s presentingViewController] != nil" % vc) if isPresented: fb.evaluateEffect( "[(UIViewController *)%s dismissViewControllerAnimated:YES completion:nil]" # noqa B950 % vc) else: raise Exception("Argument must be presented") else: raise Exception("Argument must be a UIViewController")
def presentViewController(viewController): vc = "(%s)" % (viewController) if fb.evaluateBooleanExpression( "%s != nil && ((BOOL)[(id)%s isKindOfClass:(Class)[UIViewController class]])" % (vc, vc)): notPresented = fb.evaluateBooleanExpression( "[%s presentingViewController] == nil" % vc) if notPresented: fb.evaluateEffect( "[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:%s animated:YES completion:nil]" # noqa B950 % vc) else: raise Exception("Argument is already presented") else: raise Exception("Argument must be a UIViewController")
def _showLayer(layer): layer = "(" + layer + ")" size = "((CGRect)[(id)" + layer + " bounds]).size" width = float(fb.evaluateExpression("(CGFloat)(" + size + ".width)")) height = float(fb.evaluateExpression("(CGFloat)(" + size + ".height)")) if width == 0.0 or height == 0.0: print("Nothing to see here - the size of this element is {} x {}.". format(width, height)) return fb.evaluateEffect("UIGraphicsBeginImageContextWithOptions(" + size + ", NO, 0.0)") fb.evaluateEffect( "[(id)" + layer + " renderInContext:(void *)UIGraphicsGetCurrentContext()]") result = fb.evaluateExpressionValue( "(UIImage *)UIGraphicsGetImageFromCurrentImageContext()") if result.GetError() is not None and str(result.GetError()) != "success": print(result.GetError()) else: image = result.GetValue() _showImage(image) fb.evaluateEffect("UIGraphicsEndImageContext()")
def maskView(viewOrLayer, color, alpha): unmaskView(viewOrLayer) window = fb.evaluateExpression( "(UIWindow *)[[UIApplication sharedApplication] keyWindow]") origin = convertPoint(0, 0, viewOrLayer, window) size = fb.evaluateExpressionValue("(CGSize)((CGRect)[(id)%s frame]).size" % viewOrLayer) rectExpr = "(CGRect){{%s, %s}, {%s, %s}}" % ( origin.GetChildMemberWithName("x").GetValue(), origin.GetChildMemberWithName("y").GetValue(), size.GetChildMemberWithName("width").GetValue(), size.GetChildMemberWithName("height").GetValue(), ) mask = fb.evaluateExpression("(id)[[UIView alloc] initWithFrame:%s]" % rectExpr) fb.evaluateEffect("[%s setTag:(NSInteger)%s]" % (mask, viewOrLayer)) fb.evaluateEffect("[%s setBackgroundColor:[UIColor %sColor]]" % (mask, color)) fb.evaluateEffect("[%s setAlpha:(CGFloat)%s]" % (mask, alpha)) fb.evaluateEffect("[%s addSubview:%s]" % (window, mask)) flushCoreAnimationTransaction()
def setBorder(layer, width, color, colorClass): fb.evaluateEffect("[%s setBorderWidth:(CGFloat)%s]" % (layer, width)) fb.evaluateEffect( "[%s setBorderColor:(CGColorRef)[(id)[%s %sColor] CGColor]]" % (layer, colorClass, color))
def setUnborder(layer): fb.evaluateEffect("[%s setBorderWidth:(CGFloat)%s]" % (layer, 0))
def run(self, arguments, options): fb.evaluateEffect( "[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)]" )
def setViewHidden(object, hidden): fb.evaluateEffect("[{} setHidden:{}]".format(object, int(hidden))) flushCoreAnimationTransaction()
def slowAnimation(speed=1): fb.evaluateEffect( '[[[UIApplication sharedApplication] windows] setValue:@(%s) forKeyPath:@"layer.speed"]' % speed)
def flushCoreAnimationTransaction(): fb.evaluateEffect("[CATransaction flush]")
def run(self, arguments, options): fb.evaluateEffect("[CKComponentDebugController reflowComponents]")