Skip to content

Android: Overlap TouchableOpacity and View behave differently when there is backgroundColor style  #28694

Closed
facebook/react-native-website
#2537
@gie3d

Description

@gie3d

Description

I created 2 Views that display overlaps to each others. The top and the bottom

2563-04-20 at 16 31

When the bottom view background wasn't configured. It responded to the press event correctly. Let's say when I press on the overlap zone, it showed that the bottom one had been pressed

However, when I configured the bottom view backgroundColor. When I pressed on the overlap zone, on Android, it responded as I pressed on the top view which I think it's incorrect. (iOS it responded correctly that the bottom was pressed)

2563-04-20 at 16 37

React Native version:

System:
OS: macOS 10.15.4
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 605.80 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
Yarn: 1.22.0 - ~/.nvm/versions/node/v12.16.0/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.16.0/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
npmPackages:
react: ~16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz => 0.61.4
npmGlobalPackages:
react-native-cli: 2.0.1

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.
Here is an example component

const OverlapseTouchExample = ({backgroundColor}) => {
  const [pressedBox, setPressefBox] = React.useState('')
  return (
    <View>
      <Text>{pressedBox} pressed</Text>
      <TouchableOpacity style={[styles.box, {backgroundColor: 'blue'}]} onPress={() => setPressefBox('top')} />
      <View style={backgroundColor ? { backgroundColor: 'orange' } : null}>
        <View style={{marginTop: -75}}>
          <TouchableOpacity style={[styles.boxBottom, backgroundColor ? { backgroundColor: 'green '} : null]} onPress={() => setPressefBox('bottom')} />
        </View>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  box: {
    width: 150,
    height: 150,
    borderWidth: 1,
  },
  boxBottom: {
    width: 120,
    height: 200,
    borderWidth: 1,
  }
})

The problem found when set the backgroundColor to true
<OverlapseTouchExample backgroundColor={true} />

Expected Results

It should response to the press event the same whether or not backgroundColor is configured or not.

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/@gie3d/9b6c32

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions