question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How Swipable List use FlatList not ListView?

See original GitHub issue

react-native, react and native-base version

react-native 0.49 react 16.0.0 native-base 2.3.4

Expected behaviour

Use Swipable List with recommended FlatList

Actual behaviour

Now the example in the docs using Swipable List with depleted ListView

Steps to reproduce (code snippet or screenshot)

render() {
    const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
    return (
      <Container>
        <Header />
        <Content>
          <List
            dataSource={this.ds.cloneWithRows(this.state.listViewData)}
            renderRow={data =>
              <ListItem>
                <Text> {data} </Text>
              </ListItem>}
            renderLeftHiddenRow={data =>
              <Button full onPress={() => alert(data)}>
                <Icon active name="information-circle" />
              </Button>}
            renderRightHiddenRow={(data, secId, rowId, rowMap) =>
              <Button full danger onPress={_ => this.deleteRow(secId, rowId, rowMap)}>
                <Icon active name="trash" />
              </Button>}
            leftOpenValue={75}
            rightOpenValue={-75}
          />
        </Content>
      </Container>
    );

Question

How can I use FlatList with Swipeable List and Swipeable Row?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
akhil-gacommented, Dec 8, 2017

@Jancat Pasting a sample code

import React, { Component } from 'react';
import { Container, Header, Content, SwipeRow, View, Text, Icon, Button } from 'native-base';
import { FlatList } from 'react-native'

export default class App extends Component {
  constructor(props) {
    super(props)
    this.state = { data: [{ key: 1, value: 'one' }, { key: 2, value: 'two' }, { key: 3, value: 'three' }, { key: 4, value: 'four' }, { key: 5, value: 'five' }] }
  }

  removeItem(key) {
    let data = this.state.data
    data = data.filter((item) => item.key !== key)
    this.setState({ data })
  }

  render() {
    return (
      <Container>
        <Header />
        <Content scrollEnabled={false}>

          <FlatList
            data={this.state.data}
            renderItem={({ item }) => <SwipeRow
              leftOpenValue={75}
              rightOpenValue={-75}
              left={
                <Button success onPress={() => alert(item.value)} >
                  <Icon active name="add" />
                </Button>
              }
              body={
                <View>
                  <Text style={{ paddingLeft: 15 }}>{item.value}</Text>
                </View>
              }
              right={
                <Button danger onPress={() => this.removeItem(item.key)}>
                  <Icon active name="trash" />
                </Button>
              }
            />}
          />
        </Content>
      </Container>
    );
  }
}

Gif

swiperow

0reactions
iKrushYoucommented, Jun 8, 2019

@akhil-geekyants do you know if NativeBase ever switched over to FlatList?

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to get current flat list item data in reactnative using react ...
I'm not getting how to get the current item object of a flat list. I used react-native-swipeout and react-native-swipe-list-view and in both ...
Read more >
react-native-swipe-list-view-fix - npm
ListView that renders SwipeRows. Props. useFlatList. Render list using React Native's FlatList. type: bool. defaultValue: ...
Read more >
FlatList - React Native
FlatList. A performant interface for rendering basic, flat lists, supporting the most handy features: Fully cross-platform.
Read more >
Swipe List - NativeBase
Swipe List. SwipeListView is a vertical ListView with rows that swipe open and closed. ... Here is an example to show how easily...
Read more >
React Native Show Message for empty FlatList
Here is some line of code that we have used to show the message for the empty List. <FlatList data={dataSource} keyExtractor={(item, index) =>...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found