Fixed blur on Android

This commit is contained in:
Nathan Broadbent 2017-04-10 23:55:58 +07:00
parent 9629416b4b
commit a0802c0e99
2 changed files with 11 additions and 7 deletions

View File

@ -34,6 +34,6 @@ repositories {
} }
dependencies { dependencies {
compile 'com.facebook.react:react-native:0.19.+' compile 'com.facebook.react:react-native:0.41.+'
compile 'com.fivehundredpx:blurringview:1.0.0' compile 'com.fivehundredpx:blurringview:1.0.0'
} }

View File

@ -1,5 +1,6 @@
package com.cmcewen.blurview; package com.cmcewen.blurview;
import android.app.Activity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -14,6 +15,8 @@ public class BlurViewManager extends SimpleViewManager<BlurringView> {
public static final int defaultRadius = 10; public static final int defaultRadius = 10;
public static final int defaultSampling = 10; public static final int defaultSampling = 10;
private static Activity currentActivity;
@Override @Override
public String getName() { public String getName() {
return REACT_CLASS; return REACT_CLASS;
@ -21,6 +24,8 @@ public class BlurViewManager extends SimpleViewManager<BlurringView> {
@Override @Override
public BlurringView createViewInstance(ThemedReactContext context) { public BlurringView createViewInstance(ThemedReactContext context) {
currentActivity = context.getCurrentActivity();
BlurringView blurringView = new BlurringView(context); BlurringView blurringView = new BlurringView(context);
blurringView.setBlurRadius(defaultRadius); blurringView.setBlurRadius(defaultRadius);
blurringView.setDownsampleFactor(defaultSampling); blurringView.setDownsampleFactor(defaultSampling);
@ -44,12 +49,11 @@ public class BlurViewManager extends SimpleViewManager<BlurringView> {
@ReactProp(name = "viewRef") @ReactProp(name = "viewRef")
public void setViewRef(BlurringView view, int viewRef) { public void setViewRef(BlurringView view, int viewRef) {
ViewGroup viewGroup = (ViewGroup) view.getRootView().findViewById(viewRef); View blurredView = currentActivity.findViewById(viewRef);
if (viewGroup != null) {
View v = viewGroup.getChildAt(0); if (blurredView != null) {
view.setBlurredView(v); view.setBlurredView(blurredView);
view.invalidate(); view.invalidate();
} }
} }
} }