Exemplo n.º 1
0
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()
Exemplo n.º 2
0
 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.")
Exemplo n.º 3
0
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
            )
Exemplo n.º 4
0
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()")
Exemplo n.º 5
0
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")
Exemplo n.º 6
0
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")
Exemplo n.º 7
0
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()")
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 def setUnborder(layer):
     fb.evaluateEffect("[%s setBorderWidth:(CGFloat)%s]" % (layer, 0))
Exemplo n.º 11
0
 def run(self, arguments, options):
     fb.evaluateEffect(
         "[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)]"
     )
Exemplo n.º 12
0
def setViewHidden(object, hidden):
    fb.evaluateEffect("[{} setHidden:{}]".format(object, int(hidden)))
    flushCoreAnimationTransaction()
Exemplo n.º 13
0
def slowAnimation(speed=1):
    fb.evaluateEffect(
        '[[[UIApplication sharedApplication] windows] setValue:@(%s) forKeyPath:@"layer.speed"]'
        % speed)
Exemplo n.º 14
0
def flushCoreAnimationTransaction():
    fb.evaluateEffect("[CATransaction flush]")
Exemplo n.º 15
0
 def run(self, arguments, options):
     fb.evaluateEffect("[CKComponentDebugController reflowComponents]")