JavaScript FlatList scroll with the static component flatlist scroll to top,flatlist scroll to index,flatlist scroll

I have one static component and many for loop rendered components in a screen.

The all code below here.

import React from "react";
import { View, Text, FlatList } from "react-native";
...

class FlatListScrollWithStatic extends React.Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <FriendsTop />  // the static component
        <FlatList
          style={{ flex: 1 }}
          data={this.props.friendsCard}
          renderItem={({ item }) => <FriendsCard {...item} />}  // the for loop rendered components
          keyExtractor={(item, index) => index.toString()}
        />
      </View>
    );
  }
}

Now I want to migrate the FriendsTop into Flatlist, let it scroll with the rendered components, how should I change my code?

Answer:1

Flatlist has a prop ListHeaderComponent which accepts a JSX element. So:

import React from "react";
import { View, Text, FlatList } from "react-native";
...

class FlatListScrollWithStatic extends React.Component {
  render() {
    return (
      <View style={{ flex: 1 }}>

        <FlatList
          style={{ flex: 1 }}
          data={this.props.friendsCard}
          renderItem={({ item }) => <FriendsCard {...item} />}  // the for loop rendered components
          keyExtractor={(item, index) => index.toString()}
          ListHeaderComponent={<FriendsTop />}
        />
      </View>
    );
  }
}
Answer:2

This may work for you:

import React, { Fragment } from "react";

...

<FlatList
  style={{ flex: 1 }}
  data={this.props.friendsCard}
  renderItem={({ item }, index) => (
    <Fragment>
      { !index && <FriendsTop /> } // Render when !index is truthy (i.e. index === 0)
      <FriendsCard {...item} />
    </Fragment>
  )}
  keyExtractor={(item, index) => index.toString()}
/>
Answer:3

I have a basic script which shows/hides a div. I'm using this for a drop-down menu. https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp I'm looking for the div element to be hidden when ...

I have a basic script which shows/hides a div. I'm using this for a drop-down menu. https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp I'm looking for the div element to be hidden when ...

I'm using this library here: ng-sortable And I'm using it on a table. The thing is, when I physically drag a table row, the row shrinks and doesn't keep the original look of the table. I narrowed ...

I'm using this library here: ng-sortable And I'm using it on a table. The thing is, when I physically drag a table row, the row shrinks and doesn't keep the original look of the table. I narrowed ...

I have the following array var x = [{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18}] And i am trying to add the following ...

I have the following array var x = [{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18}] And i am trying to add the following ...

  1. concatenate arrays with different dimensions python
  2. concatenate arrays with different dimensions matlab
  3. concatenate arrays with numpy
  4. concatenate arrays with python
  5. concatenate arrays with
  6. concat arrays with spread operator
  7. concat arrays with reduce
  8. concatenate arrays in matlab
  9. concatenate arrays of different sizes matlab
  10. concatenate arrays of different sizes python
  11. concatenate arrays in java
  12. concatenate arrays in javascript
  13. concatenate arrays in c
  14. concatenate arrays in r
  15. concatenate arrays in list python
  16. concatenate arrays in excel
  17. concatenate arrays in loop matlab
  18. concatenate arrays of different sizes numpy
  19. concatenate arrays in php
  20. concatenate arrays in a list

An API I'm working with is returning poorly structured data like this: { "scsi0": "vm-101-disk-1.qcow2,size=32G", "scsi1": "vm-101-disk-2.qcow2,size=32G", "scsi2": "vm-101-disk-3.qcow2,...

An API I'm working with is returning poorly structured data like this: { "scsi0": "vm-101-disk-1.qcow2,size=32G", "scsi1": "vm-101-disk-2.qcow2,size=32G", "scsi2": "vm-101-disk-3.qcow2,...