react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Layout] Vertical centering fails when container has absolute positioning and no explicit height

Open premasagar opened this issue 11 years ago • 32 comments

The code below renders like this, with the red square at the top of the container (screenshot from iOS 8.3 simulator):

positioning-1

If an explicit height:70 is set on the container, then the red square is vertically centered:

positioning-2

I would expect the square to be vertically centered within its container, without needing to set an explicit height. The yellow background color fills the height of the element without an explicit height set.

This is only an issue for elements that have absolute positioning, not those with relative positioning.

<View>
    <View style={{
      position: 'absolute',
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
      flex: 1,
      flexDirection: 'row',
      justifyContent: 'center',
      alignItems: 'center',
      backgroundColor: 'yellow'
    }}>
      <View style={{
        backgroundColor: 'red',
        width: 10,
        height: 10
      }}/>
    </View>

    <View style={{
      opacity: 0.5,
      borderColor: 'black',
      borderWidth: 1
    }}>
      <Text>Lorem ipsum lorem ipsum</Text>
      <Text>Lorem ipsum lorem ipsum</Text>
      <Text>Lorem ipsum lorem ipsum</Text>
      <Text>Lorem ipsum lorem ipsum</Text>
    </View>
  </View>

Maybe related #384

premasagar avatar May 11 '15 11:05 premasagar

Also experiencing this issue, hardcoding the height fixes it for me

BlooJeans avatar May 22 '15 20:05 BlooJeans

Looks like a bug to me, @lwansbrough can you test this out when you pull the newest version of css-layout?

Runnable example that you can just copy and paste in: here

brentvatne avatar May 29 '15 22:05 brentvatne

+1. Just got hit by this bug. need to explicitly give a height.

chirag04 avatar Jun 10 '15 18:06 chirag04

:+1: I have a very similar issue but it doesn't matter whether or not the position is set. In my case, if there are several columns in a row, and the content in one column determines the height of the row, vertical centering does not work in the other columns.

screen shot 2015-07-16 at 10 36 34

Here is the css for this screenshot:

leftRowActions: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'flex-end',
    alignItems: 'center',

    borderBottomColor: 'white',
    borderBottomWidth: 2,
    backgroundColor: '#3878c8'
  },
  rightRowActions: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'flex-start',
    alignItems: 'center',

    borderBottomColor: 'white',
    borderBottomWidth: 2,
    backgroundColor: '#26c3bd'
  },

Edit: setting alignItems: 'center' on the parent does not work because then column is centered but the backgroundColor does not fill the row.

screen shot 2015-07-16 at 10 47 26

felixakiragreen avatar Jul 16 '15 14:07 felixakiragreen

+1 On this bug. Should we create an issue in https://github.com/facebook/css-layout ?

pietropizzi avatar Aug 31 '15 13:08 pietropizzi

+1. I am having same issue too.

eluleci avatar Sep 06 '15 09:09 eluleci

+1. having same issue

alvingarcia avatar Sep 07 '15 11:09 alvingarcia

Please open this bug in the css-layout repo.

ide avatar Sep 07 '15 17:09 ide

I'm actually pretty sure it has already been opened https://github.com/facebook/css-layout/issues/83 Needs some love there though

pietropizzi avatar Sep 07 '15 21:09 pietropizzi

Yes, + 1. I am having same issue too.

hufeng avatar Sep 12 '15 04:09 hufeng

+1

kitt1987 avatar Sep 14 '15 08:09 kitt1987

+1

jhau avatar Sep 21 '15 03:09 jhau

+1

swathysubhash avatar Sep 24 '15 11:09 swathysubhash

+1

ilansas avatar Oct 20 '15 15:10 ilansas

+1

SteveMellross avatar Oct 25 '15 08:10 SteveMellross

+1

respectTheCode avatar Nov 24 '15 10:11 respectTheCode

+1

smalllixin avatar Dec 16 '15 11:12 smalllixin

+1

olivierlesnicki avatar Dec 26 '15 17:12 olivierlesnicki

+1

niftylettuce avatar Jan 07 '16 20:01 niftylettuce

+1

kaplanov avatar Jan 15 '16 15:01 kaplanov