977e8820c1 | ||
---|---|---|
android | ||
examples/Basic | ||
ios | ||
src | ||
.eslintrc | ||
.flowconfig | ||
.gitignore | ||
.npmignore | ||
.watchmanconfig | ||
LICENSE | ||
README.md | ||
index.js | ||
package.json | ||
react-native-blur.podspec |
README.md
React Native Blur
Component implementation for UIVisualEffectView's blur and vibrancy effect.
Check the roadmap here
Content
Installation
- Install package via npm:
npm install react-native-blur
- Link your native dependencies:
react-native link react-native-blur
- Inside your code include JS part by adding
const { BlurView, VibrancyView } = require('react-native-blur');
- Compile and have fun!
Usage example
You can run built-in example via few simple steps:
- Clone repository
- Go to
examples/Basic
- Run
npm install && open Basic.xcodeproj
- Hit "Run"(
cmd+R
) button on XCode panel
Blur View
To use blur
view, you need to require BlurView
to your module and insert <BlurView>
tag inside render function as it's done below:
const { BlurView } = require('react-native-blur');
const Menu = React.createClass({
render() {
return (
<Image source={{uri}} style={styles.menu}>
<BlurView blurType="light" blurAmount={10} style={styles.blur}>
<Text>Hi, I am a tiny menu item</Text>
</BlurView>
</Image>
);
}
});
In this example, Image
component will be blurred, a BlurView
content will stay untouched.
Vibrancy View
The vibrancy effect lets the content underneath a blurred view show through more vibrantly
const { VibrancyView } = require('react-native-blur');
const Menu = React.createClass({
render() {
return (
<Image source={{uri}} style={styles.menu}>
<VibrancyView blurType="light" style={styles.blur}>
<Text>Hi, I am a tiny menu item</Text>
</VibrancyView>
</Image>
);
}
});
Component properties
blurType
(String) - blur type effectxlight
- extra light blur typelight
- light blur typedark
- dark blur type
blurAmount
(Default: 10, Number) - blur amount effect0-100
- Adjusts blur intensity
Note: blurAmount
does not refresh with Hot Reloading. You must a refresh the app to view the results of the changes
Android
Android support uses an external library which has slightly different properties and setup requirements. You must add the following to the android/app/build.gradle
file:
android {
...
defaultConfig {
...
renderscriptTargetApi 20
renderscriptSupportModeEnabled true
}
}
repositories {
maven { url 'https://github.com/500px/500px-android-blur/raw/master/releases/' }
}
dependencies {
...
compile project(':react-native-blur')
}
buildscript {
repositories {
maven { url 'https://github.com/500px/500px-android-blur/raw/master/releases/' }
}
dependencies {
classpath 'com.fivehundredpx:blurringview:1.0.0'
}
}
The android BlurView works by blurring an existing referenced view, so you must wait till the view you want to blur is rendered and then provide the reference to the BlurView as the viewRef
prop. Take a look at the example to see how it works.
It has the following props:
viewRef
(Number) - a reference to the existing view you want to blurblurRadius
(Number)downsampleFactor
(Number)overlayColor
(Color)
Troubleshooting
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
...
import com.cmcewen.blurview.BlurViewPackage;
...
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new BlurViewPackage()
);
}
...
}
Questions?
Feel free to contact me in twitter or create an issue