Kureev / react-native-blur

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

Pressable becomes full screen when inside BlurView on Android #616

Open mohshbool opened 5 months ago

mohshbool commented 5 months ago

This is happens only on Android, all versions. This problem disappears if I change styling in the code and refreshing. Problem stays away even after i undo the change even if it was irrelevant to the component.

Environment:

"@react-native-community/blur": "^4.4.0",
"react-native": "0.73.1",

Scenario:

import React from 'react';
import {Dimensions, StyleSheet, View} from 'react-native';
import {BlurView} from '@react-native-community/blur';

const Component = () => {
  return (
    <BlurView style={styles(theme).container}>
      <Pressable
        onPress={unlock}
        style={styles(theme).buttonContainer}
      >
        <Text style={styles(theme).buttonText}>UNLOCK</Text>
    </BlurView>
  );
};

const styles = StyleSheet.create({
    container: {
      position: 'absolute',
      zIndex: 1,
      width: '100%',
      height: Dimensions.get('window').height * 0.92,
      justifyContent: 'flex-end',
      paddingHorizontal: 25,
    },
    buttonContainer: {marginBottom: 20},
    buttonText: {fontSize: 15, color: 'white'},
  });

Screenshot of the code above from android: screen

praveen-me commented 4 months ago

Hey @mohshbool

Wrap the Pressable component inside a TouchableOpacity with an activeOpacity of 1. This resolves the issue and ensures the button remains responsive.

Example Code

Here’s an example implementation:

import React from 'react';
import {Dimensions, StyleSheet, View, TouchableOpacity, Pressable, Text} from 'react-native';
import {BlurView} from '@react-native-community/blur';

const Component = () => {
  return (
    <BlurView style={styles.container}>
      <TouchableOpacity activeOpacity={1} style={{flex: 1}}>
        <Pressable onPress={unlock} style={styles.buttonContainer}>
          <Text style={styles.buttonText}>UNLOCK</Text>
        </Pressable>
      </TouchableOpacity>
    </BlurView>
  );
};

const styles = StyleSheet.create({
  container: {
    position: 'absolute',
    zIndex: 1,
    width: '100%',
    height: Dimensions.get('window').height * 0.92,
    justifyContent: 'flex-end',
    paddingHorizontal: 25,
  },
  buttonContainer: {
    marginBottom: 20,
  },
  buttonText: {
    fontSize: 15,
    color: 'white',
  },
});

export default Component;

Explanation

By wrapping Pressable in TouchableOpacity, we maintain the intended functionality and improve cross-platform consistency.

rajgupta027 commented 1 month ago

Still doesn't work. Applied activeOpacity to 1 as suggested @praveen-me I had a work around by wrapping children inside blurView inside one single View. Works for me.🙂