Convert Figma logo to code with AI

aksonov logoreact-native-tableview

Native iOS UITableView for React Native with JSON support and more

1,419
185
1,419
27

Top Related Projects

✌️ ListView with pull-to-refresh and infinite scrolling for Android and iOS React-Native apps

Easy React Native Layout & Grid for the Dumb

High performance listview for React Native and web!

UI Components Library for React Native

Material Design for React Native (Android & iOS)

Cross-Platform React Native UI Toolkit

Quick Overview

React Native TableView is a native iOS UITableView component for React Native applications. It provides a high-performance, customizable table view implementation that closely mimics the native iOS look and feel while allowing for easy integration with React Native projects.

Pros

  • High performance due to native implementation
  • Closely resembles native iOS UITableView in appearance and behavior
  • Supports various cell types and customization options
  • Easy integration with React Native projects

Cons

  • iOS-only, not suitable for cross-platform development
  • Limited documentation and examples
  • Relatively small community compared to some other React Native components
  • May require additional native code knowledge for advanced customization

Code Examples

  1. Basic TableView setup:
import TableView from 'react-native-tableview';

const MyComponent = () => (
  <TableView>
    <TableView.Section>
      <TableView.Item>Row 1</TableView.Item>
      <TableView.Item>Row 2</TableView.Item>
    </TableView.Section>
  </TableView>
);
  1. TableView with multiple sections:
<TableView>
  <TableView.Section header="Section 1">
    <TableView.Item>Item 1</TableView.Item>
    <TableView.Item>Item 2</TableView.Item>
  </TableView.Section>
  <TableView.Section header="Section 2">
    <TableView.Item>Item 3</TableView.Item>
    <TableView.Item>Item 4</TableView.Item>
  </TableView.Section>
</TableView>
  1. TableView with custom cell styles:
<TableView>
  <TableView.Section>
    <TableView.Item style={{backgroundColor: 'lightblue'}}>
      Custom styled row
    </TableView.Item>
    <TableView.Item accessoryType="DisclosureIndicator">
      Row with disclosure indicator
    </TableView.Item>
  </TableView.Section>
</TableView>

Getting Started

  1. Install the package:

    npm install react-native-tableview
    
  2. Link the native module:

    react-native link react-native-tableview
    
  3. Import and use in your React Native component:

    import TableView from 'react-native-tableview';
    
    const MyComponent = () => (
      <TableView>
        <TableView.Section>
          <TableView.Item>Hello, TableView!</TableView.Item>
        </TableView.Section>
      </TableView>
    );
    

Competitor Comparisons

✌️ ListView with pull-to-refresh and infinite scrolling for Android and iOS React-Native apps

Pros of react-native-gifted-listview

  • More customizable with features like pull-to-refresh and infinite scrolling
  • Supports both iOS and Android platforms
  • Includes built-in loading and empty list views

Cons of react-native-gifted-listview

  • Less native-like appearance compared to react-native-tableview
  • May require more setup and configuration for basic use cases
  • Not specifically optimized for iOS table view functionality

Code Comparison

react-native-gifted-listview:

<GiftedListView
  rowView={this._renderRowView}
  onFetch={this._onFetch}
  firstLoader={true}
  pagination={true}
  refreshable={true}
/>

react-native-tableview:

<TableView>
  <Section>
    <Cell cellStyle="Basic" title="Basic" />
    <Cell cellStyle="RightDetail" title="RightDetail" detail="Detail" />
  </Section>
</TableView>

The react-native-gifted-listview code shows its focus on customization and advanced features like pagination and refreshable lists. In contrast, the react-native-tableview code demonstrates its simplicity and native-like structure for creating table views, especially suited for iOS applications.

react-native-gifted-listview offers more flexibility and cross-platform support, making it suitable for complex list requirements. However, react-native-tableview provides a more straightforward approach for creating native-looking table views, particularly for iOS apps, with less setup required for basic use cases.

Easy React Native Layout & Grid for the Dumb

Pros of react-native-easy-grid

  • More flexible layout system with grid-based components
  • Easier to create responsive designs across different screen sizes
  • Better documentation and examples for quick implementation

Cons of react-native-easy-grid

  • May have a steeper learning curve for developers new to grid systems
  • Less performant for large, complex layouts compared to native TableView
  • Limited styling options for individual cells

