Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Swipable List use FlatList not ListView? #1430

Closed
Jancat opened this issue Dec 8, 2017 · 7 comments
Closed

How Swipable List use FlatList not ListView? #1430

Jancat opened this issue Dec 8, 2017 · 7 comments

Comments

@Jancat
Copy link

Jancat commented Dec 8, 2017

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?

@akhil-ga
Copy link
Contributor

akhil-ga commented 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

@Jancat
Copy link
Author

Jancat commented Dec 8, 2017

@akhil-geekyants Thanks, I thought about this way using SwipeRow.
But the default behavior such closing rows when other rows are opened will be lost.
And the press event seems to be invalid, like this:

renderItem={({ item }) => (
  <TouchableHighlight onPress={() =>alert('press')}>  // don't alert
    <SwipeRow ... />
  </TouchableHighlight >
)       

I want to know whether there is a plan to use FlatList in Swipable List for better performance?

@akhil-ga
Copy link
Contributor

yes, NativeBase will be using FlatList in the upcoming major release.

@Jancat
Copy link
Author

Jancat commented Dec 14, 2017

By the way. I can't customize list item style in SwipeRow.
Such as I can't modify the default SwipeRow body style below:
image

Why not give a style property ?

@SupriyaKalghatgi
Copy link
Contributor

Fixed with 2.3.6

akhil-ga added a commit to GeekyAnts/native-base-docs that referenced this issue Mar 19, 2018
@gs-rbarman
Copy link

Does NativeBase 2.12.0 use FlatList for Swipable List too @akhil-geekyants ?

@iKrushYou
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants