Git Product home page Git Product logo

Comments (8)

bfarrgaynor avatar bfarrgaynor commented on July 24, 2024 3

@SteffenC rather than calling a local function on the list component, I make each item it's own component.

In my main component (the list):

render: function() {

            return (
                <View style={gStyles.listViewMax}>

                       <ListView
                        dataSource={this.state.dataSource}
                        renderRow={this.renderAlert}
                        style={gStyles.jobListView}
                      />

                </View>
             );
},

renderAlert: function(job) {
        return (<AlertListItem alertKeyType={this.state.alertKeyType} job={job} />);
  },

My AlertListItem.js (Component)

 render: function() {

        var myButtons = null;

        if(this.state.read) {
                myButtons  = [
                      {
                        text: 'Mark as Unread',
                        backgroundColor: '#FCA612',
                        color:'white',
                        onPress: () => { 
                               this.markRead('markunread');
                             },
                      }
                    ];
         } else {
                myButtons = [
                      {
                        text: 'Mark as Read',
                        backgroundColor: '#FCA612',
                        color:'white',
                        onPress: () => { 
                               this.markRead('markread');
                             },
                      }
                    ];

         }

         let swipeoutBtns = myButtons;

        return (<Swipeout autoClose={true} job={this.props.job} right={swipeoutBtns}>
              <View style={gStyles.alertListViewItemContainer}>
                  <View style={gStyles.alertListViewItemContainerButton}>

                          <View style={gStyles.alertListViewItemPersonalDetails}> 
                              <Text style={gStyles.alertListViewItemName}>{this.props.job.firstname} {this.props.job.lastname}</Text>
                              <Text style={gStyles.alertListViewItemNote}>{this.props.job.note}</Text>
                              <Text style={gStyles.alertListViewItemTimeAgo}>{this.props.job.datetime}</Text>
                          </View>


                          <View style={gStyles.alertListViewItemReadFlag}> 
                            {this.readOrNot()}
                          </View>
                  </View>
              </View>
        </Swipeout>);

... in this way I can use the props or the state on the component to store anything I want about that particular list item.

from react-native-swipeout.

bfarrgaynor avatar bfarrgaynor commented on July 24, 2024 2

Ok so I think I figured out an approach.

`

renderRow: function(rowData) {


    let swipeoutBtns = [
          {
            text: 'Mark as read',
            onPress: () => { 
                   this.markAsRead(rowData);
                 },
          }
        ];



return (
      <Swipeout autoClose={true} right={swipeoutBtns}>
 // ... rest of your row render function

`

from react-native-swipeout.

rsp8055 avatar rsp8055 commented on July 24, 2024 1

It's so simple, the solution is here

` right: [
{
onPress: () => {

                    const deletingRow = this.state.activeRowKey;
                    const jsonData = this.state.jsonData;

                    Alert.alert(
                        'Delete',
                        'Are you sure you want to delete ?',
                        [
                            { text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
                            {
                                text: 'Yes', onPress: () => {
                                    jsonData.splice(this.props.index, 1);
                                    this.props.parentFlatList.refreshFlatList(deletingRow);
                                }
                            },
                        ],
                        { cancelable: true }
                    );

                },
                component: <SwipeDelete />,
            },
        ],`

from react-native-swipeout.

SteffenC avatar SteffenC commented on July 24, 2024

@bfarrgaynor Could you share a bit more of your code ? I'm having the same issue, and can't quite see how this should work

from react-native-swipeout.

SteffenC avatar SteffenC commented on July 24, 2024

@bfarrgaynor Beautiful ! Thank you very much!

from react-native-swipeout.

rsp8055 avatar rsp8055 commented on July 24, 2024

How to pass the onPress function as a prop to the custom component, here I tried some but not working
` right: [
{
onPress() {

                    const deletingRow = this.state.activeRowKey;
                    const jsonData = this.state.jsonData;

                    Alert.alert(
                        'Delete',
                        'Are you sure you want to delete ?',
                        [
                            { text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
                            {
                                text: 'Yes', onPress: () => {
                                    jsonData.splice(this.props.index, 1);
                                    this.props.parentFlatList.refreshFlatList(deletingRow);
                                }
                            },
                        ],
                        { cancelable: true }
                    );

                },

                component: <SwipeDelete onPressFun={onPress()} />     // here to pass above onPress() ?
            }
        ],

`

from react-native-swipeout.

mangleshyadav avatar mangleshyadav commented on July 24, 2024

@rsp8055
Could you please create a demo for the same on "https://expo.io/snacks" ?.
It would be very helpful to understand.

from react-native-swipeout.

rsp8055 avatar rsp8055 commented on July 24, 2024

Here you can find out the example : https://www.youtube.com/watch?v=9qof4eCt9UY

from react-native-swipeout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.