Code Comparison

react-native-easy-grid:

import { Grid, Row, Col } from 'react-native-easy-grid';

<Grid>
  <Row>
    <Col><Text>Column 1</Text></Col>
    <Col><Text>Column 2</Text></Col>
  </Row>
</Grid>

react-native-tableview:

import TableView from 'react-native-tableview';

<TableView>
  <Section>
    <Item>Row 1</Item>
    <Item>Row 2</Item>
  </Section>
</TableView>

react-native-easy-grid offers a more flexible layout system with its Grid, Row, and Col components, making it easier to create responsive designs. However, it may have a steeper learning curve and potentially lower performance for complex layouts. react-native-tableview provides a more native-like TableView experience with better performance for large datasets but offers less flexibility in terms of layout customization. The code comparison shows the different approaches to creating structured layouts in each library.

High performance listview for React Native and web!

Pros of recyclerlistview

  • Cross-platform support for React Native and web applications
  • Highly performant with optimized rendering for large lists
  • Flexible layout system with support for grid and variable-sized items

Cons of recyclerlistview

  • Steeper learning curve due to more complex API
  • Requires more setup and configuration compared to simpler solutions
  • May be overkill for basic list implementations

Code Comparison

recyclerlistview:

<RecyclerListView
  layoutProvider={this._layoutProvider}
  dataProvider={this._dataProvider}
  rowRenderer={this._rowRenderer}
/>

react-native-tableview:

<TableView>
  <Section>
    <Cell cellStyle="Basic" title="Basic" />
    <Cell cellStyle="RightDetail" title="RightDetail" detail="Detail" />
  </Section>
</TableView>

recyclerlistview offers more flexibility and performance optimizations, while react-native-tableview provides a simpler, more declarative API for basic table views. The choice between the two depends on the complexity of your list requirements and the target platforms for your application.

UI Components Library for React Native

Pros of react-native-ui-lib

  • Comprehensive UI component library with a wide range of pre-built components
  • Highly customizable and themeable, allowing for consistent design across the app
  • Active development and regular updates, ensuring compatibility with the latest React Native versions

Cons of react-native-ui-lib

  • Larger package size due to the extensive component library
  • Steeper learning curve for developers new to the library's conventions
  • May require more setup and configuration compared to simpler libraries

Code Comparison

react-native-tableview:

<TableView>
  <Section header="Header">
    <Cell cellStyle="Basic" title="Basic" />
    <Cell cellStyle="RightDetail" title="RightDetail" detail="Detail" />
  </Section>
</TableView>

react-native-ui-lib:

<View>
  <Text text70 marginB-s4>Header</Text>
  <ListItem title="Basic" />
  <ListItem title="RightDetail" rightContent={<Text text80>Detail</Text>} />
</View>

The react-native-tableview code is more focused on creating table-like structures, while react-native-ui-lib offers a more flexible approach to building list-like components with customizable layouts. react-native-ui-lib provides a wider range of UI components beyond just table views, making it suitable for various app design needs.

Material Design for React Native (Android & iOS)

Pros of react-native-paper

  • Comprehensive UI component library with a wide range of pre-built components
  • Follows Material Design guidelines, ensuring a consistent and modern look
  • Active development and community support, with frequent updates and improvements

Cons of react-native-paper

  • Larger bundle size due to the extensive component library
  • May require additional configuration for custom styling and theming
  • Some components might not be as performant as native implementations

Code Comparison

react-native-paper:

import { DataTable } from 'react-native-paper';

<DataTable>
  <DataTable.Header>
    <DataTable.Title>Name</DataTable.Title>
    <DataTable.Title>Age</DataTable.Title>
  </DataTable.Header>
  <DataTable.Row>
    <DataTable.Cell>John</DataTable.Cell>
    <DataTable.Cell>30</DataTable.Cell>
  </DataTable.Row>
</DataTable>

react-native-tableview:

import TableView from 'react-native-tableview';

<TableView>
  <TableView.Section>
    <TableView.Cell>John</TableView.Cell>
    <TableView.Cell>30</TableView.Cell>
  </TableView.Section>
</TableView>

react-native-paper offers a more structured and feature-rich table component, while react-native-tableview provides a simpler, native-like table implementation. The choice between the two depends on the specific requirements of your project, such as design consistency, performance needs, and desired customization options.

