react-native-blur icon indicating copy to clipboard operation
react-native-blur copied to clipboard

[Android] view ref not blurring

Open stantoncbradley opened this issue 6 years ago • 5 comments

Experiencing weird behavior on Android... following android example, it appears the text view is blurring and not the image view? image code:

import React, { Component } from 'react';
import { View, Image, Text, findNodeHandle, StyleSheet } from 'react-native';
import { BlurView } from 'react-native-blur';
import uri from '../../../Assets/uri.png';

export default class Menu extends Component {
  constructor(props) {
    super(props);
    this.state = { viewRef: null };
  }

  imageLoaded() {
    console.log('setting blur ref!');
    this.setState({ viewRef: findNodeHandle(this.backgroundImage) });
  }

  render() {
    return (
      <View style={styles.container}>
        <Image
          ref={(img) => { this.backgroundImage = img; }}
          source={uri}
          style={styles.absolute}
          onLoadEnd={this.imageLoaded.bind(this)}
        />
        <BlurView
          style={styles.absolute}
          viewRef={this.state.viewRef}
          blurType="light"
          blurAmount={1}
        />
        <Text style={{ flex: 1 }}>Hi, I am some unblurred text</Text>
      </View>
    );
  }
}

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

anyone else experiencing this, or get blur working on Android???

stantoncbradley avatar Feb 17 '18 00:02 stantoncbradley

try to increase the blurAmount and add blurRadius, I managed to do it on android but the blur is not as blurred as in ios although I am putting the numbers to maximum

MorcosS avatar Apr 24 '18 19:04 MorcosS

any update?

mr-piratman avatar May 01 '18 13:05 mr-piratman

I just did some experimentation and did end up getting Android to display correctly but had to implement some Android-specific workarounds:

  • iOS doesn't seem to need all the viewRef state wiring but Android does
  • On Android, edges of component with the set ref do not blur, but on iOS they do (Android clips all subviews). If blurred edges are desired, the blurred-edge view must be a child of the view with ref set and have padding applied. (see screenshots below)
  • For Images contained within a View, a background color must be applied to enclosing View. backgroundColor: 'transparent' works but Android displays both the BlurView image and underlying Image, so opacity: 0 should be set on the underlying image to prevent both blur and non-blur from displaying. (@MorcosS I think this is why you're not seeing Android as blurred)

Gist here: https://gist.github.com/computerjazz/90acb6024d19c306c71f9bafc7c84836

iOS: simulator screen shot - iphone x - 2018-05-17 at 14 00 10

Android: screenshot_20180517-140005

computerjazz avatar May 17 '18 21:05 computerjazz

thanks I will try that

MorcosS avatar May 18 '18 00:05 MorcosS

Thanks @computerjazz! It worked for me :)

lucaspelloni2 avatar Sep 25 '19 14:09 lucaspelloni2