question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistency padding properties when using flex

See original GitHub issue

This get weird when I add padding properties

React Native version:

System: OS: macOS 11.2.1 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Memory: 116.91 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 15.3.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.9 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: Not Found IDEs: Android Studio: 4.1 AI-201.8743.12.41.7042882 Xcode: 12.4/12D4e - /usr/bin/xcodebuild Languages: Java: 11.0.8 - /usr/local/opt/openjdk@11/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.1 => 17.0.1 react-native: 0.64.1 => 0.64.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps To Reproduce

This is test code here

<Text>Simple flex</Text>
<View style={{ flexDirection: "row", borderColor: "blue", borderWidth: 1, padding: 10, height: 70, }}>
  <View style={{ flex: 1, borderWidth: 1, borderColor: "green" }} />
  <View style={{ flex: 1, borderWidth: 1, borderColor: "red" }} />
</View>
<Text style={{ marginTop: 20 }}>Padding with flex</Text>
<View style={{ flexDirection: "row", borderColor: "blue", borderWidth: 1, padding: 10, height: 70, }}>
  <View style={{ flex: 1, padding: 0, borderWidth: 1, borderColor: "green" }} />
  <View style={{ flex: 1, padding: 20, borderWidth: 1,  borderColor: "red" }} />
</View>

Simulator Screen Shot - iPhone 11 - 2021-05-19 at 11 23 15

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
chrisgleincommented, May 19, 2021

I believe this is just expected from flex layout. For example if I translate your markup to HTML like so:

Simple flex
<div style="display: flex; flex-direction: row; border-color: blue; border-width: 1px; padding: 10px; height: 70px">
  <div style="flex: 1; border-style: solid; border-width: 1px; border-color: green"></div>
  <div style="flex: 1; border-style: solid; border-width: 1px; border-color: red"></div>
</div>

Padding with flex
<div style="display: flex; flex-direction: row; border-color: blue; border-width: 1px; padding: 10px; height: 70px">
  <div style="flex: 1; border-style: solid; border-width: 1px; border-color: green; padding: 0px"></div>
  <div style="flex: 1; border-style: solid; border-width: 1px; border-color: red; padding: 20px"></div>
</div>

I get the same result. You can run that in a jsFiddle here. If it behaves this way with HTML flexbox layout then it seems correct that RN/Yoga flexbox match. This appears to be by design.

0reactions
vdthieucommented, May 19, 2021

I updated my code above to clearly show the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent margin between flex items on last row
The flexbox specification advises against using percentage margin and padding in a flex container. Authors should avoid using percentages in ...
Read more >
958714 - Flex items treat percentage padding & margin values ...
Summary: Flex items treat percentage padding & margin values in vertical axis as 0, if the flex container lacks an explicit height (allowed...
Read more >
[css3-flexbox] error in flexbox editor's draft on "margin/padding
Hi www-style, The current editor's draft of the flexbox spec[1] is inconsistent on whether the margin & padding properties can take the ...
Read more >
Don't Overthink It (Flexbox) Grids - CSS-Tricks
You could add padding to the columns. I like the idea of using justification to create the columns, like: .flex-grid-thirds { display: flex; ......
Read more >
What is Margin Collapse in CSS? And How to Avoid It
Inconsistencies may occur depending on, where that component is placed as the margin may interact with another.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found