Cross-Platform React Native UI Toolkit

Pros of react-native-elements

  • Comprehensive UI toolkit with a wide range of customizable components
  • Active community and frequent updates
  • Extensive documentation and examples

Cons of react-native-elements

  • Larger bundle size due to the extensive component library
  • May require additional configuration for optimal performance
  • Some components might not fit perfectly with specific design requirements

Code Comparison

react-native-elements:

import { ListItem } from 'react-native-elements';

<ListItem
  title="John Doe"
  subtitle="Software Developer"
  leftAvatar={{ source: { uri: 'https://example.com/avatar.jpg' } }}
  bottomDivider
  chevron
/>

react-native-tableview:

import TableView from 'react-native-tableview';

<TableView>
  <TableView.Section>
    <TableView.Item value="John Doe">
      <Text>Software Developer</Text>
    </TableView.Item>
  </TableView.Section>
</TableView>

react-native-elements offers a more feature-rich ListItem component with built-in avatar and chevron support, while react-native-tableview provides a simpler, iOS-style TableView structure. react-native-elements is more suitable for cross-platform development with a wider range of UI components, whereas react-native-tableview is focused on creating native iOS-like table views in React Native applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Native TableView

Native iOS UITableView for React Native with JSON support

npm version npm downloads code style: prettier

Contents

