Issue
When pushing and popping the pages
I am using Custom renderer
for left and right transition. I want to write that code in shared project without using custom renderer
or dependency services
This is my code. How can I write this totally cross platform
if
{
transaction.SetCustomAnimations(Resource.Animation.enter_right, Resource.Animation.exit_left,
Resource.Animation.enter_left, Resource.Animation.exit_right);
}
else
{
transaction.SetCustomAnimations(Resource.Animation.enter_left, Resource.Animation.exit_right,
Resource.Animation.enter_right, Resource.Animation.exit_left);
}
Solution
You can use Xamarin.Plugin.SharedTransitions
this plugin.
https://github.com/GiampaoloGabba/Xamarin.Plugin.SharedTransitions
You can use it like following step.
1.In the App.xaml.cs
, use following code to warp the MainPage.
public App()
{
InitializeComponent();
var sharedTransitionNavigationPage=new SharedTransitionNavigationPage(new MainPage());
MainPage = sharedTransitionNavigationPage;
}
In the MainPage.xam.cs
add following code for Animations
and navigation.
namespace MyPopUpPageDemo
{
public partial class MainPage : ContentPage
{
public MainPage()
{
//for Animations
SharedTransitionNavigationPage.SetBackgroundAnimation(this, BackgroundAnimation.SlideFromRight);
SharedTransitionNavigationPage.SetTransitionDuration(this, 2000);
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
//for navigation
Navigation.PushAsync(new Page1());
}
}
}
In the page1, that is same.
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Page1 : ContentPage
{
public Page1()
{
SharedTransitionNavigationPage.SetBackgroundAnimation(this, BackgroundAnimation.SlideFromRight);
SharedTransitionNavigationPage.SetTransitionDuration(this, 1000);
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Page2());
}
}
Here is running GIF.
Answered By - Leon Lu - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.