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

ListEmptyComponent not taking full screen with flex 1 in SectionList #17944

Closed
AlexisLeon opened this issue Feb 12, 2018 · 34 comments
Closed

ListEmptyComponent not taking full screen with flex 1 in SectionList #17944

AlexisLeon opened this issue Feb 12, 2018 · 34 comments

Comments

@AlexisLeon
Copy link

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 8.9.0
  Yarn: 1.3.2
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
  react: ^16.2.0 => 16.2.0
  react-native: 0.53.0 => 0.53.0

Expected Behavior

ListEmptyComponent (my EmptyComponent) has style flex: 1 and should be rendered taking full screen.
If ListHeaderComponent or ListFooterComponent are defined and styled with flex: 1, should render the elements with the same proportion and using the whole screen.

simulator screen shot - iphone 8 plus - 2018-02-11 at 22 55 10

Actual Behavior

ListEmptyComponent (my EmptyComponent) renders using only the space it needs (to fit).

simulator screen shot - iphone 8 plus - 2018-02-11 at 22 54 56

Reproducible Demo

import React from 'react';
import { SectionList, Text, View, StyleSheet } from 'react-native';

const EmptyComponent = ({ title }) => (
  <View style={styles.emptyContainer}>
    <Text style={styles.emptyText}>{title}</Text>
  </View>
);

const App = () => (
  <View style={styles.app}>
    <SectionList
      keyExtractor
      renderItem={({ item }) => <Text>{item.name}</Text>}
      sections={[]}
      ListEmptyComponent={
        <EmptyComponent title="Nothing here, come back later.." />
      }
    />
  </View>
);

const styles = StyleSheet.create({
  app: {
    flex: 1,
  },
  emptyContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  emptyText: {
    fontSize: 30,
  },
});
@hbarylskyi
Copy link

having same issue on 0.52.2

@TheDutchCoder
Copy link

Same issue on RN 0.53.0

@ghost
Copy link

ghost commented Mar 2, 2018

Same issues on RN 0.53.3

@smsmdida
Copy link

smsmdida commented Mar 6, 2018

The same issue on RN 0.54

@hramos hramos added the Lists label Mar 8, 2018
@kdastan
Copy link
Contributor

kdastan commented Mar 12, 2018

Any news ?

@bezenson
Copy link

bezenson commented Apr 4, 2018

The same for me. RN 0.54.4
UPD. For me helped this attr: contentContainerStyle={{ flex: 1, alignItems: 'center' }}

@jayesbe
Copy link

jayesbe commented Apr 16, 2018

contentContainerStyle={{ flexGrow: 1 }}

worked better for me.

@smsmdida
Copy link

@inferusvv we can't use flex in conentContainerStyle it will disable the scroll

@bezenson
Copy link

@smsmdida Hm, you might be right. In my case I have container without scrolling inside

@hbarylskyi
Copy link

hbarylskyi commented Apr 19, 2018

Had to use this as a workaround:

contentContainerStyle={[ { flexGrow: 1 } , items.length ? null : { justifyContent: 'center'} ]}

@sagarrabadiya
Copy link

same here RN: 0.55.4 the above workaround spoils the entire layout.. 😆

@lahed
Copy link

lahed commented May 30, 2018

don't work for me

<ScrollView contentContainerStyle={{ flexGrow: 1 }} >
    <View style={{ flex: 1, backgroundColor:'red'}} >
      <Text>asdasdsad</Text>
    </View>
  </ScrollView>

@AntonPuko
Copy link

Hey. the fix is merged to master already db061ea.
And it probably will be released in 0.56

@Evyraad
Copy link

Evyraad commented Jun 27, 2018

@hbarylskyi It doesn't work if your FlatList has a header component.

@taylorkline
Copy link

taylorkline commented Sep 20, 2018

This should be linked to (and hopefully closed by): PR #18206

@kientux
Copy link

kientux commented Oct 6, 2018

Is this fixed? I'm still facing this bug in 0.57.

@tobiastornros
Copy link

Still an issue with 0.57.1.
contentContainerStyle with flex or flexGrow will destroy header component or makes items in list not clickable.

@Faolain
Copy link

Faolain commented Nov 30, 2018

As mentioned above still a bug in 0.57

@kcotias
Copy link

kcotias commented Nov 30, 2018

contentContainerStyle={{ flexGrow: 1 }}

worked better for me.

Worked like a charm! Thanks a lot!

@FirdousNath
Copy link

I got success with the simple trick as below

import { Dimensions } from "react-native";
const SCREEN_HEIGHT = Dimensions.get("window").height;