Features

  • Look and feel of iOS TableView - because it is! (with group/plain tableview type, sections headers, etc)
  • Display long lists of data (like country list) with no performance loss
  • Built-in accessory types (checkmark or disclosure indicator)
  • Pull to refresh!
  • Automatic scroll to initial selected value during component initialization (autoFocus property)
  • Automatic item selection with "checkmark" with old item de-selection (optionally), see demo, useful to select country/state/etc.
  • Render Native Section Index Titles (sectionIndexTitlesEnabled property)
  • Native JSON support for datasource. If you need to display large dataset, generated Javascript will became very large and impact js loading time. To solve this problem the component could read JSON directly from app bundle without JS!
  • Filter JSON datasources using NSPredicate syntax. For example you could select states for given country only (check demo)
  • Create custom UITableView cells with flexible height using React Native syntax (TableView.Cell tag)
  • Use TableView as menu to navigate to other screens (check included demo, using react-navigation https://reactnavigation.org)
  • Native editing mode for table - move/delete option is supported by using attributes canMove, canEdit for items/sections

Installation

Using npm:

npm install react-native-tableview --save

or using yarn:

yarn add react-native-tableview

⚠️ If you are on React Native < 0.60.0, you must use version 2.x.x of this library

Pods

If using CocoaPods or React Native version >= 0.60.0

cd ios && pod install && cd ..

Linking

For React Native <= 0.59 only

react-native link react-native-tableview

If fails, follow manual linking steps below,

Manual Linking

  1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
  2. Add ./node_modules/react-native-tableview/RNTableView.xcodeproj
  3. In the XCode project navigator, select your project, select the Build Phases tab and in the Link Binary With Libraries section add libRNTableView.a
  4. And in the Build Settings tab in the Search Paths/Header Search Paths section add $(SRCROOT)/../node_modules/react-native-tableview (make sure it's recursive).

Supported Styles

UITableView styles

These values are provided to the tableViewStyle prop.

<TableView tableViewStyle={TableView.Consts.Style.Grouped}>
StyleValuePreview
PlainTableView.Consts.Style.Plainalt text
GroupedTableView.Consts.Style.Groupedalt text

UITableViewCell styles

These values are provided to the tableViewCellStyle prop.

<TableView tableViewCellStyle={TableView.Consts.CellStyle.Default}>
StyleValuePreview
DefaultTableView.Consts.CellStyle.Defaultalt text
Value1TableView.Consts.CellStyle.Value1alt text
Value2TableView.Consts.CellStyle.Value2alt text
SubtitleTableView.Consts.CellStyle.Subtitlealt text

Accessory types

These values are provided to the accessoryType prop on the Item.

<Item accessoryType={TableView.Consts.AccessoryType.None}>
StyleValuePreview
NoneTableView.Consts.AccessoryType.Nonealt text
Disclosure IndicatorTableView.Consts.AccessoryType.DisclosureIndicatoralt text
Disclosure ButtonTableView.Consts.AccessoryType.DisclosureButtonalt text
CheckmarkTableView.Consts.AccessoryType.Checkmarkalt text
Detail ButtonTableView.Consts.AccessoryType.DetailButtonalt text

Disclosure Indicator can also be applied by adding the arrow prop on the section.

<Section arrow>

Checkmark can also be applied by adding the selected prop on the Item.

<Item selected>

Props

For a full list of props on all components check out the typescript definitions file.

Methods

scrollTo()

Scrolls to a set of coordinates on the tableview.

/**
  * @param x Horizontal pixels to scroll
  * @param y Vertical pixels to scroll
  * @param animated With animation or not
  */
  scrollTo(x: number, y: number, animated: boolean): void;

scrollToIndex()

Scroll to an item in a section

/**
  * @param params scroll params
  * @param params.index index of the cell
  * @param params.section index of the section @default 0
  * @param params.animated scroll with animation @default true
  */
  scrollToIndex(params: { index: number, section?: number, animated?: boolean }): void;

List item format

Items in the list can be either TableView.Item or TableView.Cell. An Item is simply text. A Cell can be any complex component. However, only Items can be edited or moved. There are also issues with Cells re-rendering on data changes (#19) that can be avoided by using Items. If you want to be able to re-render, edit or move a complex component, use reactModuleForCell, described in Editable Complex Components.

Examples

Smooth scrolling with large network loaded list

demo-3

() => {
  const [loading, setLoading] = useState(true);
  const [users, setUsers] = useState([]);

  useEffect(() => {
    const getUsers = async () => {
      const response = await fetch('https://randomuser.me/api/?results=5000');
      const data = await response.json();

      setLoading(false);
      setUsers(
        data.results.map(a => ({
          name: `${a.name.first} ${a.name.last}`,
          id: a.registered,
        }))
      );
    };

    getUsers();
  }, []);

  return (
    <View style={{ flex: 1 }}>
      <Text style={styles.title}>
        {loading ? 'Fetching' : 'Fetched'} 5000 users
      </Text>

      {loading && <ActivityIndicator />}

      <TableView
        style={{ flex: 1 }}
        tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
      >
        <Section>
          {users.map(a => (
            <Item key={a.id}>{a.name}</Item>
          ))}
        </Section>
      </TableView>
    </View>
  );
};

App-bundled JSON with filter and selected value checkmarked

editing example

// list spanish provinces and add 'All states' item at the beginning

const country = 'ES';

return (
  <View style={{ flex: 1 }}>
    <Text style={styles.title}>Showing States in Spain</Text>
    <TableView
      style={{ flex: 1 }}
      json="states"
      selectedValue="ES53"
      filter={`country=='${country}'`}
      tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
      onPress={event => alert(JSON.stringify(event))}
    />
  </View>
);

Built-in editing

editing example

render() {
  return (
    <View style={{ flex: 1 }}>
      <TableView
        style={{ flex: 1 }}
        editing={navigation.getParam('editing')}
      >
        <Section canMove canEdit>
          <Item canEdit={false}>Item 1</Item>
          <Item>Item 2</Item>
          <Item>Item 3</Item>
          <Item>Item 4</Item>
          <Item>Item 5</Item>
          <Item>Item 6</Item>
          <Item>Item 7</Item>
          <Item>Item 8</Item>
        </Section>
      </TableView>
    </View>
  )
}

Pull to Refresh

pull to refresh example

function reducer(state, action) {
  switch (action.type) {
    case 'getUsers':
      return { ...state, loading: false, users: action.payload };
    case 'startRefresh':
      return { ...state, refreshing: true };
    case 'endRefresh':
      return {
        ...state,
        refreshing: false,
        amount: state.amount + 10,
        users: [...state.users, ...action.payload],
      };
    default:
      return state;
  }
}

() => {
  const [{ loading, amount, refreshing, users }, dispatch] = useReducer(
    reducer,
    {
      loading: true,
      users: [],
      refreshing: false,
      amount: 10,
    }
  );

  useEffect(() => {
    const getUsers = async () => {
      const data = await fetchUsers();
      dispatch({ type: 'getUsers', payload: data });
    };

    getUsers();
  }, []);

  const fetchUsers = async () => {
    const response = await fetch('https://randomuser.me/api/?results=10');
    const data = await response.json();

    return data.results.map(a => ({
      name: `${a.name.first} ${a.name.last}`,
      id: a.login.uuid,
    }));
  };

  const fetchMore = async () => {
    dispatch({ type: 'startRefresh' });
    const data = await fetchUsers();
    dispatch({ type: 'endRefresh', payload: data });
  };

  return (
    <View style={{ flex: 1 }}>
      <Text style={styles.title}>
        {loading ? 'Fetching' : 'Fetched'} {amount} users
      </Text>

      {loading && <ActivityIndicator />}

      <TableView
        style={{ flex: 1 }}
        tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
        canRefresh
        refreshing={refreshing}
        onRefresh={fetchMore}
      >
        <Section>
          {users.map(a => (
            <Item key={a.id}>{a.name}</Item>
          ))}
        </Section>
      </TableView>
    </View>
  );
};
}

Customization

The following style props are supported:

  • tableViewCellStyle
  • tableViewCellEditingStyle
  • separatorStyle
  • contentInset
  • contentOffset
  • scrollIndicatorInsets
  • cellLayoutMargins
  • cellSeparatorInset

Colors:

  • textColor
  • tintColor
  • selectedTextColor
  • detailTextColor
  • separatorColor
  • headerTextColor
  • headerBackgroundColor
  • footerTextColor

Base font:

  • fontSize
  • fontWeight
  • fontStyle
  • fontFamily

"Subtitle" font:

  • detailFontSize
  • detailFontWeight
  • detailFontStyle
  • detailFontFamily

Header font:

  • headerFontSize
  • headerFontWeight
  • headerFontStyle
  • headerFontFamily

Footer font:

  • footerFontSize
  • footerFontWeight
  • footerFontStyle
  • footerFontFamily

Images / Icons

An Item component takes an image and an optional imageWidth prop.

An image prop can be a string pointing to the name of an asset in your "Asset Catalog". In this case an imageWidth prop is recommended.

<Item image="icon-success.png" imageWidth={40} />

Alternatively, you can require the image from your local app code. In this case an imageWidth is unnecessary.

<Item image={require('../images/icon-success.png')} />

Editable Complex Components

Only Items can be edited or moved. However you can create a complex component that is referenced by an Item using reactModuleForCell. You will need to do several things to set this up.

  1. Write your view component.
  2. Pass the name of your view component as a prop in your <TableView> component.
  3. Create a list of <Item>s in your TableView, passing props intended for your view component.
  4. Register your view component as an App root view.

Write your cell view component.

For example,

//Should be pure... setState on top-level component doesn't seem to work

class TableViewExampleCell extends React.Component {
  render() {
    var style = { borderColor: '#aaaaaa', borderWidth: 1, borderRadius: 3 };

    // Fill the full native table cell height.
    style.flex = 1;

    // All Item props get passed to this cell inside this.props.data. Use them to control the rendering, for example background color:
    if (this.props.data.backgroundColor !== undefined) {
      style.backgroundColor = this.props.data.backgroundColor;
    }

    return (
      <View style={style}>
        <Text>
          section:{this.props.section},row:{this.props.row},label:
          {this.props.data.label}
        </Text>
        <Text> message:{this.props.data.message}</Text>
      </View>
    );
  }
}

For more examples, see examples/TableViewDemo.

Pass component as prop.

<TableView reactModuleForCell="TableViewExampleCell" >

Create list of items, passing props

<Section canEdit={true}>
  {this.props.items.map(function(item) {
    return (
      <Item
        key={'i' + item.data.date}
        label={item.label}
        message={item.message}
      />
    );
  })}
</Section>

Note that the props you pass must be primitive types: they cannot be objects. Also, note that the props become properties of the data prop in your reactModuleForCell component. That is, you pass label="foo" and in your component you pick it up as this.props.data.label.

Register your component.

Each cell you render becomes a reuseable root view or App.

var { AppRegistry } = React;

...

AppRegistry.registerComponent('TableViewExample', () => TableViewExample);

When debugging, you will see the message:

Running application "TableViewExample" with appParams: { /* params */ }. __DEV__ === true, development-level warning are ON, performance optimizations are OFF

multiple times. While slightly annoying, this does not seem to affect performance. You may also see message Unbalanced calls start/end for tag 5.

NPM DownloadsLast 30 Days