[vlc-commits] [Git][videolan/vlc][master] 2 commits: macosx: More safely switch between animation types in...

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Nov 10 05:48:47 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
8a4cfec7 by Claudio Cambra at 2022-11-10T05:35:16+00:00
macosx: More safely switch between animation types in VLCLibraryCollectionViewFlowLayout, instead of pointer switching

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
97912516 by Claudio Cambra at 2022-11-10T05:35:16+00:00
macosx: Fix jittering when closing animation begins

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


1 changed file:

- modules/gui/macosx/library/VLCLibraryCollectionViewFlowLayout.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryCollectionViewFlowLayout.m
=====================================
@@ -43,6 +43,11 @@ typedef NS_ENUM(NSUInteger, VLCDetailViewAnimationType)
     VLCDetailViewAnimationTypeCollapse,
 };
 
+typedef NS_ENUM(NSUInteger, VLCExpandAnimationType) {
+    VLCExpandAnimationTypeDefault = 0,
+    VLCExpandAnimationTypeLarge,
+};
+
 static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
                                             const CVTimeStamp *inNow,
                                             const CVTimeStamp *inOutputTime,
@@ -58,7 +63,9 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
 
     NSArray *_defaultHeightAnimationSteps;
     NSArray *_largeHeightAnimationSteps;
-    NSArray *_animationSteps;
+    
+    VLCExpandAnimationType _animationType;
+    CGFloat _prevProvidedAnimationStep;
 }
 
 @property (nonatomic, readwrite) BOOL detailViewIsAnimating;
@@ -73,14 +80,15 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
 - (instancetype)init
 {
     self = [super init];
-    if (self == nil) {
-        return nil;
+    if (self) {
+        _defaultHeightAnimationSteps = [NSArray arrayWithArray:[self generateAnimationStepsForExpandedViewHeight:kDetailViewDefaultExpandedHeight]];
+        _largeHeightAnimationSteps = [NSArray arrayWithArray:[self generateAnimationStepsForExpandedViewHeight:kDetailViewLargeExpandedHeight]];
+        
+        _animationType = VLCExpandAnimationTypeDefault;
+        _prevProvidedAnimationStep = 0;
+        
+        [self resetLayout];
     }
-
-    _defaultHeightAnimationSteps = [NSArray arrayWithArray:[self generateAnimationStepsForExpandedViewHeight:kDetailViewDefaultExpandedHeight]];
-    _largeHeightAnimationSteps = [NSArray arrayWithArray:[self generateAnimationStepsForExpandedViewHeight:kDetailViewLargeExpandedHeight]];
-    _animationSteps = _defaultHeightAnimationSteps;
-    [self resetLayout];
     
     return self;
 }
@@ -99,6 +107,25 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
     return [generatedAnimationSteps copy];
 }
 
+- (CGFloat)currentAnimationStep
+{
+    if (_animationIndex < 0 || _animationIndex >= kAnimationSteps) {
+        return _prevProvidedAnimationStep; // Try to disguise problem
+    }
+    
+    switch(_animationType) {
+        case VLCExpandAnimationTypeLarge:
+            _prevProvidedAnimationStep = [_largeHeightAnimationSteps[_animationIndex] floatValue];
+            break;
+        case VLCExpandAnimationTypeDefault:
+        default:
+            _prevProvidedAnimationStep = [_defaultHeightAnimationSteps[_animationIndex] floatValue];
+            break;
+    }
+    
+    return _prevProvidedAnimationStep;
+}
+
 #pragma mark - Public methods
 - (void)expandDetailSectionAtIndex:(NSIndexPath *)indexPath
 {
@@ -193,13 +220,13 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
     if ([elementKind isEqualToString:VLCLibraryCollectionViewAudioGroupSupplementaryDetailViewKind]) {
 
         isLibrarySupplementaryView = YES;
-        _animationSteps = _largeHeightAnimationSteps;
+        _animationType = VLCExpandAnimationTypeLarge;
 
     } else if ([elementKind isEqualToString:VLCLibraryCollectionViewAlbumSupplementaryDetailViewKind] ||
                [elementKind isEqualToString:VLCLibraryCollectionViewMediaItemSupplementaryDetailViewKind]) {
 
         isLibrarySupplementaryView = YES;
-        _animationSteps = _defaultHeightAnimationSteps;
+        _animationType = VLCExpandAnimationTypeDefault;
     }
     
     if(isLibrarySupplementaryView) {
@@ -213,7 +240,7 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
         detailViewAttributes.frame = NSMakeRect(NSMinX(self.collectionView.frame),
                                                 selectedItemFrameMaxY + kDetailViewMargin,
                                                 self.collectionViewContentSize.width - 20.0,
-                                                [_animationSteps[_animationIndex] floatValue]);
+                                                [self currentAnimationStep]);
 
         return detailViewAttributes;
     }
@@ -239,12 +266,12 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
 # pragma mark - Calculation of displaced frame attributes
 
 - (NSRect)frameForDisplacedAttributes:(NSCollectionViewLayoutAttributes *)inAttributes {
-    if(inAttributes == nil || _animationSteps == NULL) {
+    if(inAttributes == nil) {
         return NSZeroRect;
     }
 
     NSRect attributesFrame = inAttributes.frame;
-
+    
     if (self.selectedIndexPath) {
         NSCollectionViewLayoutAttributes *selectedItemLayoutAttributes = [self layoutAttributesForItemAtIndexPath:_selectedIndexPath];
 
@@ -253,9 +280,9 @@ static CVReturn detailViewAnimationCallback(CVDisplayLinkRef displayLink,
         }
 
         NSRect selectedItemFrame = selectedItemLayoutAttributes.frame;
-
+        
         if (NSMinY(attributesFrame) > (NSMaxY(selectedItemFrame))) {
-            attributesFrame.origin.y += [_animationSteps[_animationIndex] floatValue] + kDetailViewMargin;
+            attributesFrame.origin.y += [self currentAnimationStep] + kDetailViewMargin;
         }
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e9f6e2adb8ca9038320a8cd6ea849930b18a2054...97912516a4e2280122c2f62205e7f508c304cd06

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e9f6e2adb8ca9038320a8cd6ea849930b18a2054...97912516a4e2280122c2f62205e7f508c304cd06
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list