than I declare the empty component

_listEmptyComponent = () => {
    return (
      <View
        style={{
          justifyContent: "center",
          alignItems: "center",
          height: SCREEN_HEIGHT , //responsible for 100% height
          backgroundColor: "#ddd"
        }}
      >
        <Text
          style={{
            justifyContent: "center",
            alignItems: "center",
            fontSize: 20
          }}
        >
          No Contracts Found
        </Text>
      </View>
    );

And at last Flatlist look like :

<FlatList
           extraData={this.props.contracts}
           data={this.props.contracts}
           ListEmptyComponent={this._listEmptyComponent.bind(this)}
           renderItem={({ item }) => (
             <Text>{item.contractName}>
             <Text/>
           )}
           keyExtractor={(item, index) => item.id}
         />

@riadeveloper
Copy link

And this is probably the best solution to fix it

@Salakar
Copy link
Contributor

Salakar commented Apr 10, 2019

👋 hey all, this issue has been pretty quiet lately - is this still an issue with the latest version of React Native?

Please let me know if so and I'll re-open.

Thank you.

@Salakar Salakar closed this as completed Apr 10, 2019
@elyalvarado
Copy link
Contributor

Hi @Salakar, I can confirm this is still an issue in 0.59.4.

@jayan2019
Copy link

jayan2019 commented Apr 12, 2019

contentContainerStyle={{ flexGrow: 1 }} Worked on 0.59, but not in 0.59.4

@Salakar Salakar reopened this Apr 13, 2019
@Salakar
Copy link
Contributor

Salakar commented Apr 13, 2019

@elyalvarado @jayan2019 - thanks for confirming - I've re-opened this issue.

@elyalvarado
Copy link
Contributor

This should be fixed with the merged PR #24339, as soon as it lands in a release version

@cpojer
Copy link
Contributor

cpojer commented Apr 14, 2019

Fixed on master.

@junhyukso
Copy link

I think it's not workking in 0.60

@Technaur
Copy link

I fixed it by wrapping my FlatList in a View with flexGrow: 1 on the View and on the FlatList contentContainerStyle I also set flexGrow: 1 (Working on 0.60.5 for me)

<View style={{ flexGrow: 1 }}> <FlatList contentContainerStyle={{ flexGrow: 1 }} /> </View>

Just make sure that any parent views this component is wrapped in are also flex: 1 (I have noticed that this can have an effect on children components flex)

Hope this helps :)

@jayan2019
Copy link

jayan2019 commented Sep 6, 2019

Working on 0.60.5

<FlatList 
      contentContainerStyle={{ flex: 1 }}
      renderItem={({item}) => (<View />)}
      ListEmptyComponent={() => (
      <View style={{flex: 1, alignItems: 'center', justifyContent: 'center',}}>
           <Text>No Data Found</Text>
      </View>
      )}
/> 

@yishin
Copy link

yishin commented Dec 20, 2019

contentContainerStyle={{ height: '100%' }}

@diegoP08
Copy link

contentContainerStyle={{minHeight: '100%'}} works for me

@ChenhuaWANG22
Copy link

on 0.61.5:

  1. below two will work, but it will make items overlapping for list with length >0.
    so something like this may help.
    contentContainerStyle={items.length ? {} : { flex: 1 } }

@jayan2019

Working on 0.60.5

<FlatList 
      contentContainerStyle={{ flex: 1 }}
      renderItem={({item}) => (<View />)}
      ListEmptyComponent={() => (
      <View style={{flex: 1, alignItems: 'center', justifyContent: 'center',}}>
           <Text>No Data Found</Text>
      </View>
      )}
/> 

@yishin

contentContainerStyle={{ height: '100%' }}

  1. below is working correctly for empty list and list with content.
    @diegoP08

contentContainerStyle={{minHeight: '100%'}} works for me

  1. but, at the end, I am still afraid of this issue will arise again once I upgrade RN.
    so, I prefer to wrap FlatList into MyFlatList:
    return (
        data.length > 0
            ? <FlatList
                style={styles.flatList}
                renderItem={({ item, index }) => renderItem(item, index)}
                ItemSeparatorComponent={ItemSeparatorComponent}
                data={data}
                keyExtractor={keyExtractor}
            />
            : <View style={styles.textWrap}>
                <Text style={styles.placeholderText}>
                    {placeholder}
                </Text>
            </View>
    )

@fsobh
Copy link

fsobh commented Apr 2, 2020

contentContainerStyle={{ height: '100%' }}

Worked like a charm :)

@facebook facebook locked as resolved and limited conversation to collaborators Apr 14, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests