@react-native-community/blur

repository·master·Indexed 26 days ago

https://github.com/margelo/react-native-blur

A React Native component providing high-performance blur and vibrancy effects. It utilizes UIVisualEffectView on iOS and BlurView on Android. The library includes a BlurView component for both platforms and a VibrancyView component exclusively for iOS. Key configurations include blurType, blurAmount, and platform-specific properties like blurRadius and downsampleFactor for Android, and reducedTransparencyFallbackColor for iOS.

Tokens
2.9K
Snippets
7
Records
18
Agent score
85%

What's inside @react-native-community/blur

  1. Run the Example App

    master

    To run the included example project, clone the repository, install dependencies, and use the provided yarn command.

    git clone https://github.com/react-native-community/react-native-blur.git
    cd react-native-blur
    yarn
    yarn example android/ios
  2. Use the BlurView component

    master

    The BlurView component provides blur effects on iOS (using UIVisualEffectView) and Android (using BlurView). To blur content, position the BlurView on top of the elements you want to blur using absolute positioning.

    import React from "react";
    import { View, Image, Text, StyleSheet } from "react-native";
    import { BlurView } from "@react-native-community/blur";
    
    export default function Menu() {
      return (
        <View style={styles.container}>
          <Image
            key={'blurryImage'}
            source={{ uri: 'https://example.com/image.png' }}
            style={styles.absolute}
          />
          <Text style={styles.absolute}>Hi, I am some blurred text</Text>
          {/* The BlurView will blur everything positioned behind it */}
          <BlurView
            style={styles.absolute}
            blurType="light"
            blurAmount={10}
            reducedTransparencyFallbackColor="white"
          />
          <Text>I'm the non blurred text because I got rendered on top of the BlurView</Text>
        </View>
      )
    }
    
    const styles = StyleSheet.create({
      container: {
        justifyContent: "center",
        alignItems: "center"
      },
      absolute: {
        position: "absolute",
        top: 0,
        left: 0,
        bottom: 0,
        right: 0
      }
    });
  3. Use the VibrancyView component (iOS only)

    master

    The VibrancyView component is supported on iOS only. It allows content underneath the view to show through more vibrantly. Note that VibrancyView must contain nested views to function correctly.

    import { VibrancyView } from "@react-native-community/blur";
    
    export default function Menu() {
      return (
        <Image source={{ uri: 'https://example.com/image.png' }} style={styles.absolute}>
          <VibrancyView blurType="light" style={styles.flex}>
            <Text>Hi, I am some vibrant text.</Text>
          </VibrancyView>
        </Image>
      )
    }
  4. Configure autolinking for @react-native-community/blur

    master

    When using this library in a monorepo or a project where the library source is located outside the application's root directory, you must configure the dependencies object in react-native.config.js. This ensures the React Native CLI can correctly locate the library's native source code for autolinking.

    Set the root property for @react-native-community/blur to the absolute path of the library's root directory.

    module.exports = {
      dependencies: {
        '@react-native-community/blur': {
          root: path.join(__dirname, '..'),
        },
      },
    };
  5. Configure blurType values

    master

    Available blurType values for general use:

    • xlight: extra light blur type
    • light: light blur type
    • dark: dark blur type
    • regular: regular blur type (iOS 10+ and tvOS only)
    • prominent: prominent blur type (iOS 10+ and tvOS only)
    • extraDark: extra dark blur type (tvOS only)
  6. Configure BlurView properties

    master

    The BlurView component accepts the following props:

    PropertyTypePlatformDescription
    blurTypestringAllThe type of blur effect to apply (see blurType)
    blurAmountnumber (0-100)AllIntensity of blur. Default is 10. Note: Android maximum is 32
    reducedTransparencyFallbackColorcoloriOS onlyColor used when the iOS 'Reduce Transparency' setting is enabled
    blurRadiusnumber (0-25)Android onlyRadius of the blur
    downsampleFactornumber (0-25)Android onlyDownsampling factor
    overlayColorcolorAndroid onlyOverlay color (defaults to color based on blurType)
  7. Configure blurType values for iOS 13+

    master

    iOS 13+ supports additional material-based blur types:

    • chromeMaterial / chromeMaterialLight / chromeMaterialDark
    • material / materialLight / materialDark
    • thickMaterial / thickMaterialLight / thickMaterialDark
    • thinMaterial / thinMaterialLight / thinMaterialDark
    • ultraThinMaterial / ultraThinMaterialLight / ultraThinMaterialDark
  8. Configure BlurViewProps for Android

    master

    When using BlurView on Android, you can pass the following props to control the blurring effect. Note that Android uses a specific calculation where blurRadius and downsampleFactor are derived from blurAmount if not explicitly provided.

    Constraints & Behaviors:

    • blurRadius: Must not be greater than 25. If a value higher than 25 is provided, the component will throw an error. If blurAmount is used to calculate the radius, it is capped at 25.
    • blurType: Determines the default overlayColor if one is not provided. Available types are 'dark', 'light', and 'xlight'.
    • overlayColor: A string representing the color overlay. If not provided, it defaults based on blurType.
    • downsampleFactor: If not provided, it defaults to the value of blurRadius.
    • Error Handling: The component listens for ReactNativeBlurError events via DeviceEventEmitter and re-throws them as standard JavaScript errors.
    type BlurViewProps = ViewProps & {
      blurAmount?: number;
      blurType?: 'dark' | 'light' | 'xlight';
      blurRadius?: number;
      downsampleFactor?: number;
      overlayColor?: string;
      enabled?: boolean;
      autoUpdate?: boolean;
    };
  9. Use the BlurView component on iOS

    master

    The BlurView component provides a blur effect for your views on iOS. It accepts several props to control the intensity and style of the blur.

    Props:

    • blurType (optional): Determines the visual style of the blur. Defaults to 'dark'.
    • blurAmount (optional): A number representing the blur intensity. Defaults to 10.
    • reducedTransparencyFallbackColor (optional): A color string used as a fallback when the user has enabled 'Reduce Transparency' in iOS settings.
    • style (optional): Standard React Native ViewStyle props.
    • ...rest: Any other standard ViewProps.