Kureev / react-native-blur

React Native Blur component
MIT License
3.76k stars 556 forks source link

Library is broken on Android #365

Open wmonecke opened 4 years ago

wmonecke commented 4 years ago

Bug

The library is unusable on Android.

The BlurView covers the whole screen and setting { overflow: 'hidden' } on parent is just a hack and actually causes performance issues, because if you inspect your views you can see BlurView is still rendering on the whole screen.

Also in the documentation, there are basically no instructions on how to implement viewRef.

If this is part of react-native-community it should at least be working properly. Wasted way too much time trying to make this work. It would be nice to have a disclaimer that this is only working for iOS at the current state.

Environment info

"@react-native-community/blur": "^3.4.1",
"react": "16.8.6",
"react-native": "0.60.4",
Psiiirus commented 4 years ago

I ran into i android issues to wiht 3.4.1 maybe try to checkout the 3.5.0 dev-master branch and see if this is still a bug.

Frans-L commented 4 years ago

With 3.5, the same bug exists.

martinfrouin commented 4 years ago

It actually works with the master branch. Can you add a release ?

JimTeva commented 4 years ago

I just updated to 3.6 and it works now.

ovcharukmaks commented 4 years ago

It still doesn't work. For android blur view takes whole screen. I'm using "@react-native-community/blur": "^3.6.0".

danleveille commented 4 years ago

Still having the same problem on 3.6.

luisnaranjo733 commented 4 years ago

I'm also experiencing basic functionality issues on Android with 3.6 from npm. Setting overflow: "hidden" on the parent of the still does not solve the issue.

Basically, the blur effect just isn't happening. It's just a transparent view.

benov84 commented 4 years ago

Not working in Android - its just transparent

SunskyXH commented 4 years ago

The same issue on 3.6 while using <BlurView />, and adding overflow: hidden to its parent view did not solve this problem.

pke commented 4 years ago

viewRef is not used anywhere in the source code (anymore)? The instructions in various issues are also vague in regard to Android. They claim you are supposed to put the BlurView before the content to be blurred. I am confused.

Also a lot of old issues from 2016 regarding render problems on Android are still open. That's adding to the confusion. Would the maintainer close old issues maybe?

MinhNguyenWre commented 4 years ago

The same issue on 3.6 while using <BlurView />, and adding overflow: hidden to its parent view did not solve this problem.

Same here. Does anyone have an idea? I can not set width and height for blur view in android, it always fullscreen overlap.

lumberman commented 3 years ago

Unrofrtuntaly, not a single library will work on Android as good as it works on iOS.

Read all the complications of performant blurring Native Android developers have in this thread: https://www.reddit.com/r/androiddev/comments/drs9bm/realtime_blurring_on_android_vs_ios/

A few quotes:

The blur is done on the main thread. Even though RS blur is allegedly executed on GPU, it's still effectively a blocking operation from the point of view of our code, because we have to wait till it finishes its job on the same thread we called it.

If I remember correctly, blur was never added to Android due to legacy reasons. In the early days of Android when having a GPU on a mobile device was not a given, Blur was simply too expensive of an operation to have it done by CPU only. This is why Android opted for the shading.

After reading all of this I decided to drop the idea of blurring anything on Android.

Orange9000 commented 3 years ago

In may case using overlayColor='transpanrent' prop reduced blur view size from full screen to the size i set in style prop.

talhamuhammadashraf commented 3 years ago

in Android it does not take children ,So you can place BlurView on absolute and an extra view on absolute with children

matinzd commented 3 years ago

Poor performance issue still exists on android on the latest version 3.6.0.

iarmankhan commented 3 years ago

@talhamuhammadashraf can you share example snippet? I couldn't make it work with react-navigation tab bar - for bottom tab bar blur

talhamuhammadashraf commented 3 years ago

@iarmankhan i was not using with tabbar but here is my code i just placed my content as sibling of blurview not as a children

