简体   繁体   English

如何在平面列表中仅渲染特定元素一次 - React Native

[英]How to render a specific element only once in a flatlist - React Native

I have a scroll page that I built using a react native flatlist.我有一个使用 react native flatlist 构建的滚动页面。

 return (
      <>
        <SearchHeader placeholder="Buscar procedimento" getValueUserSearch={this.getInfoSearch} />
        <FlatList
          keyExtractor={procedure => procedure.id}
          data={procedures}
          renderItem={_ => {
            return (
              <Container style={styles.MainContainer}>
                {procedures.length ? (
                  <Text bold style={styles.TitleSearch}>
                    Exibindo todos os resultados
                  </Text>
                ) : (
                  <Text bold style={styles.TitleSearch}>
                    Busque pelo procedimento
                  </Text>
                )}
                {procedures.map(procedure => (
                  <ArrowBox key={procedure.id} onPress={() => RootNavigation.navigate('ProcedureDetails', {procedure})}>
                    <Text bold style={styles.ProcedureTitle}>
                      {procedure.name}
                    </Text>
                    {!!procedure.synonyms.length && (
                      <>
                        <Text bold style={styles.ProcedureSynonymTitle}>
                          Sinônimos
                        </Text>
                        <View style={styles.ProcedureSynonymOptionsContainer}>
                          {procedure.synonyms.map(synonym => <Text style={styles.ProcedureSynonymOption} key={synonym}>{synonym}</Text>)}
                        </View>
                      </>
                    )}
                  </ArrowBox>
                ))}
                <HelpBox
                  scene="AccreditedProvidersNetwork"
                  styleMainContainer={{display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItem: 'center'}}
                  style={{borderColor: 'rgba(0, 0, 0, 0.2)', marginTop: 24, marginBottom: 24, width: deviceWidth * 0.9}}
                  styleFirstText={{color: '#000'}}
                  styleSecondText={{color: 'rgba(0, 0, 0, 0.7)'}}
                  icon={HelpIcon}
                />
              </Container>
            );
          }}
          onEndReached={this.loadProcedures}
          onEndReachedThreshold={0.1}
          ListFooterComponent={this.renderFooter}
        />
      </>
    );

However I have a problem, the following blocks of code are being repeated by flatlist:但是我有一个问题,以下代码块被 flatlist 重复:

               {procedures.length ? (
                  <Text bold style={styles.TitleSearch}>
                    Exibindo todos os resultados
                  </Text>
                ) : (
                  <Text bold style={styles.TitleSearch}>
                    Busque pelo procedimento
                  </Text>
                )}

And:和:

             <HelpBox
                  scene="AccreditedProvidersNetwork"
                  styleMainContainer={{display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItem: 'center'}}
                  style={{borderColor: 'rgba(0, 0, 0, 0.2)', marginTop: 24, marginBottom: 24, width: deviceWidth * 0.9}}
                  styleFirstText={{color: '#000'}}
                  styleSecondText={{color: 'rgba(0, 0, 0, 0.7)'}}
                  icon={HelpIcon}
                />

But I can't repeat them.但我不能重复它们。 The only block I need to repeat is this:我需要重复的唯一块是:

{procedures.map(procedure => (
                  <ArrowBox key={procedure.id} onPress={() => RootNavigation.navigate('ProcedureDetails', {procedure})}>
                    <Text bold style={styles.ProcedureTitle}>
                      {procedure.name}
                    </Text>
                    {!!procedure.synonyms.length && (
                      <>
                        <Text bold style={styles.ProcedureSynonymTitle}>
                          Sinônimos
                        </Text>
                        <View style={styles.ProcedureSynonymOptionsContainer}>
                          {procedure.synonyms.map(synonym => <Text style={styles.ProcedureSynonymOption} key={synonym}>{synonym}</Text>)}
                        </View>
                      </>
                    )}
                  </ArrowBox>
                ))}

I understand that the solution is to remove them from Flatlist.我知道解决方案是将它们从 Flatlist 中删除。 However, I need the entire page to have the scroll and I cannot leave these components fixed.但是,我需要整个页面才能滚动,而且我不能让这些组件保持固定。 These components need to accompany the scroll as well.这些组件也需要伴随滚动。

How could I make these components not repeat themselves?我怎样才能让这些组件不重复?

Thanks!!谢谢!!

ListHeaderComponent 和 ListFooterComponent 属性。

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

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