how to make the blur effect with react-native?

前端 未结 8 2058
春和景丽
春和景丽 2020-12-24 05:03

how to make the blur effect with react-native ? like \'background-image\'

and i want to switch the effect \'blur\' and \'none\',\'none\' means no blur effe

相关标签:
8条回答
  • 2020-12-24 05:22

    Anyone who is trying to blur a video view in react native android, would not be able to do so with the libraries available at the time of writing this answer. But I achieved this effect by using WebView as a frame for the video. Write a little HTML page with video tag in it and style it as per your requirement and then add CSS filter property with blur as it's value, to the style of video tag. Create some javascript functions as well to play and pause the video (they'll be just one liners) which you can call from react-native code using WebView's injectJavaScript() method. You can add this html code directly to the WebView using html property of source probe of WebView component. This is obviously a hacky solution, and it won't be as fast as the native one. If you want to apply some animations or do something with layout of video, then do it with the WebView component in react-native code, that would be as fast other react-native components.

    0 讨论(0)
  • 2020-12-24 05:23

    If you created your app using CRNA i.e, using expo. You can use BlurView from expo.

    import {BlurView} from 'expo';

    It got two props to control the blur effect.

    tint which takes string value namely light, default, or dark. and intensity which ranges from 1 to 100

    0 讨论(0)
  • 2020-12-24 05:24

    Now you can do this without any library using the prop: blurRadius.

    E.g

    <Image
        style={styles.img}
        resizeMode='cover'
        source={imgSrc} 
        blurRadius={1}
    />
    

    Explanation: the number(1) means the amount of blur you want to apply on the image, the higher the number, the blurrier the image.

    Unfortunately, this doesn't work on Android yet (RN 0.40.0). Nevertheless, it could be useful to who's looking for only an iOS solution.

    Edit: It seems to be working on Android now.

    0 讨论(0)
  • 2020-12-24 05:32

    With recent React native version (0.57) you can use blurRadius, it works both iOS and Android http://facebook.github.io/react-native/docs/image#blurradius

    0 讨论(0)
  • 2020-12-24 05:33

    Install react-native-blur:

    npm install react-native-blur
    
    import BlurView from 'react-native-blur';
    
    ...
    <BlurView blurType="light" style={styles.blur}>
    ...
    
    0 讨论(0)
  • 2020-12-24 05:33

    Try this blurry library.

    dependencies :: compile 'jp.wasabeef:blurry:2.0.2'

    https://github.com/wasabeef/Blurry

    0 讨论(0)
提交回复
热议问题