Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorgames committed Feb 1, 2018
2 parents c092280 + 250746a commit 793a6c8
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 111 deletions.
213 changes: 126 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace HelloXamarinFormsWorld.Android
base.OnCreate(bundle);

Rg.Plugins.Popup.Popup.Init(this, bundle);
Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication (new App ());
}
Expand Down Expand Up @@ -129,8 +129,8 @@ Xamarin.Forms.Forms.Init(e, Rg.Plugins.Popup.Popup.GetExtraAssemblies());
* BackgroundColor: Hex #80FF5C5C where #80 opacity [Range](http://stackoverflow.com/questions/5445085/understanding-colors-in-android-6-characters/11019879#11019879)
* CloseWhenBackgroundIsClicked: Close pop-up when click on the background
* HasSystemPadding: Enabled/Disabled system padding offset (Only for Content not for Background)
![Android](/icons/system-padding-droid.png) ![Android](/icons/system-padding-ios.png)
![Android](/icons/system-padding-droid.png) ![Android](/icons/system-padding-ios.png)
* SystemPadding: (ReadOnly) Thickness

## How To Use
Expand Down Expand Up @@ -177,115 +177,147 @@ Task RemovePageAsync(PopupPage page, bool animate = true) // Navigation.RemovePo
```
```csharp
public partial class MyPopupPage : PopupPage
{
public MyPopupPage()
{
public MyPopupPage()
{
InitializeComponent();
}
InitializeComponent();
}

protected override void OnAppearing()
{
base.OnAppearing();
}
protected override void OnAppearing()
{
base.OnAppearing();
}

protected override void OnDisappearing()
{
base.OnDisappearing();
}

// Method for animation child in PopupPage
// Invoced after custom animation end
protected override Task OnAppearingAnimationEnd()
{
return Content.FadeTo(0.5);
}
protected override void OnDisappearing()
{
base.OnDisappearing();
}

// Method for animation child in PopupPage
// Invoked before custom animation begin
protected override Task OnDisappearingAnimationBegin()
{
return Content.FadeTo(1);
}
// Methods for support animations of views in your popup page
protected override bool OnBackButtonPressed()
{
// Prevent hide popup
//return base.OnBackButtonPressed();
return true;
}
// Invoked before an appearing animation
protected override void OnAppearingAnimationBegin()
{
base.OnAppearingAnimationBegin();
}

// Invoced when background is clicked
protected override bool OnBackgroundClicked()
{
// Return default value - CloseWhenBackgroundIsClicked
return base.OnBackgroundClicked();
}
// Invoked after an appearing animation
protected override void OnAppearingAnimationEnd()
{
base.OnAppearingAnimationEnd();
}

// Invoked before an disappearing animation
protected override void OnDisappearingAnimationBegin()
{
base.OnDisappearingAnimationBegin();
}

// Invoked after an disappearing animation
protected override void OnDisappearingAnimationEnd()
{
base.OnDisappearingAnimationEnd();
}

protected override Task OnAppearingAnimationBeginAsync()
{
return base.OnAppearingAnimationBeginAsync();
}

protected override Task OnAppearingAnimationEndAsync()
{
return base.OnAppearingAnimationEndAsync();
}

protected override Task OnDisappearingAnimationBeginAsync()
{
return base.OnDisappearingAnimationBeginAsync();
}

protected override Task OnDisappearingAnimationEndAsync()
{
return base.OnDisappearingAnimationEndAsync();
}

protected override bool OnBackButtonPressed()
{
// Prevent hide popup
//return base.OnBackButtonPressed();
return true;
}

// Invoced when background is clicked
protected override bool OnBackgroundClicked()
{
// Return default value - CloseWhenBackgroundIsClicked
return base.OnBackgroundClicked();
}
}

// Main Page
// Main Page
public partial class MainPage : ContentPage
public partial class MainPage : ContentPage
{
public MainPage()
{
public MainPage()
{
InitializeComponent();
}
InitializeComponent();
}

// Button Click
private async void OnOpenPupup(object sender, EventArgs e)
{
var page = new MyPopupPage();
// Button Click
private async void OnOpenPupup(object sender, EventArgs e)
{
var page = new MyPopupPage();

await Navigation.PushPopupAsync(page);
// or
await PopupNavigation.PushAsync(page);
}
await Navigation.PushPopupAsync(page);
// or
await PopupNavigation.PushAsync(page);
}
}
```

## User Animation

```csharp
// User animation
class UserAnimation : IPopupAnimation
// User animation
class UserAnimation : IPopupAnimation
{
// Call Before OnAppering
public void Preparing(View content, PopupPage page)
{
// Call Before OnAppering
public void Preparing(View content, PopupPage page)
{
// Preparing content and page
content.Opacity = 0;
}
// Preparing content and page
content.Opacity = 0;
}

// Call After OnDisappering
public void Disposing(View content, PopupPage page)
{
// Dispose Unmanaged Code
}
// Call After OnDisappering
public void Disposing(View content, PopupPage page)
{
// Dispose Unmanaged Code
}

// Call After OnAppering
public async Task Appearing(View content, PopupPage page)
{
// Show animation
await content.FadeTo(1);
}
// Call After OnAppering
public async Task Appearing(View content, PopupPage page)
{
// Show animation
await content.FadeTo(1);
}

// Call Before OnDisappering
public async Task Disappearing(View content, PopupPage page)
{
// Hide animation
await content.FadeTo(0);
}
// Call Before OnDisappering
public async Task Disappearing(View content, PopupPage page)
{
// Hide animation
await content.FadeTo(0);
}
}

