Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit c8ee45d

Browse files
authored
Fix a bug that DrawerLocation cannot be changed dynamically (#484)
* Fix a bug that drawer is shown at the wrong location when the DrawerLocation is changed but ShowDrawer is called before layout is updated. For example when on button clicked the DrawerLocation is changed and right after that ShowDrawer is called. When this happens the change of the DrawerLocation calls InvalidateMeasure but before the layout pass the ShowDrawer method is called, which plays a the animation associated with the previous DrawerLocation value.
1 parent 12310bb commit c8ee45d

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

Controls/Primitives/Primitives.UWP/SideDrawer/Commands/AnimationContext.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Windows.UI.Xaml.Media.Animation;
1+
using Windows.UI.Xaml.Media.Animation;
72

83
namespace Telerik.UI.Xaml.Controls.Primitives.SideDrawer.Commands
94
{
@@ -32,12 +27,21 @@ public class AnimationContext
3227
/// </summary>
3328
public Storyboard DrawerStoryBoardReverse { get; set; }
3429

30+
internal DrawerLocation DrawerLocation { get; set; }
31+
32+
internal DrawerTransition DrawerTransition { get; set; }
33+
3534
internal bool IsGenerated
3635
{
3736
get
3837
{
3938
return this.MainContentStoryBoard != null && this.MainContentStoryBoardReverse != null && this.DrawerStoryBoard != null && this.DrawerStoryBoardReverse != null;
4039
}
4140
}
41+
42+
internal bool IsValid(DrawerLocation location, DrawerTransition transition)
43+
{
44+
return this.IsGenerated && this.DrawerLocation == location && this.DrawerTransition == transition;
45+
}
4246
}
4347
}

Controls/Primitives/Primitives.UWP/SideDrawer/RadSideDrawer.AnimationGenerator.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ internal AnimationContext GetAnimations(bool shouldPrepareDrawer = true)
6666
return this.GetSlideAlongAnimations();
6767

6868
default:
69-
return new AnimationContext();
69+
return new AnimationContext() { DrawerLocation = this.DrawerLocation, DrawerTransition = this.DrawerTransition };
7070
}
7171
}
7272

@@ -165,7 +165,9 @@ private AnimationContext GetPushAnimations()
165165
MainContentStoryBoard = this.mainContentStoryboard,
166166
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
167167
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
168-
DrawerStoryBoard = this.sideBarStoryboard
168+
DrawerStoryBoard = this.sideBarStoryboard,
169+
DrawerLocation = this.DrawerLocation,
170+
DrawerTransition = this.DrawerTransition
169171
};
170172
}
171173

@@ -259,7 +261,9 @@ private AnimationContext GetRevealAnimations()
259261
MainContentStoryBoard = this.mainContentStoryboard,
260262
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
261263
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
262-
DrawerStoryBoard = this.sideBarStoryboard
264+
DrawerStoryBoard = this.sideBarStoryboard,
265+
DrawerLocation = this.DrawerLocation,
266+
DrawerTransition = this.DrawerTransition
263267
};
264268
}
265269

@@ -400,7 +404,9 @@ private AnimationContext GetReverseSlideOutAnimations()
400404
MainContentStoryBoard = this.mainContentStoryboard,
401405
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
402406
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
403-
DrawerStoryBoard = this.sideBarStoryboard
407+
DrawerStoryBoard = this.sideBarStoryboard,
408+
DrawerLocation = this.DrawerLocation,
409+
DrawerTransition = this.DrawerTransition
404410
};
405411
}
406412

@@ -509,7 +515,9 @@ private AnimationContext GetScaleDownPusherAnimations()
509515
MainContentStoryBoard = this.mainContentStoryboard,
510516
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
511517
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
512-
DrawerStoryBoard = this.sideBarStoryboard
518+
DrawerStoryBoard = this.sideBarStoryboard,
519+
DrawerLocation = this.DrawerLocation,
520+
DrawerTransition = this.DrawerTransition
513521
};
514522
}
515523

@@ -651,7 +659,9 @@ private AnimationContext GetScaleUpAnimations()
651659
MainContentStoryBoard = this.mainContentStoryboard,
652660
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
653661
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
654-
DrawerStoryBoard = this.sideBarStoryboard
662+
DrawerStoryBoard = this.sideBarStoryboard,
663+
DrawerLocation = this.DrawerLocation,
664+
DrawerTransition = this.DrawerTransition
655665
};
656666
}
657667

@@ -718,7 +728,9 @@ private AnimationContext GetSlideInOnTopAnimations()
718728
MainContentStoryBoard = this.mainContentStoryboard,
719729
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
720730
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
721-
DrawerStoryBoard = this.sideBarStoryboard
731+
DrawerStoryBoard = this.sideBarStoryboard,
732+
DrawerLocation = this.DrawerLocation,
733+
DrawerTransition = this.DrawerTransition
722734
};
723735
}
724736

@@ -842,7 +854,9 @@ private AnimationContext GetSlideAlongAnimations()
842854
MainContentStoryBoard = this.mainContentStoryboard,
843855
MainContentStoryBoardReverse = this.mainContentStoryboardReverse,
844856
DrawerStoryBoardReverse = this.sideBarStoryboardReverse,
845-
DrawerStoryBoard = this.sideBarStoryboard
857+
DrawerStoryBoard = this.sideBarStoryboard,
858+
DrawerLocation = this.DrawerLocation,
859+
DrawerTransition = this.DrawerTransition
846860
};
847861
}
848862

Controls/Primitives/Primitives.UWP/SideDrawer/RadSideDrawer.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ public void ShowDrawer()
428428
return;
429429
}
430430

431+
if (!this.Context.IsValid(this.DrawerLocation, this.DrawerTransition))
432+
{
433+
this.UpdateLayout();
434+
}
435+
431436
if (this.DrawerState == DrawerState.Closed)
432437
{
433438
this.Context.MainContentStoryBoard.Begin();
@@ -674,7 +679,7 @@ protected override AutomationPeer OnCreateAutomationPeer()
674679
private static void OnDrawerTransitionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
675680
{
676681
var sideDrawer = d as RadSideDrawer;
677-
if (sideDrawer.drawer != null)
682+
if (sideDrawer.drawer != null && (DrawerTransition)e.NewValue != (DrawerTransition)e.OldValue)
678683
{
679684
sideDrawer.ResetDrawer();
680685
}
@@ -720,7 +725,7 @@ private static void OnDrawerStateChanged(DependencyObject d, DependencyPropertyC
720725
private static void OnDrawerLocationChagned(DependencyObject d, DependencyPropertyChangedEventArgs e)
721726
{
722727
var sideDrawer = d as RadSideDrawer;
723-
if (sideDrawer.drawer != null)
728+
if (sideDrawer.drawer != null && (DrawerLocation)e.NewValue != (DrawerLocation)e.OldValue)
724729
{
725730
sideDrawer.ResetDrawer();
726731
}

0 commit comments

Comments
 (0)