Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After a component sets the backgroundColor property, its zIndex will be infinite? #45273

Closed
1280103995 opened this issue Jul 4, 2024 · 3 comments

Comments

@1280103995
Copy link

Description

The backgroundColor of a component will cause the zIndex property of its sibling components to become invalid.

Devices: iPhone XR, Samsung A51

Steps to reproduce

I just created a new project.

import React, {useState} from 'react';
import {
  LayoutChangeEvent,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from 'react-native';

function Popover() {
  const [visible, setVisible] = useState(false);
  const [top, setTop] = useState(0);

  const onLayout = (e: LayoutChangeEvent) => {
    const {x, y, width, height} = e.nativeEvent.layout;
    setTop(height + 10);
  };

  return (
    <View style={{overflow: 'visible', alignItems: 'center'}}>
      <TouchableOpacity
        style={{height: 30, backgroundColor: 'orange'}}
        onLayout={onLayout}
        onPress={() => setVisible(!visible)}>
        <Text>Press here to open popover!</Text>
      </TouchableOpacity>

      {visible && (
        <View style={[{alignItems: 'center', zIndex: 999, position: 'absolute', top}]}>
          <View style={[styles.triangle]} />
          <View
            style={{
              backgroundColor: 'rgba(0,0,0,0.65)',
              padding: 10,
              borderRadius: 5,
            }}>
            <Text style={styles.popoverText}>
              This is the contents of the popover
            </Text>
          </View>
        </View>
      )}
    </View>
  );
}

function App(): React.JSX.Element {
  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      <Popover />
      <View style={{width: '100%', height: 50, justifyContent: 'flex-end', backgroundColor: 'pink'}}>
        <Text>Other element</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  triangle: {
    width: 0,
    height: 0,
    borderStyle: 'solid',
    borderTopWidth: 0,
    borderBottomWidth: 8,
    borderRightWidth: 8,
    borderLeftWidth: 8,
    borderRightColor: 'transparent',
    borderLeftColor: 'transparent',
    borderTopColor: 'transparent',
    borderBottomColor: 'rgba(0,0,0,0.65)',
    backgroundColor: 'transparent',
  },
  popoverText: {
    color: 'white',
    flexWrap: 'nowrap',
  },
});

export default App;

Just change

<View style={{width: '100%', height: 50, justifyContent: 'flex-end', backgroundColor: 'pink'}}>
<Text>Other element</Text>
</View>

to:

<View style={{width: '100%', height: 50, justifyContent: 'flex-end' }}>
<Text>Other element</Text>
</View>

React Native Version

0.74.2

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 77.98 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.6.2
    path: /opt/homebrew/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.4
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/fjliang/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11255304
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/fjliang/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.2
    wanted: 0.74.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false


### Stacktrace or Logs

```text
no log

Reproducer

The code is provided above.

Screenshots and Videos

6fd20 aac4-666136776765
@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available labels Jul 4, 2024
Copy link

github-actions bot commented Jul 4, 2024

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

Copy link

github-actions bot commented Jul 4, 2024

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.74.3. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@1280103995
Copy link
Author

Adding zIndex property to other components solved my problem.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jul 8, 2024
@cortinico cortinico removed Needs: Triage 🔍 Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants