Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. {
  2.  
  3.   "Observer":
  4.  
  5. {
  6.  
  7.   "Category_2":
  8.  
  9. [{
  10.  
  11.   "row1" : "Reading_1",
  12.  
  13.   "row2" : "Reading_2",
  14.  
  15.   "row3" : "Reading_3",
  16.  
  17.   "row4" : "Reading_4"
  18.  
  19. }]
  20.  
  21. }
  22.  
  23. }
  24.  
  25. import React, { Component } from 'react';
  26.  
  27. import { AppRegistry, View, Text,TouchableOpacity, ListView, StyleSheet,SectionList } from 'react-native';
  28.  
  29. import { createStackNavigator,createAppContainer } from "react-navigation";
  30.  
  31. const data_Custom = require('./Observer.json');
  32.  
  33.  
  34. class RenderList extends Component
  35.  
  36. {
  37.  
  38.   static navigationOptions = 
  39.  
  40. {
  41.  
  42.   title: 'List Items'
  43.  
  44. };
  45.  
  46.   constructor() {
  47.  
  48.   super();
  49.  
  50.   var ds = new ListView.DataSource({
  51.  
  52.   rowHasChanged: (r1, r2) => r1 !== r2,
  53.  
  54.   sectionHeaderHasChanged: (h1, h2) => h1 !== h2,
  55.  
  56. });
  57.  
  58.   this.state = {
  59.  
  60.   dataSource: ds.cloneWithRowsAndSections({dataBlob: data_Custom}, {sectionIdentities:["Category_2"]}, {rowIdentities:["row1","row2","row3","row4"]} ),
  61.  
  62. };
  63.  
  64. }
  65.  
  66.  
  67.   renderRow(custom){
  68.  
  69.  return (
  70.  
  71.   <View >
  72.  
  73.   <Text style = { styles.container2 }>
  74.  
  75.   {custom.rowIdentities}
  76.  
  77.   </Text>
  78.  
  79.  </View>
  80.  
  81. );
  82.  
  83. }
  84.  
  85.  
  86.  
  87.   renderSectionHeader(custom_s) {
  88.  
  89.   return (
  90.  
  91.   <Text style = { styles.container2 }>
  92.  
  93.   {custom_s.sectionIdentities}
  94.  
  95.   </Text>
  96.  
  97. )
  98.  
  99. }
  100.  
  101.  
  102.   render() {
  103.  
  104.   return (
  105.  
  106.   <ListView
  107.  
  108.   dataSource={this.state.dataSource}
  109.  
  110.   renderRow={this.renderRow.bind(this)}
  111.  
  112.   renderSectionHeader={this.renderSectionHeader}
  113.  
  114.   />
  115.  
  116. );
  117.  
  118. }
  119.  
  120. }
  121.  
  122.  
  123. const App = createStackNavigator(
  124.  
  125. {
  126.  
  127.   List: { screen: RenderList },
  128.  
  129. });
  130.  
  131.  
  132. export default createAppContainer(App);
  133.  
  134.  
  135. const styles = StyleSheet.create(
  136.  
  137. {
  138.  
  139.   container1:
  140.  
  141. {
  142.  
  143.   flex: 1
  144.  
  145. },
  146.  
  147.   container2:
  148.  
  149. {
  150.  
  151.   flex: 1,
  152.  
  153.   justifyContent: 'center',
  154.  
  155.   alignItems: 'center',
  156.  
  157.   paddingHorizontal: 15,
  158.  
  159.   fontSize: 18
  160.  
  161. },
  162.  
  163.   item:
  164.  
  165. {
  166.  
  167.   padding: 15
  168.  
  169. },
  170.  
  171.   text:
  172.  
  173. {
  174.  
  175.   fontSize: 18
  176.  
  177. },
  178.  
  179.   separator:
  180.  
  181. {
  182.  
  183.   height: 2,
  184.  
  185.   backgroundColor: 'rgba(0,0,0,0.5)'
  186.  
  187. }
  188.  
  189. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement