2019-03-26 19:18:58 +00:00
# `@react-native-community/blur`
2016-09-26 06:57:31 +00:00
2019-03-26 19:18:58 +00:00
[![npm version ](https://badge.fury.io/js/%40react-native-community%2Fblur.svg )](https://badge.fury.io/js/%40react-native-community%2Fblur)
2015-10-05 20:47:33 +00:00
2020-03-04 17:46:11 +00:00
A component for UIVisualEffectView's blur and vibrancy effect on iOS, and [BlurView ](https://github.com/Dimezis/BlurView ) on Android.< br >
2017-04-17 15:28:34 +00:00
< img src = 'https://cloud.githubusercontent.com/assets/139536/25066337/3c9d44c0-224d-11e7-8ca6-028478bf4a7d.gif' / >
2015-10-05 20:47:33 +00:00
### Content
2017-04-17 15:28:34 +00:00
2015-10-05 20:47:33 +00:00
- [Installation ](#installation )
2017-04-17 15:28:34 +00:00
- [BlurView ](#blurview )
- [VibrancyView ](#vibrancyview )
- [Example React Native app ](#example-react-native-app )
2015-10-05 20:47:33 +00:00
- [Questions? ](#questions )
### Installation
2017-04-17 15:28:34 +00:00
2019-03-27 12:37:52 +00:00
1. Install the library using either Yarn:
2015-10-05 22:19:51 +00:00
2019-03-26 18:19:21 +00:00
```
2019-03-27 12:37:52 +00:00
yarn add @react -native-community/blur
```
or npm:
```
npm install --save @react -native-community/blur
2019-03-26 18:19:21 +00:00
```
2015-10-05 22:19:51 +00:00
2016-12-09 21:59:34 +00:00
2. Link your native dependencies:
2019-03-26 18:19:21 +00:00
```
2019-03-27 12:37:52 +00:00
react-native link @react -native-community/blur
2019-03-26 18:19:21 +00:00
```
2017-04-10 17:07:13 +00:00
2019-08-27 04:09:34 +00:00
3. (iOS only) Install to Xcode:
```
cd ios
pod install
```
2019-12-27 08:41:00 +00:00
4. (Android only, optional)
2019-03-26 19:02:28 +00:00
If you've defined _[project-wide properties](https://developer.android.com/studio/build/gradle-tips.html)_ (**recommended**) in your root `build.gradle` , this library will detect the presence of the following properties:
```groovy
buildscript {...}
allprojects {...}
/**
+ Project-wide Gradle configuration properties
*/
ext {
compileSdkVersion = 27
targetSdkVersion = 27
buildToolsVersion = "27.0.3"
}
```
2019-12-27 08:41:00 +00:00
5. Include the library in your code:
2015-10-05 20:53:37 +00:00
2019-03-26 18:19:21 +00:00
```javascript
2019-03-27 12:56:38 +00:00
import { BlurView, VibrancyView } from "@react-native-community/blur";
2019-03-26 18:19:21 +00:00
```
2015-10-05 20:53:37 +00:00
2019-12-27 08:41:00 +00:00
6. Compile and have fun!
2015-10-05 20:47:33 +00:00
2017-04-17 15:28:34 +00:00
### BlurView
**Properties:**
- `blurType` (String)
- `xlight` - extra light blur type
- `light` - light blur type
- `dark` - dark blur type
2017-06-26 12:43:33 +00:00
- `extraDark` - extra dark blur type (tvOS only)
2019-03-26 17:53:50 +00:00
- `regular` - regular blur type (iOS 10+ and tvOS only)
- `prominent` - prominent blur type (iOS 10+ and tvOS only)
2020-01-18 08:58:52 +00:00
- iOS 13 only Blur types:
- `chromeMaterial` - An adaptable blur effect that creates the appearance of the system chrome.
- `material` - An adaptable blur effect that creates the appearance of a material with normal thickness.
- `thickMaterial` - An adaptable blur effect that creates the appearance of a material that is thicker than normal.
- `thinMaterial` - An adaptable blur effect that creates the appearance of an ultra-thin material.
- `ultraThinMaterial` - An adaptable blur effect that creates the appearance of an ultra-thin material.
- `chromeMaterialDark` - A blur effect that creates the appearance of an ultra-thin material and is always dark.
- `materialDark` - A blur effect that creates the appearance of a thin material and is always dark.
- `thickMaterialDark` - A blur effect that creates the appearance of a material with normal thickness and is always dark.
- `thinMaterialDark` - A blur effect that creates the appearance of a material that is thicker than normal and is always dark.
- `ultraThinMaterialDark` - A blur effect that creates the appearance of the system chrome and is always dark.
- `chromeMaterialLight` - An adaptable blur effect that creates the appearance of the system chrome.
- `materialLight` - An adaptable blur effect that creates the appearance of a material with normal thickness.
- `thickMaterialLight` - An adaptable blur effect that creates the appearance of a material that is thicker than normal.
- `thinMaterialLight` - An adaptable blur effect that creates the appearance of a thin material.
- `ultraThinMaterialLight` - An adaptable blur effect that creates the appearance of an ultra-thin material.
2017-04-17 15:28:34 +00:00
- `blurAmount` (Default: 10, Number)
- `0-100` - Adjusts blur intensity
> Note: The maximum `blurAmount` on Android is 32, so higher values will be clamped to 32.
> Complete usage example that works on iOS and Android:
```javascript
2019-03-26 18:19:21 +00:00
import React, { Component } from "react";
2020-03-04 17:46:11 +00:00
import { View, Image, Text, StyleSheet } from "react-native";
2019-03-27 12:56:38 +00:00
import { BlurView } from "@react-native-community/blur";
2017-04-17 15:28:34 +00:00
export default class Menu extends Component {
render() {
return (
< View style = {styles.container} >
2020-04-01 11:48:12 +00:00
< Image
key={'blurryImage'}
source={{ uri }}
style={styles.absolute}
/>
< Text style = {styles.absolute} > Hi, I am some blurred text< / Text >
{/* in terms of positioning and zIndex-ing everything before the BlurView will be blurred */}
2017-04-17 15:28:34 +00:00
< BlurView
style={styles.absolute}
viewRef={this.state.viewRef}
blurType="light"
blurAmount={10}
2019-03-26 17:54:20 +00:00
/>
2020-04-01 11:48:12 +00:00
< Text > I'm the non blurred text because I got rendered on top of the BlurView< / Text >
2017-04-17 15:28:34 +00:00
< / View >
);
}
}
const styles = StyleSheet.create({
container: {
2019-03-26 18:19:21 +00:00
justifyContent: "center",
alignItems: "center"
2017-04-17 15:28:34 +00:00
},
absolute: {
position: "absolute",
2019-03-26 18:19:21 +00:00
top: 0,
left: 0,
bottom: 0,
right: 0
}
2017-04-17 15:28:34 +00:00
});
```
In this example, the `Image` component will be blurred, because the `BlurView` in positioned on top. But the `Text` will stay unblurred.
### VibrancyView
**Uses the same properties as `BlurView` (`blurType` and `blurAmount` ).**
> The vibrancy effect lets the content underneath a blurred view show through more vibrantly
> (Note: `VibrancyView` is only supported on iOS. Also note that the `VibrancyView` must contain nested views.)
2017-04-10 16:55:58 +00:00
2017-04-17 15:28:34 +00:00
```javascript
2019-03-27 12:56:38 +00:00
import { VibrancyView } from "@react-native-community/blur";
2017-04-17 15:28:34 +00:00
export default class Menu extends Component {
render() {
return (
2019-03-26 18:19:21 +00:00
< Image source = {{ uri } } style = {styles.absolute} >
2017-04-17 15:28:34 +00:00
< VibrancyView blurType = "light" style = {styles.flex} >
< Text > Hi, I am some vibrant text.< / Text >
< / VibrancyView >
< / Image >
);
}
}
```
### Android
2020-03-04 17:46:11 +00:00
Android uses the [BlurView ](https://github.com/Dimezis/BlurView ).
2017-04-17 15:28:34 +00:00
If you only need to support iOS, then you can safely ignore these limitations.
In addition to `blurType` and `blurAmount` , Android has some extra props that can be used to override the default behavior (or configure Android-specific behavior):
2019-03-26 18:19:21 +00:00
- `blurRadius` (Number - between 0 and 25) - Manually adjust the blur radius. (Default: matches iOS blurAmount)
2017-04-17 15:28:34 +00:00
- `downsampleFactor` (Number - between 0 and 25) - Scales down the image before blurring (Default: matches iOS blurAmount)
2019-03-26 18:19:21 +00:00
- `overlayColor` (Color) - Set a custom overlay color (Default color based on iOS blurType)
2017-04-17 15:28:34 +00:00
### Example React Native App
This project includes an example React Native app, which was used to make the GIF in this README.
You can run the apps by following these steps:
2017-04-10 16:55:58 +00:00
1. Clone the repository
```
cd ~
git clone https://github.com/react-native-community/react-native-blur.git
```
2019-03-26 18:52:44 +00:00
2. cd to `example`
2017-04-10 16:55:58 +00:00
```
2019-03-26 18:52:44 +00:00
cd react-native-blur/example
2017-04-10 16:55:58 +00:00
```
3. Install dependencies
```
npm install
```
4. Run the apps:
#### Run the iOS app
```
react-native run-ios
```
2017-07-09 21:38:50 +00:00
#### Run the tvOS app
type:
2019-03-26 18:19:21 +00:00
2017-07-09 21:38:50 +00:00
```
react-native run-ios
```
`react-native link` don’ t works properly with the tvOS target so we need to add the library manually.
First select your project in Xcode.
< img src = "./docs/tvOS-step-1.jpg" width = "40%" >
After that, select the tvOS target of your application and select « General » tab
< img src = "./docs/tvOS-step-2.jpg" width = "40%" >
Scroll to « Linked Frameworks and Libraries » and tap on the + button
< img src = "./docs/tvOS-step-3.jpg" width = "40%" >
Select RNBlur-tvOS
< img src = "./docs/tvOS-step-4.jpg" width = "40%" >
That’ s all, you can use react-native-blur for your tvOS application
2017-04-10 16:55:58 +00:00
#### Run the Android app
```
react-native run-android
```
2015-10-05 20:47:33 +00:00
2017-04-17 15:28:34 +00:00
### Troubleshooting
2017-04-10 16:55:58 +00:00
2016-08-20 14:32:22 +00:00
On older instances of react-native, BlurView package does not get added into the MainActivity/MainApplication classes where you would see `Warning: Native component for 'BlurView' does not exist` in RN YellowBox or console.
To rectify this, you can add the BlurViewPackage manually in MainActivity/MainApplication classes
2019-03-26 18:19:21 +00:00
2016-08-20 14:32:22 +00:00
```java
...
import com.cmcewen.blurview.BlurViewPackage;
...
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List< ReactPackage > getPackages() {
return Arrays.< ReactPackage > asList(
2016-10-28 01:52:26 +00:00
new MainReactPackage(),
2016-08-20 14:32:22 +00:00
new BlurViewPackage()
);
}
...
}
```
2015-10-05 20:47:33 +00:00
### Questions?
2017-04-17 15:28:34 +00:00
2019-08-27 04:08:28 +00:00
Feel free to contact me on [twitter ](https://twitter.com/kureevalexey ) or [create an issue ](https://github.com/Kureev/react-native-blur/issues/new )