|
1 | 1 | package com.cmcewen.blurview;
|
2 | 2 |
|
| 3 | +import android.graphics.drawable.Drawable; |
3 | 4 | import android.view.View;
|
| 5 | +import android.view.ViewGroup; |
4 | 6 |
|
| 7 | +import com.facebook.react.uimanager.ViewGroupManager; |
5 | 8 | import com.facebook.react.uimanager.SimpleViewManager;
|
6 | 9 | import com.facebook.react.uimanager.ThemedReactContext;
|
7 | 10 | import com.facebook.react.uimanager.annotations.ReactProp;
|
8 | 11 |
|
| 12 | +import java.util.Objects; |
| 13 | + |
9 | 14 | import javax.annotation.Nonnull;
|
10 | 15 |
|
| 16 | +import eightbitlab.com.blurview.BlurView; |
| 17 | +import eightbitlab.com.blurview.RenderScriptBlur; |
| 18 | + |
11 | 19 |
|
12 | 20 | @SuppressWarnings("unused")
|
13 |
| -class BlurViewManager extends SimpleViewManager<BlurringView> { |
| 21 | +class BlurViewManager extends ViewGroupManager<BlurView> { |
14 | 22 | private static final String REACT_CLASS = "BlurView";
|
15 | 23 |
|
16 | 24 | private static final int defaultRadius = 10;
|
17 | 25 | private static final int defaultSampling = 10;
|
18 | 26 |
|
19 |
| - private static ThemedReactContext context; |
20 |
| - |
21 | 27 | @Override
|
22 | 28 | public @Nonnull String getName() {
|
23 | 29 | return REACT_CLASS;
|
24 | 30 | }
|
25 | 31 |
|
26 | 32 | @Override
|
27 |
| - public @Nonnull BlurringView createViewInstance(@Nonnull ThemedReactContext ctx) { |
28 |
| - context = ctx; |
29 |
| - |
30 |
| - BlurringView blurringView = new BlurringView(ctx); |
31 |
| - blurringView.setBlurRadius(defaultRadius); |
32 |
| - blurringView.setDownsampleFactor(defaultSampling); |
33 |
| - return blurringView; |
| 33 | + public @Nonnull BlurView createViewInstance(@Nonnull ThemedReactContext ctx) { |
| 34 | + BlurView blurView = new BlurView(ctx); |
| 35 | + View decorView = Objects.requireNonNull(ctx.getCurrentActivity()).getWindow().getDecorView(); |
| 36 | + ViewGroup rootView = decorView.findViewById(android.R.id.content); |
| 37 | + Drawable windowBackground = decorView.getBackground(); |
| 38 | + blurView.setupWith(rootView) |
| 39 | + .setFrameClearDrawable(windowBackground) |
| 40 | + .setBlurAlgorithm(new RenderScriptBlur(ctx)) |
| 41 | + .setBlurRadius(defaultRadius) |
| 42 | + .setHasFixedTransformationMatrix(false); |
| 43 | + return blurView; |
34 | 44 | }
|
35 | 45 |
|
36 | 46 | @ReactProp(name = "blurRadius", defaultInt = defaultRadius)
|
37 |
| - public void setRadius(BlurringView view, int radius) { |
| 47 | + public void setRadius(BlurView view, int radius) { |
38 | 48 | view.setBlurRadius(radius);
|
39 | 49 | view.invalidate();
|
40 | 50 | }
|
41 | 51 |
|
42 | 52 | @ReactProp(name = "overlayColor", customType = "Color")
|
43 |
| - public void setColor(BlurringView view, int color) { |
| 53 | + public void setColor(BlurView view, int color) { |
44 | 54 | view.setOverlayColor(color);
|
45 | 55 | view.invalidate();
|
46 | 56 | }
|
47 | 57 |
|
48 | 58 | @ReactProp(name = "downsampleFactor", defaultInt = defaultSampling)
|
49 |
| - public void setDownsampleFactor(BlurringView view, int factor) { |
50 |
| - view.setDownsampleFactor(factor); |
51 |
| - } |
52 |
| - |
53 |
| - @ReactProp(name = "viewRef") |
54 |
| - public void setViewRef(BlurringView view, int viewRef) { |
55 |
| - if (context != null && context.getCurrentActivity() != null) { |
56 |
| - View viewToBlur = context.getCurrentActivity().findViewById(viewRef); |
| 59 | + public void setDownsampleFactor(BlurView view, int factor) { |
57 | 60 |
|
58 |
| - if (viewToBlur != null) { |
59 |
| - view.setBlurredView(viewToBlur); |
60 |
| - } |
61 |
| - } |
62 | 61 | }
|
63 | 62 | }
|
0 commit comments