Skip to content

Commit 7c510f2

Browse files
bratscheglennawatson
authored andcommitted
feature: Allow XamForms navigation transition animations to be disabled (#1655)
1 parent 9b0aba5 commit 7c510f2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace ReactiveUI.XamForms
4+
{
5+
public class DisableAnimationAttribute : Attribute
6+
{
7+
}
8+
}

src/ReactiveUI.XamForms/RoutedViewHost.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using Xamarin.Forms;
7-
using Splat;
8-
using ReactiveUI;
6+
using System.Reactive;
97
using System.Reactive.Linq;
108
using System.Reactive.Threading.Tasks;
11-
using System.Diagnostics;
12-
using System.Reactive;
9+
using System.Reflection;
10+
11+
using Xamarin.Forms;
12+
13+
using Splat;
1314

1415
namespace ReactiveUI.XamForms
1516
{
@@ -86,19 +87,26 @@ public RoutedViewHost()
8687

8788
d(this.WhenAnyObservable(x => x.Router.Navigate)
8889
.SelectMany(_ => PageForViewModel(Router.GetCurrentViewModel()))
89-
.SelectMany(async x => {
90+
.SelectMany(async page => {
9091
if (popToRootPending && this.Navigation.NavigationStack.Count > 0)
9192
{
92-
this.Navigation.InsertPageBefore(x, this.Navigation.NavigationStack[0]);
93+
this.Navigation.InsertPageBefore(page, this.Navigation.NavigationStack[0]);
9394
await this.PopToRootAsync();
9495
}
9596
else
9697
{
97-
await this.PushAsync(x);
98+
bool animated = true;
99+
var attribute = page.GetType().GetCustomAttribute<DisableAnimationAttribute>();
100+
if (attribute != null)
101+
{
102+
animated = false;
103+
}
104+
105+
await this.PushAsync(page, animated);
98106
}
99107

100108
popToRootPending = false;
101-
return x;
109+
return page;
102110
})
103111
.Subscribe());
104112

0 commit comments

Comments
 (0)