xbmc / Official-Kodi-Remote-iOS

Full-featured remote control for XBMC Media Center. It features library browsing, now playing informations and a direct remote control.
Other
219 stars 104 forks source link

Review animations with duration of 0 seconds (AnimDuration:0.0) #1101

Closed wutschel closed 2 weeks ago

wutschel commented 1 month ago

During code review several occasions of animation with 0 seconds durations were found. This can be handled w/o animations at all. Search for AnimDuration:0.0 .

wutschel commented 2 weeks ago

@kambala-decapitator, I looked into options and found the following. Does this look reasonable?

typedef void (^animationBlock)(void);

+ (void)AnimView:(UIView*)view AnimDuration:(NSTimeInterval)seconds Alpha:(CGFloat)alphavalue XPos:(int)X YPos:(int)Y {
    animationBlock animation = ^{
        CGRect frame = view.frame;
        frame.origin.x = X;
        frame.origin.y = Y;
        view.frame = frame;
    };
    [Utilities animateWithDuration:seconds animation:animation];
}

+ (void)animateWithDuration:(NSTimeInterval)seconds animation:(animationBlock)animation {
    if (seconds > 0.0) {
        [UIView animateWithDuration:seconds
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:animation
                         completion:nil];
    }
    else {
        animation();
    }
}
kambala-decapitator commented 2 weeks ago

Looks like too much unnecessary work to me. Can't you just avoid any animation code for 0.0 cases completely?

wutschel commented 2 weeks ago

In this case I would just create AnimView:Alpha:XPos:, w/o the duration parameter.