Native iOS UITableView for React Native with JSON support.
- 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
- UITableViewStylePlain (TableView.Consts.Style.Plain)
- UITableViewStyleGrouped (TableView.Consts.Style.Grouped)
- UITableViewCellStyleDefault (TableView.Consts.CellStyle.Default)
- UITableViewCellStyleValue1 (TableView.Consts.CellStyle.Value1)
- UITableViewCellStyleValue2 (TableView.Consts.CellStyle.Value2)
- UITableViewCellStyleSubtitle (TableView.Consts.CellStyle.Subtitle)
- UITableViewCellAccessoryDisclosureIndicator ("arrow" attribute for TableView.Item or TableView.Section)
- UITableViewCellAccessoryCheckmark ("selected" attribute for TableView.Item)
'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
render(){
return (
<TableView selectedValue="ES" style={{flex:1}} json="countries"
tableViewCellStyle={TableView.Consts.CellStyle.Subtitle}
onPress={(event) => console.log(event)}/>
);
}
// 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>
);
}
npm install react-native-tableview --save
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- add
./node_modules/react-native-tableview/RNTableView.xcodeproj
- In the XCode project navigator, select your project, select the
Build Phases
tab and in theLink Binary With Libraries
section add libRNTableView.a - (optional) If you will use JSON file, add it to iOS application bundle
var TableView = require('react-native-tableview')