Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@react-native-community/blur
Advanced tools
@react-native-community/blur is a React Native package that provides a BlurView component to create blur effects on views. It is useful for creating visually appealing UI elements by applying a blur effect to background images or views.
Basic Blur Effect
This code demonstrates how to apply a basic blur effect to an image using the BlurView component. The blurType prop specifies the type of blur (e.g., light, dark), and the blurAmount prop specifies the intensity of the blur.
import React from 'react';
import { View, Image, StyleSheet } from 'react-native';
import { BlurView } from '@react-native-community/blur';
const App = () => {
return (
<View style={styles.container}>
<Image source={{ uri: 'https://example.com/image.jpg' }} style={styles.image} />
<BlurView style={styles.absolute} blurType="light" blurAmount={10} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
image: {
width: 300,
height: 300,
},
absolute: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
},
});
export default App;
Dynamic Blur Effect
This code demonstrates how to create a dynamic blur effect where the blur intensity can be adjusted using a slider. The blurAmount state is updated based on the slider's value, and the BlurView component's blurAmount prop is set accordingly.
import React, { useState } from 'react';
import { View, Image, Slider, StyleSheet } from 'react-native';
import { BlurView } from '@react-native-community/blur';
const App = () => {
const [blurAmount, setBlurAmount] = useState(10);
return (
<View style={styles.container}>
<Image source={{ uri: 'https://example.com/image.jpg' }} style={styles.image} />
<BlurView style={styles.absolute} blurType="light" blurAmount={blurAmount} />
<Slider
style={styles.slider}
minimumValue={0}
maximumValue={20}
value={blurAmount}
onValueChange={setBlurAmount}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
image: {
width: 300,
height: 300,
},
absolute: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
},
slider: {
position: 'absolute',
bottom: 50,
width: 300,
},
});
export default App;
react-native-blur is another package that provides a BlurView component for React Native applications. It offers similar functionality to @react-native-community/blur, allowing developers to apply blur effects to views. However, @react-native-community/blur is more actively maintained and has better support for the latest React Native versions.
expo-blur is a package provided by Expo that offers a BlurView component for creating blur effects. It is part of the Expo ecosystem, making it easy to integrate with other Expo modules. Compared to @react-native-community/blur, expo-blur is more suitable for projects that are already using Expo.
@react-native-community/blur
A component for UIVisualEffectView's blur and vibrancy effect on iOS, and BlurView on Android.
yarn add @react-native-community/blur
Install native dependencies (iOS only):
cd ios && pod install
Property | Possible Values | Default | Platform |
---|---|---|---|
blurType | See blurType below | - | All |
blurAmount | 0 - 100 (The maximum blurAmount on Android is 32, so higher values will be clamped to 32) | 10 | All |
reducedTransparencyFallbackColor | Any color | - | iOS only |
blurRadius | 0 - 25 | Matches iOS blurAmount | Android only |
downsampleFactor | 0 - 25 | Matches iOS blurAmount | Android only |
overlayColor | Any color | Default color based on iOS blurType | Android only |
Name | Description |
---|---|
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) |
Name | Description |
---|---|
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. |
chromeMaterial | An adaptable blur effect that creates the appearance of the system chrome. |
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. |
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 function Menu() {
return (
<View style={styles.container}>
<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 */}
<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
}
});
In this example, the Image
component will be blurred, because the BlurView
in positioned on top. But the Text
will stay unblurred.
If the accessibility setting Reduce Transparency
is enabled the BlurView
will use reducedTransparencyFallbackColor
as it's background color rather than blurring. If no reducedTransparencyFallbackColor
is provided, theBlurView
will use the default fallback color (white, black, or grey depending on blurType
)
Uses the same properties as BlurView
(blurType
, blurAmount
, and reducedTransparencyFallbackColor
).
The vibrancy effect lets the content underneath a blurred view show through more vibrantly
VibrancyView is only supported on iOS. Also note that the VibrancyView must contain nested views
import { VibrancyView } from "@react-native-community/blur";
export default function Menu() {
return (
<Image source={{ uri }} style={styles.absolute}>
<VibrancyView blurType="light" style={styles.flex}>
<Text>Hi, I am some vibrant text.</Text>
</VibrancyView>
</Image>
)
}
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:
Clone the repository
git clone https://github.com/react-native-community/react-native-blur.git
Install dependencies
yarn
yarn example android/ios
Feel free to create an issue
FAQs
React Native Blur component
The npm package @react-native-community/blur receives a total of 106,791 weekly downloads. As such, @react-native-community/blur popularity was classified as popular.
We found that @react-native-community/blur demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.