React Native Blur component
Go to file
Alexey Kureev e2075520c7
Fix the example project (#361)
2020-03-10 23:19:19 +00:00
.vscode Configure Eslint & Prettier (#302) 2019-03-26 14:19:21 -04:00
android Feat/eightbitlab blurview (#358) 2020-03-04 17:46:11 +00:00
docs [tvOS] Update README.MD (#220) 2017-07-09 23:38:50 +02:00
example Fix the example project (#361) 2020-03-10 23:19:19 +00:00
ios Enable regular and prominent BlurEffectStyles for iOS 10.0+ (#276) 2019-03-26 13:53:50 -04:00
src Feat/eightbitlab blurview (#358) 2020-03-04 17:46:11 +00:00
.eslintrc Configure Eslint & Prettier (#302) 2019-03-26 14:19:21 -04:00
.flowconfig Rebuild react-native-blur for RN-0.11.4 2015-10-05 22:42:23 +02:00
.gitignore Update .gitignore 2017-07-09 23:39:18 +02:00
.npmignore Regenerate example app (#303) 2019-03-26 14:52:44 -04:00
.prettierrc Configure Eslint & Prettier (#302) 2019-03-26 14:19:21 -04:00
.watchmanconfig Rebuild react-native-blur for RN-0.11.4 2015-10-05 22:42:23 +02:00
LICENSE Create LICENSE 2016-11-06 16:25:50 +01:00
README.md Feat/eightbitlab blurview (#358) 2020-03-04 17:46:11 +00:00
index.d.ts Feat/eightbitlab blurview (#358) 2020-03-04 17:46:11 +00:00
index.js Modernize imports and lifecycles (#304) 2019-03-26 14:56:31 -04:00
index.js.flow Feat/eightbitlab blurview (#358) 2020-03-04 17:46:11 +00:00
package.json Feat/eightbitlab blurview (#358) 2020-03-04 17:46:11 +00:00
react-native-blur.podspec Use the correct urls for issues, homepage & repo (#221) 2017-07-10 15:23:25 +02:00
yarn.lock chore: fix linting 2019-11-08 23:32:40 +02:00

README.md

@react-native-community/blur

npm version

A component for UIVisualEffectView's blur and vibrancy effect on iOS, and BlurView on Android.

Content

Installation

  1. Install the library using either Yarn:
yarn add @react-native-community/blur

or npm:

npm install --save @react-native-community/blur
  1. Link your native dependencies:
react-native link @react-native-community/blur
  1. (iOS only) Install to Xcode:
cd ios
pod install
  1. (Android only) Add the following to android/app/build.gradle
android {
    // make sure to use 23.0.3 or greater
    buildToolsVersion '23.0.3'

    // ...
    defaultConfig {
        // Add these lines below the existing config
        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
    }
}
  1. (Android only, optional) If you've defined project-wide properties (recommended) in your root build.gradle, this library will detect the presence of the following properties:
buildscript {...}
allprojects {...}

/**
  + Project-wide Gradle configuration properties
  */
ext {
    compileSdkVersion   = 27
    targetSdkVersion    = 27
    buildToolsVersion   = "27.0.3"
}
  1. Include the library in your code:
import { BlurView, VibrancyView } from "@react-native-community/blur";
  1. Compile and have fun!

BlurView

Properties:

  • blurType (String)
    • xlight - extra light blur type
    • light - light blur type
    • dark - dark blur type
    • extraDark - extra dark blur type (tvOS only)
    • regular - regular blur type (iOS 10+ and tvOS only)
    • prominent - prominent blur type (iOS 10+ and tvOS only)
  • 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:

import React, { Component } from "react";
import { View, Image, Text, StyleSheet } from "react-native";
import { BlurView } from "@react-native-community/blur";

export default class Menu extends Component {

  render() {
    return (
      <View style={styles.container}>
        <Text>Hi, I am some unblurred text</Text>
        <BlurView
          style={styles.absolute}
          viewRef={this.state.viewRef}
          blurType="light"
          blurAmount={10}
        >
          <Text>I'm the BlurView content on both iOS and Android</Text>
        </BlurView>
        <Image
          source={{ uri }}
          style={styles.absolute}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    justifyContent: "center",
    alignItems: "center"
  },
  absolute: {
    position: "absolute",
    top: 0,
    left: 0,
    bottom: 0,
    right: 0
  }
});

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.)

import { VibrancyView } from "@react-native-community/blur";

export default class Menu extends Component {
  render() {
    return (
      <Image source={{ uri }} style={styles.absolute}>
        <VibrancyView blurType="light" style={styles.flex}>
          <Text>Hi, I am some vibrant text.</Text>
        </VibrancyView>
      </Image>
    );
  }
}

Android

Android uses the BlurView.

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):

  • blurRadius (Number - between 0 and 25) - Manually adjust the blur radius. (Default: matches iOS blurAmount)
  • downsampleFactor (Number - between 0 and 25) - Scales down the image before blurring (Default: matches iOS blurAmount)
  • overlayColor (Color) - Set a custom overlay color (Default color based on iOS blurType)

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:

  1. Clone the repository
cd ~
git clone https://github.com/react-native-community/react-native-blur.git
  1. cd to example
cd react-native-blur/example
  1. Install dependencies
npm install
  1. Run the apps:

Run the iOS app

react-native run-ios

Run the tvOS app

type:

react-native run-ios

react-native link dont works properly with the tvOS target so we need to add the library manually.

First select your project in Xcode.

After that, select the tvOS target of your application and select « General » tab

Scroll to « Linked Frameworks and Libraries » and tap on the + button

Select RNBlur-tvOS

Thats all, you can use react-native-blur for your tvOS application

Run the Android app

react-native run-android

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 on twitter or create an issue