Свернуть / развернуть плоский список не работает в React-Native - PullRequest
0 голосов
/ 05 июня 2019

Я пытаюсь развернуть / свернуть Flatlist в приложении React-Native.Но это не расширяется.Я пытаюсь отобразить данные заголовков плоского списка. Затем, если пользователь нажимает на каждый раздел, мне нужно развернуть ячейку и показать другую ячейку внутри нее.Это как клетка внутри клетки, я новичок в React-Native.

Class.js

      constructor(props) {
        super(props);
        this.state = {
          selected: (new Map(): Map<string, boolean>),
        };
        this.itemSelectionHandler.bind(this);
      }

  selectionHandler = (data) => {
    const { navigation } = this.props;
    navigation.navigate('someclass', { selectedData: data });
  }

     keyExtractor = (item, index) => `some-${index}`;


      separator = () => (<View style={styles.separator} />);

          headerSectionExpandCollapseHandler = (index) => {
            this.setState((state) => {
              // copy the map rather than modifying state.
              const selected = new Map(state.selected);
              selected.set(index, !selected.get(index)); // toggle
              return { selected };
            });
          }
      renderExpandCollapseCell = ({ item, index }) => (
        <expandCollapaeCell
          title={get(item, 'title')}
          item={get(item, 'name')}
          code={get(item, 'code')}
          onExpandToggled={() => this.headerSectionExpandCollapseHandler(get(item, index))}
          expanded={!!this.state.selected.get(item, index)}
          onSelected={this.selectionHandler}
        />
      )


        render() {
            const { data } = this.state;
             return (
                        <FlatList
                        contentContainerStyle={{ flexGrow: 1 }}
                        data={data}
                        extraData={this.state}
                        keyExtractor={this.keyExtractor}
                        renderItem={this.renderExpandCollapseCell}
                        ItemSeparatorComponent={this.separator}
                        onSelected={this.itemSelectionHandler}

                      />
          );
        }


    `

ExpandCollapseCell.js

    export default class ExpandCollapseCell extends PureComponent {
      data = (item, index) => (
        <View key={`some-cell-${index}`}>
          <TouchableOpacity activeOpacity={0.8} onPress={this.props.onSelected.bind(this, item)}>
            <View style={styles.somestyles}>
              <View style={styles.somestyles}>
                <Text style={[styles.title]}>{get(item, 'name')}</Text>
                <Text style={[styles.code]} numberOfLines={2}>{`(${get(item, 'code')})`}</Text>
              </View>
            </View>
          </TouchableOpacity>
        </View>
      )

      render() {
        const { expanded, title, item, onExpandToggled, onSelected } = this.props;

        const cellHeight = expanded ? (item.length * 40) + 30 : 30;
        return (
          <View style={[styles.container, { height: cellHeight }]}>
            <View style={styles.headerContainer}>
              <TouchableOpacity style={styles.headerButton} onPress={onExpandToggled}>
                <View style={styles.detailsContainer}>
                  <Image source={expanded ? res.images.arrow_up : res.images.arrow_down} />
                  <DefaultLabel
                    labelStyle={[styles.font, styles.color]}
                  >
                    {title}
                  </DefaultLabel>
                </View>
              </TouchableOpacity>
            </View>
            <View style={[styles.cellContainer]}>
              {expanded && item.map(this.data)}
            </View>
          </View>
        );
      }
    }

Он просто показывает данные, но не расширяет ячейку.Есть предложения?

enter image description here

...