1
1
package com .cmcewen .blurview ;
2
2
3
+ import android .app .Activity ;
3
4
import android .graphics .drawable .Drawable ;
4
5
import android .view .View ;
5
6
import android .view .ViewGroup ;
6
7
7
8
import com .facebook .react .uimanager .ViewGroupManager ;
8
- import com .facebook .react .uimanager .SimpleViewManager ;
9
9
import com .facebook .react .uimanager .ThemedReactContext ;
10
10
import com .facebook .react .uimanager .annotations .ReactProp ;
11
11
12
- import java .util .Objects ;
13
-
14
12
import javax .annotation .Nonnull ;
15
13
16
14
import eightbitlab .com .blurview .BlurView ;
@@ -32,14 +30,17 @@ class BlurViewManager extends ViewGroupManager<BlurView> {
32
30
@ Override
33
31
public @ Nonnull BlurView createViewInstance (@ Nonnull ThemedReactContext ctx ) {
34
32
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 );
33
+ Activity currentActivity = ctx .getCurrentActivity ();
34
+ if (currentActivity != null ) {
35
+ View decorView = currentActivity .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
+ }
43
44
return blurView ;
44
45
}
45
46
0 commit comments