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

Using absolute positioning, when the parent element has padding, the width height of the current element is incorrectly laid out using a percentage layout #46392

Open
ShaoGongBra opened this issue Sep 9, 2024 · 12 comments
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.

Comments

@ShaoGongBra
Copy link

ShaoGongBra commented Sep 9, 2024

Description

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import React from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  useColorScheme,
  View,
} from 'react-native';

function App(): React.JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: '#eee',
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView>
        <View
          style={{
            backgroundColor: '#000',
            height: 300,
            paddingTop: 200,
            paddingLeft: 200
          }}>
          <View style={{
            position: 'absolute',
            // width height 100%会排除父元素的padding
            width: '100%', height: '100%', left: 0, top: 0,
            backgroundColor: '#666'
          }} />
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

export default App;

WX20240909-101807

In the new architecture, I set the height to 100%, but its height is not equal to the height of the parent container, but will subtract the padding of the parent container

Steps to reproduce

1

React Native Version

0.75.2

Affected Platforms

Runtime - Android, Runtime - iOS

Areas

Fabric - The New Renderer

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
  Memory: 35.26 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.3
    path: /private/var/folders/rf/gd60z12164z72bny7z_0d4f80000gn/T/xfs-de932bea/node
  Yarn:
    version: 3.6.4
    path: /private/var/folders/rf/gd60z12164z72bny7z_0d4f80000gn/T/xfs-de932bea/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.3/bin/npm
  Watchman:
    version: 2024.07.15.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.1
    wanted: 0.75.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

empty

Reproducer

https://github.com/ShaoGongBra/rn-test

Screenshots and Videos

No response

@ShaoGongBra ShaoGongBra added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Sep 9, 2024
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Sep 9, 2024
@react-native-bot
Copy link
Collaborator

⚠️ 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.

@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:

@ShaoGongBra
Copy link
Author

WX20240909-103256
The same code appears inconsistent on the web side and can occupy all the width and height of the parent element

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Sep 9, 2024
@ShaoGongBra
Copy link
Author

I just closed the new architecture with 0.75.2 and got the same result, which cannot occupy all the height. However, in the previous version, I used 0.71, which was consistent with web performance at that time

@krishnendu-2003
Copy link

hello
i think i can solve this issue but i an new to opensource. Can i start forking this project?

@ShaoGongBra
Copy link
Author

hello i think i can solve this issue but i an new to opensource. Can i start forking this project?

yes

@krishnendu-2003
Copy link

krishnendu-2003 commented Sep 9, 2024

Can you guide me through the file structure of this project? In this directory will i find the app.js file and its other pages?

@krishnendu-2003
Copy link

Uploading Screenshot 2024-09-09 at 11.16.59 PM.png…

@krishnendu-2003
Copy link

is it available inside the helloworld directory?

@ShaoGongBra
Copy link
Author

is it available inside the helloworld directory?
The reproduced code is just these two sentences

<View
          style={{
            backgroundColor: '#000',
            height: 300,
            paddingTop: 200,
            paddingLeft: 200
          }}>
          <View style={{
            position: 'absolute',
            // width height 100%会排除父元素的padding
            width: '100%', height: '100%', left: 0, top: 0,
            backgroundColor: '#666'
          }} />
        </View>

@cortinico
Copy link
Contributor

@ShaoGongBra this doesn't look New Architecture related (at least from your reproducer), right? Like the same behavior happens on both Old and New Architecture

@ShaoGongBra
Copy link
Author

这看起来与 New Architecture 无关(至少从您的复制器来看),对吧?就像旧架构和新架构上都会发生相同的行为一样

yes

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) 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 Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.
Projects
None yet
Development

No branches or pull requests

4 participants