Github user cxfeng1 commented on a diff in the pull request:

    https://github.com/apache/incubator-weex/pull/581#discussion_r132132151
  
    --- Diff: ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m ---
    @@ -112,6 +115,211 @@ - (NSUInteger)_childrenCountForLayout
         return (int)(count);
     }
     
    +
    +#pragma mark LayoutAnimationDisplayLink
    +- (void)_startLayoutAnimationDisplayLink
    +{
    +    WXAssertComponentThread();
    +    if (!_layoutAnimationDisplayLink) {
    +        _layoutAnimationDisplayLink = [CADisplayLink 
displayLinkWithTarget:self 
selector:@selector(_handleLayoutAnimationDisplayLink)];
    +        [_layoutAnimationDisplayLink addToRunLoop:[NSRunLoop 
currentRunLoop] forMode:NSDefaultRunLoopMode];
    +    }
    +    else{
    +        [self _awakeLayoutAnimationDisplayLink];
    +    }
    +    
    +}
    +
    +- (void)_stopLayoutAnimationDisplayLink
    +{
    +    WXAssertComponentThread();
    +    if (_layoutAnimationDisplayLink) {
    +        [_layoutAnimationDisplayLink invalidate];
    +        _layoutAnimationDisplayLink = nil;
    +    }
    +}
    +
    +- (void)_suspendLayoutAnimationDisplayLink
    +{
    +    WXAssertComponentThread();
    +    if(_layoutAnimationDisplayLink && !_layoutAnimationDisplayLink.paused)
    +    {
    +        _layoutAnimationDisplayLink.paused = YES;
    +    }
    +}
    +
    +
    +- (void)_awakeLayoutAnimationDisplayLink
    +{
    +    WXAssertComponentThread();
    +    if (_layoutAnimationDisplayLink && _layoutAnimationDisplayLink.paused) 
{
    +        _layoutAnimationDisplayLink.paused = NO;
    +    }
    +}
    +
    +- (void)_handleLayoutAnimationDisplayLink
    +{
    +    WXAssertComponentThread();
    +    int count = _layoutAnimationDuration * 60 / 1000;
    +    if (_layoutAnimationCount >= count) {
    +        [self _suspendLayoutAnimationDisplayLink];
    +        [self _resetProcessAnimationParameter];
    +        return;
    +    }
    +    else
    +    {
    +        [self _calculateLayoutAnimationProcessingStyle];
    +    }
    +    _layoutAnimationCount ++;
    +}
    +
    +
    +- (void)_resetProcessAnimationParameter
    +{
    +    
    +    _layoutAnimationCount = 0;
    +    _layoutAnimationDuration = 0;
    +    _widthInfo = nil;
    +    _heightInfo = nil;
    +    _leftInfo = nil;
    +    _rightInfo = nil;
    +    _topInfo = nil;
    +    _bottomInfo = nil;
    +}
    +
    +- (void)_handleLayoutAnimationWithStyles:(NSDictionary *)styles
    +{
    +    [self _suspendLayoutAnimationDisplayLink];
    +    
    +    if (!_addStyles) {
    +        _fromStyles = [NSMutableDictionary 
dictionaryWithDictionary:self.styles];
    +        _addStyles = [NSMutableDictionary dictionaryWithDictionary:styles];
    +    }
    +    else
    +    {
    +        [_addStyles addEntriesFromDictionary:styles];
    +    }//保证_addStyles是唯一的
    +    
    +    _toStyles = [NSMutableDictionary dictionaryWithDictionary:_fromStyles];
    +    [_toStyles addEntriesFromDictionary:_addStyles];
    +    
    +    _layoutAnimationDuration = _fromStyles[@"transitionDuration"] ? 
[WXConvert CGFloat:_fromStyles[@"transitionDuration"]] : 0;
    +    _layoutAnimationDelay = _fromStyles[@"transitionDelay"] ? [WXConvert 
CGFloat:_fromStyles[@"transitionDelay"]] : 0;
    +    _layoutAnimationTimingFunction = [WXConvert 
CAMediaTimingFunction:_fromStyles[@"transitionTimingFunction"]];
    +    
    +    
    +    if (_layoutAnimationDuration == 0) {
    +        [self _fillCSSNode:styles];
    +        return;//如果duration为零直接关闭动画效果
    +    }
    +    
    +    if (![[NSString stringWithFormat:@"%@",_layoutAnimationTimingFunction] 
isEqualToString: kCAMediaTimingFunctionLinear]) {
    +        float vec[4] = {0.};
    +        [_layoutAnimationTimingFunction getControlPointAtIndex:1 
values:&vec[0]];
    +        [_layoutAnimationTimingFunction getControlPointAtIndex:2 
values:&vec[2]];
    +        [self unitBezierp1x:vec[0] p1y:vec[1] p2x:vec[2] p2y:vec[3]];
    +    }
    +    
    +    
    +    NSString *layoutAnimationProperty = _fromStyles[@"transitionProperty"];
    +    if ([layoutAnimationProperty containsString:@"width"]) {
    +        _widthInfo = [WXLayoutAnimationInfo new];
    +        _widthInfo.isAnimated = YES;
    +        _widthInfo.fromValue = @(_fromStyles[@"width"] ? [WXConvert 
CGFloat:_fromStyles[@"width" ]] : 0);
    +        _widthInfo.toValue = @(_toStyles[@"width"] ? [WXConvert 
CGFloat:_toStyles[@"width"]] : 0 );
    +        _widthInfo.perValue = @([_widthInfo.toValue doubleValue] - 
[_widthInfo.fromValue doubleValue]);
    +        
    +    }
    +    if ([layoutAnimationProperty containsString:@"height"])
    +    {
    +        _heightInfo = [WXLayoutAnimationInfo new];
    +        _heightInfo.isAnimated = YES;
    +        _heightInfo.fromValue = @(_fromStyles[@"height"] ? [WXConvert 
CGFloat:_fromStyles[@"height" ]] : 0);
    +        _heightInfo.toValue = @(_toStyles[@"height"] ? [WXConvert 
CGFloat:_toStyles[@"height"]] : 0 );
    +        _heightInfo.perValue = @([_heightInfo.toValue doubleValue] - 
[_heightInfo.fromValue doubleValue]);
    +        
    +    }
    +    if ([layoutAnimationProperty containsString:@"left"])
    +    {
    +        _leftInfo = [WXLayoutAnimationInfo new];
    +        _leftInfo.isAnimated = YES;
    +        _leftInfo.fromValue = @(_fromStyles[@"left"] ? [WXConvert 
CGFloat:_fromStyles[@"left" ]] : 0);
    +        _leftInfo.toValue = @(_toStyles[@"left"] ? [WXConvert 
CGFloat:_toStyles[@"left"]] : 0 );
    +        _leftInfo.perValue = @([_leftInfo.toValue doubleValue] - 
[_leftInfo.fromValue doubleValue]);
    +        
    +    }
    +    if ([layoutAnimationProperty containsString:@"right"])
    +    {
    +        _rightInfo = [WXLayoutAnimationInfo new];
    +        _rightInfo.isAnimated = YES;
    +        _rightInfo.fromValue = @(_fromStyles[@"right"] ? [WXConvert 
CGFloat:_fromStyles[@"right" ]] : 0);
    +        _rightInfo.toValue = @(_toStyles[@"right"] ? [WXConvert 
CGFloat:_toStyles[@"right"]] : 0 );
    +        _rightInfo.perValue = @([_rightInfo.toValue doubleValue] - 
[_rightInfo.fromValue doubleValue]);
    +        
    +    }
    +    if ([layoutAnimationProperty containsString:@"top"])
    +    {
    +        _topInfo = [WXLayoutAnimationInfo new];
    +        _topInfo.isAnimated = YES;
    +        _topInfo.fromValue = @(_fromStyles[@"top"] ? [WXConvert 
CGFloat:_fromStyles[@"top" ]] : 0);
    +        _topInfo.toValue = @(_toStyles[@"top"] ? [WXConvert 
CGFloat:_toStyles[@"top"]] : 0 );
    +        _topInfo.perValue = @([_topInfo.toValue doubleValue] - 
[_topInfo.fromValue doubleValue]);
    +        
    +    }
    +    if ([layoutAnimationProperty containsString:@"bottom"])
    +    {
    +        _bottomInfo = [WXLayoutAnimationInfo new];
    +        _bottomInfo.isAnimated = YES;
    +        _bottomInfo.fromValue = @(_fromStyles[@"bottom"] ? [WXConvert 
CGFloat:_fromStyles[@"bottom" ]] : 0);
    +        _bottomInfo.toValue = @(_toStyles[@"bottom"] ? [WXConvert 
CGFloat:_toStyles[@"bottom"]] : 0 );
    +        _bottomInfo.perValue = @([_widthInfo.toValue doubleValue] - 
[_bottomInfo.fromValue doubleValue]);
    +        
    +    }
    +    if ([layoutAnimationProperty containsString:@"transform"]) {
    +        
    +        
    +    }
    +    
    +    
    +    [self performSelector:@selector(_startLayoutAnimationDisplayLink) 
withObject:self afterDelay:_layoutAnimationDelay/1000];
    +    //    [self _startLayoutAnimationDisplayLink];
    +    
    +}
    +
    +
    +- (void)_calculateLayoutAnimationProcessingStyle
    +{
    +    //linear 在做贝塞尔曲线模型
    --- End diff --
    
    Use English comments


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to