npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-swipable-list-row

v1.0.3

Published

A simple and efficient react native swipable list row

Downloads

10

Readme

react-native-swipable-list-row

NOTICE

This one is deprecated!!! Don't USE IT!!!

As npmjs.org not allowed to unpublish the repo (which I didn't know before), and I didn't know that wix had a pretty awesome one, so this one is not going to be maintained anymore. SORRY.

You can check the same one in wix/react-native-interactable.

Introduction

A simple and efficient react native swipable list row implementation.

To make a swipable list row, we had two challenges:

  • The back/hidden row layout should keep up with front/visible row.
  • The listView scroll should be disabled while pull the row.

By using Animated.View, and Animated.event to hack the onLayout event, it provide more efficient way to update layout, as they all happened in native side, no re-render required.

By using setNativeProps from list view, it will be able to do the second one.

Just notice, setNativeProps is supported in FlatList from RN >= 0.47only.

The code is inspired by Tal Kol speech at React Conf 2017.

https://www.youtube.com/watch?v=mjsv8NJnt5k

Usage

You can do installation:

npm install -S react-native-swipable-list-row

Or just copy to use it in your project, more better.

import React, { Component } from 'react';

import {
  View,
  Text,
  ScrollView,
  Dimensions,
  TouchableHighlight,
  FlatList,
} from 'react-native';

import SwipableRowView from './SwipableRowView';


const window = Dimensions.get('window');

export default class ExampleView extends Component {

  constructor(props) {
    super(props);

    this.state = {
      value: 'Hello row',
    };

    this.data = [];
    for (let i = 0; i < 50; i += 1) {
      this.data.push({
        title: 'Row#' + i,
        id: i,
      });
    }
    this.update = 0;
    this.panResponder = null;
    this.rowView = null;
    this.scrollView = null;
  }

  keyExtractor = item => item.id

  renderVisibleRow = (item, closeRow) => (
    <TouchableHighlight
      style={{ flex: 1, marginBottom: 1, backgroundColor: '#F7F7F7' }}
      underlayColor={'#CCC'}
      activeOpacity={0.9}
      onPress={() => {
        item.title = 'Hello, this is a pretty long text to test the layout change in front row, so I will put something more here, blah, blah, blah...... ';
        
        // I send closeRow from SwipableRowView here
        // to test touch to close the row
        // you can do your way
        
        closeRow();
        this.update += 1;
        this.forceUpdate();
      }}
    >
      <View style={{
        justifyContent: 'center',
        alignItems: 'flex-start',
        // opacity: 0.3,
        backgroundColor: '#F7F7F7',
        paddingVertical: 20,
      }}
      >
        <Text style={{ color: 'black' }} >
          {item.title}
        </Text>
      </View>
    </TouchableHighlight>
  );

  renderHiddenRow = () => {
    return (
      <View style={{
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'flex-end',
        alignItems: 'center',
        backgroundColor: '#bedaf7',
        // paddingVertical: 20,
        marginBottom: 1,
      }}
      >
        <Button>
          Delete
        </Button>
      </View>
    );
  }

  renderRow = (rowData) => {
    const item = rowData.item;

    return (
      <SwipableRowView
        ref={(ref) => {
          this.rowView = ref;
        }}
        renderVisibleRow={(close) => this.renderVisibleRow(item, close)}
        renderHiddenRow={this.renderHiddenRow}
        rightOffset={-100}
        listView={this.scrollView}
      />
    );
  }

  render() {
    return (
      <View style={{ flex: 1, paddingTop: 55, paddingBottom: 50 }} >
        <FlatList
          ref={(ref) => {
            this.scrollView = ref;
          }}
          style={{ flex: 1, backgroundColor: '#DDD' }}
          initialNumToRender={10}
          data={this.data}
          renderItem={this.renderRow}
          keyExtractor={this.keyExtractor}
          // extraData={this.update}
          windowSize={11}
          // scrollEnabled={false}
        />

      </View>
    );
  }
}