简体   繁体   English

FlatList根本不显示标题标签

[英]FlatList doesn't show title tags at all

I'm quite new at react-redux, and currently am trying to build some stack application that will simply be some type of menu that will have it's sections with titles and when pressing the title it will show some simple text about it. 我在react-redux上是个新手,目前正在尝试构建一些堆栈应用程序,该应用程序将只是某种菜单,菜单的标题部分会出现,按标题时会显示一些简单的文本。 So I'm using Flatlist for rendering all these sections, and the rendering works perfectly fine. 因此,我使用Flatlist呈现所有这些部分,并且呈现效果非常好。 It renders exactly 9 sections which is the number of my current objects, meaning that it has access to the data, plus when I try to change the font size of the title that these sections have to display, the size of the sections change as well, meaning that it definitely has access to the title strings as well, but for some reason the text is not showing up at all. 它恰好呈现了9个部分,这是我当前对象的数量,这意味着它可以访问数据,而且当我尝试更改这些部分必须显示的标题的字体大小时,这些部分的大小也会随之改变,这意味着它当然也可以访问标题字符串,但是由于某种原因,文本根本没有显示。 Here's how it looks: 外观如下:

在此处输入图片说明

I tried to change the text color, change size, change background color, add some padding, but section still doesn't show the text. 我试图更改文本颜色,更改大小,更改背景颜色,添加一些填充,但是该部分仍未显示文本。

So here's where I implement the FlatList: 所以这是我实现FlatList的地方:

import React, { Component } from 'react';
import { FlatList } from 'react-native';
import { connect } from 'react-redux';
import ListItem from './ListItem';

class LibraryList extends Component {
    renderItem(library) {
        return <ListItem library={library} />;
    }

    render() {
        console.log(this.props.libraries);
        return (
            <FlatList
             data={this.props.libraries}
             renderItem={this.renderItem}
             keyExtractor={(library) => library.id.toString()}
            />
        );
    }
}

const mapStateToProps = state => {
    return { libraries: state.libraries };
};

export default connect(mapStateToProps)(LibraryList);

Here I implement the section itself: 在这里,我实现了该部分本身:

import React, { Component } from 'react';
import { Text } from 'react-native';
import { CardSection } from './common';


class ListItem extends Component {
     render() {
        const { titleStyle } = styles;
        return (
            <CardSection>
                <Text style={titleStyle}>
                    {this.props.library.title}
                </Text>
            </CardSection>
        );
    }
}

const styles = {
    titleStyle: {
        color: 'black',
        fontSize: 20,
        fontWeight: '600',
    }
};

export default ListItem;

And here's the code for the section itself: 这是该部分本身的代码:

import React from 'react';
import { View } from 'react-native';

const CardSection = (props) => {
  return (
    <View style={styles.containerStyle}>
      {props.children}
    </View>
  );
};

const styles = {
  containerStyle: {
    borderBottomWidth: 1,
    padding: 5,
    backgroundColor: '#fff',
    justifyContent: 'flex-start',
    flexDirection: 'row',
    borderColor: '#ddd',
  }
};

export { CardSection };

Expected result would be for titles to show up in those 9 sections. 预期结果将是标题出现在这9个部分中。

在ListItem中,将Text组件内的{this.props.library.item.title}替换为{this.props.library.item.title}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM