react-native: components with zIndex in flatlist does not seem to work
Asked Answered
M

2

4

The main render:

  render() {
    return (

    <View>
      <FlatList
      ListEmptyComponent={() => <DialogBox type="internet" />}
      ...
    </View>
     );

<DialogBox type="internet" /> container styled via absolute position:

export const dialogBox = EStyleSheet.create({
   container : {
       position: 'absolute',
       justifyContent: 'center',
       alignItems: 'center',
       top: 0,
       left: 0,
       right: 0,
       bottom: 0,
       zIndex:10000

   },
   .... 

and DialogBox:

  <View style={dialogBox.container}>
       <View style={dialogBox.box}>
       ...

If I remove absolute form container, It shows. But I want show it in middle of screen (not middle of flatlist).

But why dosen't work zIndex in absolute?

I try change the code to this:

    <View style={{position: 'absolute',zIndex:1}}>
      <FlatList
      style={{position: 'absolute',zIndex:2}}

or this:

    <View style={{position: 'relative'}}>
      <FlatList
      style={{position: 'relative'}}

But it's not work

Monniemono answered 7/5, 2019 at 10:42 Comment(0)
J
5

You can add CellRendererComponent to the FlatList, even simply adding this seems to work:

CellRendererComponent={({children}) => children}

Note: Android will crash unless you add:

removeClippedSubviews={false}
Jinajingle answered 13/3, 2022 at 12:31 Comment(2)
Hi, where exactly do I add this?Fusible
These are props of RN's FlatListJinajingle
R
-2

zIndex working not only for absolute position.

touchableCard: {
    justifyContent: "center",
    alignItems: "center",
    zIndex: 200,
    ...
  },

  emptyNotesInfo: {
    textAlign: "center",
    zIndex: 100,
    ...
  },

Try this:

   <View>
      <FlatList style={{flex: 1}}
        renderItem={ data => <View style={{zIndex: 2}}><Text>HERE example view</Text></View>}
      ...
      />
   </View>
  <View style={{ 
       position: "absolute", 
       zIndex: 1,
       alignContent: "center",
       alignItems: "center",
       alignSelf: "center"
     }}>
     <Text>HERE What you need too hide</Text>
  </View>
Runner answered 8/5, 2019 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.