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
- 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)
- 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>
<Item>Item 20</Item>
<Item>Item 21</Item>
<Item>Item 22</Item>
<Item>Item 23</Item>
<Item>Item 24</Item>
<Item>Item 25</Item>
<Item>Item 26</Item>
<Item>Item 27</Item>
<Item>Item 28</Item>
<Item>Item 29</Item>
<Item>Item 30</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>
);
}
render(){
var Cell = TableView.Cell;
return (
<TableView style={{flex:1}} onPress={(event) => alert(JSON.stringify(event))} selectedValue="1">
<Section label="section 1">
<Cell style={{backgroundColor:'gray'}} value="">
<Text style={{color:'white', textAlign:'right'}}>Cell 1</Text>
<Text style={{color:'white', textAlign:'left'}}>Cell 1</Text>
</Cell>
<Cell style={{height:200, backgroundColor:'red'}}><Text>Cell 2</Text></Cell>
<Cell><Text>Cell 3</Text></Cell>
<Cell style={{height:100}}><Text>Cell 4</Text></Cell>
<Cell><Text>Cell 5</Text></Cell>
</Section>
<Section label="section 2">
<Cell style={{backgroundColor:'gray'}} value="1">
<Text style={{color:'white', textAlign:'right'}}>Cell 1.1</Text>
<Text style={{color:'white', textAlign:'left'}}>Cell 1.1</Text>
</Cell>
<Cell style={{height:200, backgroundColor:'red'}}><Text>Cell 1.2</Text></Cell>
<Cell><Text>Cell 3</Text></Cell>
<Cell style={{height:100}}><Text>Cell 4</Text></Cell>
<Cell><Text>Cell 5</Text></Cell>
</Section>
</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/RCTTableView.xcodeproj - In the XCode project navigator, select your project, select the
Build Phasestab and in theLink Binary With Librariessection add libRCTTableView.a - (optional) If you will use JSON file, add it to iOS application bundle
var TableView = require('react-native-tableview')

