Giter Site home page Giter Site logo

sophiawang611 / react-native-tableview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aksonov/react-native-tableview

0.0 2.0 0.0 680 KB

Native iOS UITableView for React Native with JSON support and more

License: BSD 2-Clause "Simplified" License

Objective-C 78.40% JavaScript 21.60%

react-native-tableview's Introduction

react-native-tableview

Native iOS UITableView for React Native with JSON support.

Why I need to use it?

  • Look and feel native iOS TableView (with group/plain tableview type, sections headers, etc)
  • To display long lists of data (like country list) - built-in list view has performance issues for long lists
  • To use built-in accessory types (checkmark or disclosure indicator)
  • 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.
  • 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 app screen (check included demo, it uses flux router https://github.com/aksonov/react-native-router-flux)
  • Native editing mode for table - move/delete option is supported by using attributes canMove, canEdit for items/sections

Supports UITableView styles

  • UITableViewStylePlain (TableView.Consts.Style.Plain)
  • UITableViewStyleGrouped (TableView.Consts.Style.Grouped)

Supports UITableViewCell styles

  • UITableViewCellStyleDefault (TableView.Consts.CellStyle.Default)
  • UITableViewCellStyleValue1 (TableView.Consts.CellStyle.Value1)
  • UITableViewCellStyleValue2 (TableView.Consts.CellStyle.Value2)
  • UITableViewCellStyleSubtitle (TableView.Consts.CellStyle.Subtitle)

Supports accessory types

  • UITableViewCellAccessoryDisclosureIndicator ("arrow" attribute for TableView.Item or TableView.Section)
  • UITableViewCellAccessoryCheckmark ("selected" attribute for TableView.Item)

Example 1

demo-3

'use strict';

var React = require('react-native');
var { AppRegistry } = React;
var TableView = require('react-native-tableview');
var Section = TableView.Section;
var Item = TableView.Item;

class TableViewExample extends React.Component {
    render(){
        return (
            <TableView style={{flex:1}}
                       tableViewStyle={TableView.Consts.Style.Grouped}
                       tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
                       onPress={(event) => console.log(event)}>
                <Section label="Section 1" arrow={true}>
                    <Item value="1" detail="Detail1" >Item 1</Item>
                    <Item value="2">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>
                    <Item>Item 9</Item>
                    <Item>Item 10</Item>
                    <Item>Item 11</Item>
                    <Item>Item 12</Item>
                    <Item>Item 13</Item>
                    <Item>Item 14</Item>
                    <Item>Item 15</Item>
                    <Item>Item 16</Item>
                    <Item>Item 17</Item>
                    <Item>Item 18</Item>
                    <Item>Item 19</Item>
                </Section>
                <Section label="Section 2" arrow={false}>
                    <Item selected={true}>Item 1</Item>
                    <Item>Item 2</Item>
                    <Item>Item 3</Item>
                </Section>
            </TableView>
        );
    }
}

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

Example 2 (JSON source support), reads country list JSON from app bundle and display UITableView with selected value checkmarked

demo2

    render(){
        return (
            <TableView selectedValue="ES" style={{flex:1}} json="countries"
                       tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
                       onPress={(event) => console.log(event)}/>
        );
    }

Example 3 (JSON filter and optional items at the beginning)

    // list spanish provinces and add 'All states' item at the beginning
    render(){
        var country = "ES";
        return (
            <TableView selectedValue="" style={{flex:1}} json="states" filter={`country=='${country}'`}
                       tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
                       onPress={(event) => console.log(event)}>
                <Item value="">All states</Item>
            </TableView>
        );
    }

Getting started

  1. npm install react-native-tableview --save
  2. In XCode, in the project navigator, right click Libraries โžœ Add Files to [your project's name]
  3. add ./node_modules/react-native-tableview/RNTableView.xcodeproj
  4. In the XCode project navigator, select your project, select the Build Phases tab and in the Link Binary With Libraries section add libRNTableView.a
  5. (optional) If you will use JSON file, add it to iOS application bundle
  6. var TableView = require('react-native-tableview')

react-native-tableview's People

Contributors

cancan101 avatar gpbl avatar xlarsx avatar sst-nathan avatar oblador avatar nathan-smith avatar elliottsj avatar sophiawang611 avatar

Watchers

James Cloos avatar  avatar

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.