Skip to content

Commit

Permalink
Add blur library for android
Browse files Browse the repository at this point in the history
  • Loading branch information
wcoder committed Jun 8, 2018
1 parent 9f0983b commit 50c71e4
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.BlurView">
<Version>1.3.4</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Android.App;
using Android.Content;
using Android.Views;
using Android.Widget;

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

using Com.EightbitLab.BlurViewBinding;

using BlurViewFormsSample;
using BlurViewFormsSample.Droid;

[assembly: ExportRenderer(typeof(FormsBlurView), typeof(FormsBlurViewRenderer))]

namespace BlurViewFormsSample.Droid
{
public class FormsBlurViewRenderer : ViewRenderer<FormsBlurView, FrameLayout>
{
public FormsBlurViewRenderer(Context context) : base(context)
{
}

protected override void OnElementChanged(ElementChangedEventArgs<FormsBlurView> e)
{
base.OnElementChanged(e);

if (Control == null)
{
var context = Context;
var activity = context as Activity;

var rootView = (ViewGroup) activity.Window.DecorView.FindViewById(Android.Resource.Id.Content);
var windowBackground = activity.Window.DecorView.Background;

var blurView = new BlurView(context);

blurView.SetOverlayColor(Resource.Color.colorOverlay);

blurView.SetupWith(rootView)
.WindowBackground(windowBackground)
.BlurAlgorithm(new RenderScriptBlur(context))
.BlurRadius(10f);

SetNativeControl(blurView);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace BlurViewFormsSample
{
public class FormsBlurView : StackLayout
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,26 @@
xmlns:local="clr-namespace:BlurViewFormsSample"
x:Class="BlurViewFormsSample.MainPage">

<ScrollView>
<StackLayout BackgroundColor="Red">
<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />

<local:FormsBlurView HeightRequest="100">
<Label Text="Test Text" />
<Button Text="Click me!" />
</local:FormsBlurView>

<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
<BoxView BackgroundColor="Blue" HeightRequest="100" />
</StackLayout>
</ScrollView>

</ContentPage>

0 comments on commit 50c71e4

Please sign in to comment.