<Fragment>
      <BlurView
        style={styles.absolute}
        blurType="dark"
        blurAmount={100}
        blurRadius={10}
      />

      <View style={styles.absolute}>
          <ActivityIndicator color={Colors.primary} size="large" />
      </View>
    </Fragment>`
 absolute: {
    position: 'absolute',
    top: 0,
    left: 0,
    bottom: 0,
    right: 0,
  }
iarmankhan commented 3 years ago

Thank you for the reply. I tried like that but it didn't work with react-navigation 5, so I installed expo-blur instead and it's working very well.

moddatherrashed commented 3 years ago

i found a workaround, to set the overlayColor={'transparent'} and to give the view what meant to be blur backgroundColor : 'rgba(255,255,255,0.1)' for a light blur, and for the dark blur backgroundColor : 'rgba(0,0,0,0.1)' of course just on android because ios working well.

raf2k07 commented 2 years ago

I tried this on Android to get some text in a View with a blurred background, and while I got the desired blur on the background, the elements above the BlurView seemed to be sort of smudged and blurry.

Lexical-Luke commented 2 years ago

@moddatherrashed, could you please provide context for where those code snippets were/should be placed? This issue is still present for Android, I followed this to implement the blurred tab bar . On Android, the tab bar doesn't seem to dynamically load content beneath it and it also produced a secondary blur that darkens the entire screen. Is there any known fix for this, an alternate package perhaps or is my luck completely out when it comes to Android?

moddatherrashed commented 2 years ago

@Lexical-Luke I created a custom header, here is the full example of it:

import React from 'react';
import {
  Image,
  View,
  StyleSheet,
  Platform,
  TouchableOpacity,
  SafeAreaView,
  Text,
} from 'react-native';
import {assets} from '../../application/assets/assets';
import {getThemeColors} from '../../application/common/colors';
import {
  appHeaderHeight,
  isIPhoneX,
  StatusBarHeight,
  width,
} from '../../application/common/sizes';
import ReduxContainer from '../../presentation/containers/ReduxContainer';
import {BlurView} from '@react-native-community/blur';
import Icon from 'react-native-vector-icons/Ionicons';

const SubHeader = ({
  companyName,
  navigation,
  brandingConfig,
  closeIconColor,
}) => {
  return (
    <SafeAreaView style={styles.container}>
      <BlurView
        blurType="light"
        blurAmount={5}
        style={styles.blurContainer}
        overlayColor={'transparent'}></BlurView>
      <TouchableOpacity
        onPress={() => navigation.goBack()}
        style={styles.closeIconContainer}>
        <Icon
          name={'md-close'}
          size={24}
          color={
            closeIconColor ? closeIconColor : brandingConfig.colors.primary
          }
        />
      </TouchableOpacity>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  blurContainer: {
    position: 'absolute',
    top: 0,
    left: 0,
    height: StatusBarHeight + 40,
    alignItems: Platform.OS === 'android' ? 'center' : 'flex-end',
    // paddingBottom: 10,
    flexDirection: 'row',
    width: width,
    borderBottomWidth: 1,
    borderBottomColor: getThemeColors?.transparent.white30,
    backgroundColor:
      Platform.OS === 'android'
        ? getThemeColors?.transparent.white20
        : null,
  },
  container: {
    position: 'absolute',
    top: 0,
    left: 0,
    zIndex: 100,
    height: StatusBarHeight + 40,
    alignItems: Platform.OS === 'android' ? 'center' : 'flex-end',

    flexDirection: 'row',
    width: width,
  },
  profilePictureContainer: {
    justifyContent: 'center',
    alignItems: 'flex-end',
    flex: 1,
    paddingRight: 10,
  },
  closeIconContainer: {
    height: 30,
    width: 30,
    // borderRadius: 15,
    // borderColor: getThemeColors?.transparent.white60,
    // borderWidth: 0.5,
    justifyContent: 'center',
    marginHorizontal: 10,
    // marginTop: StatusBarHeight,
  },
});

export default ReduxContainer(SubHeader);

Let me know if you need more explanation

dima-devs commented 2 years ago

"@react-native-community/blur": "3.6.0" is working exactly with overflow: 'hidden' on android.

bhushan-patil-official commented 1 year ago

@iarmankhan i was not using with tabbar but here is my code i just placed my content as sibling of blurview not as a children

<Fragment>
   <BlurView
     style={styles.absolute}
     blurType="dark"
     blurAmount={100}
     blurRadius={10}
   />

   <View style={styles.absolute}>
       <ActivityIndicator color={Colors.primary} size="large" />
   </View>
 </Fragment>`
absolute: {
 position: 'absolute',
 top: 0,
 left: 0,
 bottom: 0,
 right: 0,
}

This worked for me

bonnmh commented 10 months ago

You can use

overlayColor={isIOS ? undefined : 'transparent'}

fidaay commented 8 months ago

Almost 4 years later and the package is still inestable. I wasn't aware that react-native was THAT difficult to work with, there seems to be just a lot of bugs and few packages.

mohammedsadeghi commented 5 months ago

Applying an elevation of elevation: Platform.OS === 'android' ? 50 : 0, overflow: 'hidden', to the parent and elevation: Platform.OS === 'android' ? -1 : 0, in BlurView style did resolved the issue for me!

kalenkou commented 1 month ago

the problem is still observed on android