Skip to content

Commit 47a199e

Browse files
authored
Feat/eightbitlab blurview (Kureev#358)
* Update build.gradle * Update build.gradle * feat(android-blurview): migrate to com.eightbitlab.blurview * fix(types): proptypes and typescript - removed viewRef references * fix(offset): fixing offset on android * feat(harmonized-behavior): blurview can now have children on android - Same behavior on iOS and Android now * Update BlurView.android.js * Update index.js.flow * Create App.js * Delete App.android.js * Delete App.ios.js * Update README.md
1 parent dc00052 commit 47a199e

File tree

10 files changed

+72
-452
lines changed

10 files changed

+72
-452
lines changed

README.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![npm version](https://badge.fury.io/js/%40react-native-community%2Fblur.svg)](https://badge.fury.io/js/%40react-native-community%2Fblur)
44

5-
A component for UIVisualEffectView's blur and vibrancy effect on iOS, and [500px-android-blur](https://github.com/500px/500px-android-blur) on Android.<br>
5+
A component for UIVisualEffectView's blur and vibrancy effect on iOS, and [BlurView](https://github.com/Dimezis/BlurView) on Android.<br>
66

77
<img src='https://cloud.githubusercontent.com/assets/139536/25066337/3c9d44c0-224d-11e7-8ca6-028478bf4a7d.gif' />
88

@@ -102,18 +102,10 @@ import { BlurView, VibrancyView } from "@react-native-community/blur";
102102
103103
```javascript
104104
import React, { Component } from "react";
105-
import { View, Image, Text, findNodeHandle, StyleSheet } from "react-native";
105+
import { View, Image, Text, StyleSheet } from "react-native";
106106
import { BlurView } from "@react-native-community/blur";
107107

108108
export default class Menu extends Component {
109-
constructor(props) {
110-
super(props);
111-
this.state = { viewRef: null };
112-
}
113-
114-
imageLoaded() {
115-
this.setState({ viewRef: findNodeHandle(this.backgroundImage) });
116-
}
117109

118110
render() {
119111
return (
@@ -124,14 +116,12 @@ export default class Menu extends Component {
124116
viewRef={this.state.viewRef}
125117
blurType="light"
126118
blurAmount={10}
127-
/>
119+
>
120+
<Text>I'm the BlurView content on both iOS and Android</Text>
121+
</BlurView>
128122
<Image
129-
ref={img => {
130-
this.backgroundImage = img;
131-
}}
132123
source={{ uri }}
133124
style={styles.absolute}
134-
onLoadEnd={this.imageLoaded.bind(this)}
135125
/>
136126
</View>
137127
);
@@ -155,8 +145,6 @@ const styles = StyleSheet.create({
155145
156146
In this example, the `Image` component will be blurred, because the `BlurView` in positioned on top. But the `Text` will stay unblurred.
157147
158-
Note that `viewRef` is only required if you need to support Android. See the [Android section](#android) for more details.
159-
160148
### VibrancyView
161149
162150
**Uses the same properties as `BlurView` (`blurType` and `blurAmount`).**
@@ -183,12 +171,7 @@ export default class Menu extends Component {
183171
184172
### Android
185173
186-
Android uses the [500px-android-blur](https://github.com/500px/500px-android-blur) library, which works by blurring a referenced view. This means that you must wait until the view you want to blur is rendered. You then use `findNodeHandle` to get a reference to that view, and pass that reference to the `BlurView` as the `viewRef` prop. Take a look at [the BlurView example](#blurview) to see how it works.
187-
188-
The Android library introduces some limitations:
189-
190-
- `BlurView` cannot be a child of the view that is being blurred (this would cause an infinite loop)
191-
- `BlurView` cannot contain any child components.
174+
Android uses the [BlurView](https://github.com/Dimezis/BlurView).
192175
193176
If you only need to support iOS, then you can safely ignore these limitations.
194177

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ repositories {
4040
dependencies {
4141
//noinspection GradleDynamicVersion
4242
implementation 'com.facebook.react:react-native:+'
43+
implementation 'com.eightbitlab:blurview:1.6.3'
4344
}
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,62 @@
11
package com.cmcewen.blurview;
22

3+
import android.graphics.drawable.Drawable;
34
import android.view.View;
5+
import android.view.ViewGroup;
46

7+
import com.facebook.react.uimanager.ViewGroupManager;
58
import com.facebook.react.uimanager.SimpleViewManager;
69
import com.facebook.react.uimanager.ThemedReactContext;
710
import com.facebook.react.uimanager.annotations.ReactProp;
811

12+
import java.util.Objects;
13+
914
import javax.annotation.Nonnull;
1015

16+
import eightbitlab.com.blurview.BlurView;
17+
import eightbitlab.com.blurview.RenderScriptBlur;
18+
1119

1220
@SuppressWarnings("unused")
13-
class BlurViewManager extends SimpleViewManager<BlurringView> {
21+
class BlurViewManager extends ViewGroupManager<BlurView> {
1422
private static final String REACT_CLASS = "BlurView";
1523

1624
private static final int defaultRadius = 10;
1725
private static final int defaultSampling = 10;
1826

19-
private static ThemedReactContext context;
20-
2127
@Override
2228
public @Nonnull String getName() {
2329
return REACT_CLASS;
2430
}
2531

2632
@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;
3444
}
3545

3646
@ReactProp(name = "blurRadius", defaultInt = defaultRadius)
37-
public void setRadius(BlurringView view, int radius) {
47+
public void setRadius(BlurView view, int radius) {
3848
view.setBlurRadius(radius);
3949
view.invalidate();
4050
}
4151

4252
@ReactProp(name = "overlayColor", customType = "Color")
43-
public void setColor(BlurringView view, int color) {
53+
public void setColor(BlurView view, int color) {
4454
view.setOverlayColor(color);
4555
view.invalidate();
4656
}
4757

4858
@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) {
5760

58-
if (viewToBlur != null) {
59-
view.setBlurredView(viewToBlur);
60-
}
61-
}
6261
}
6362
}

android/src/main/java/com/cmcewen/blurview/BlurringView.java

Lines changed: 0 additions & 209 deletions
This file was deleted.

0 commit comments

Comments
 (0)