Guest User

Untitled

a guest
Mar 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // ########## Import Dependencies Here ##########
  2. import React, { Component } from 'react';
  3. import RNFetchBlob from 'react-native-fetch-blob';
  4.  
  5. // ########## Import Screens Here ##########
  6. import ReadMore from './ReadMore';
  7.  
  8. // ########## Import Components Here ##########
  9. import { fetchPosts } from '../config/api';
  10.  
  11. const {height, width} = Dimensions.get('window');
  12.  
  13. let dirs = RNFetchBlob.fs.dirs;
  14.  
  15. export default class Home extends Component {
  16.  
  17. constructor() {
  18. super();
  19. var dataSource = new ListView.DataSource({
  20. rowHasChanged: (r1, r2) => r1 !== r2
  21. });
  22. this.state = {
  23. isLoading: true,
  24. dataSource: dataSource.cloneWithRows([]),
  25. }
  26. fetchPosts();
  27. }
  28.  
  29. componentDidMount() {
  30. if(Platform.OS === 'ios') {
  31. let fileUri = '/Users/taimoorkhan/Library/Developer/CoreSimulator/Devices/2149B687-A347-4C12-82FB-B83CA14B59D8/data/Containers/Data/Application/6B6B2061-56EE-40EA-A3B3-812264BD860B/Library/Caches/vinthub';
  32. let arr = fileUri.split('/');
  33. const dirs = RNFetchBlob.fs.dirs;
  34. filePath = `${dirs.CacheDir}/${arr[arr.length-1]}`;
  35. } else {
  36. filePath: '/data/user/0/{com.your-bundle-id}/cache/{projectName}';
  37. }
  38. RNFetchBlob.fs
  39. .readFile(filePath, 'utf8')
  40. .then((res) => {
  41. jsonData = JSON.parse(res);
  42. return jsonData;
  43. })
  44. .then((jsonData) => {
  45. this.setState({
  46. isLoading: false,
  47. dataSource: this.state.dataSource.cloneWithRows(jsonData.posts)
  48. })
  49. });
  50. }
  51.  
  52. render() {
  53. null
  54. );
  55. }
  56. }
Add Comment
Please, Sign In to add comment