// Popup Page
public partial class UserPopupPage : PopupPage
// Popup Page
public partial class UserPopupPage : PopupPage
{
public SecondPopupPage()
{
public SecondPopupPage()
{
InitializeComponent();
Animation = new UserAnimation();
}
InitializeComponent();
Animation = new UserAnimation();
}
}
```

Or in xaml
Expand All @@ -304,8 +336,15 @@ Or in xaml
</pages:PopupPage>
```

## Thanks
## Troubleshooting

### Doesn't work/build or etc
* Check if one version of plugin has been installed to an each project with Xamarin.Forms in solution.
* Clean a solution or an each Xamarin.Forms project.
* Close Visual Studio (or VS for Mac or Xamarin Studio or other IDA) and remove an each obj and bin folder in the each project.
* If previous items didn't help, don't hesitate, [create a new issue here](https://github.com/rotorgames/Rg.Plugins.Popup/issues).

## Thanks
* [xam-forms-transparent-modal](https://github.com/gaborv/xam-forms-transparent-modal)

## License
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.1.3.{build}-beta
version: 1.1.4.{build}-beta
branches:
only:
- master
Expand Down
9 changes: 4 additions & 5 deletions src/Demo/Demo/Pages/FirstPopupPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Demo.Animations;
using Rg.Plugins.Popup.Pages;
using Rg.Plugins.Popup.Services;
using Xamarin.Forms;
Expand All @@ -14,17 +13,17 @@ public FirstPopupPage()
InitializeComponent();
}

private void OnClose(object sender, EventArgs e)
private async void OnClose(object sender, EventArgs e)
{
PopupNavigation.PopAsync();
await PopupNavigation.PopAsync();
}

protected override Task OnAppearingAnimationEnd()
protected override Task OnAppearingAnimationEndAsync()
{
return Content.FadeTo(0.5);
}

protected override Task OnDisappearingAnimationBegin()
protected override Task OnDisappearingAnimationBeginAsync()
{
return Content.FadeTo(1);
}
Expand Down
11 changes: 4 additions & 7 deletions src/Demo/Demo/Pages/LoginPopupPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rg.Plugins.Popup.Extensions;
using Rg.Plugins.Popup.Pages;
Expand All @@ -16,9 +13,9 @@ public LoginPopupPage()
InitializeComponent();
}

protected override void OnAppearing()
protected override void OnAppearingAnimationBegin()
{
base.OnAppearing();
base.OnAppearingAnimationBegin();

FrameContainer.HeightRequest = -1;

Expand All @@ -33,7 +30,7 @@ protected override void OnAppearing()
UsernameEntry.Opacity = PasswordEntry.Opacity = 0;
}

protected async override Task OnAppearingAnimationEnd()
protected override async Task OnAppearingAnimationEndAsync()
{
var translateLength = 400u;

Expand All @@ -57,7 +54,7 @@ await Task.WhenAll(
LoginButton.FadeTo(1));
}

protected async override Task OnDisappearingAnimationBegin()
protected override async Task OnDisappearingAnimationBeginAsync()
{
var taskSource = new TaskCompletionSource<bool>();

Expand Down
34 changes: 34 additions & 0 deletions src/Rg.Plugins.Popup.Droid/Impl/PopupPlatformDroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Linq;
using System.Threading.Tasks;
using Android.App;
using Android.OS;
using Android.Provider;
using Android.Runtime;
using Android.Widget;
using Rg.Plugins.Popup.Contracts;
Expand Down Expand Up @@ -32,6 +34,8 @@ public event EventHandler OnInitialized

public bool IsInitialized => Popup.IsInitialized;

public bool IsSystemAnimationEnabled => GetIsSystemAnimationEnabled();

public async Task AddAsync(PopupPage page)
{
var decoreView = DecoreView;
Expand Down Expand Up @@ -122,5 +126,35 @@ private bool OnBackPressed(object sender, EventArgs e)
}

#endregion

#region System Animation

private bool GetIsSystemAnimationEnabled()
{
float animationScale;
var context = Popup.Context;

if (context == null)
return false;

if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
{
animationScale = Settings.Global.GetFloat(
context.ContentResolver,
Settings.Global.AnimatorDurationScale,
0);
}
else
{
animationScale = Settings.System.GetFloat(
context.ContentResolver,
Settings.System.AnimatorDurationScale,
0);
}

return animationScale > 0;
}

#endregion
}
}
Loading

0 comments on commit 793a6c8

Please sign in to comment.