Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ########## Import Dependencies Here ##########
- import React, { Component } from 'react';
- import RNFetchBlob from 'react-native-fetch-blob';
- // ########## Import Screens Here ##########
- import ReadMore from './ReadMore';
- // ########## Import Components Here ##########
- import { fetchPosts } from '../config/api';
- const {height, width} = Dimensions.get('window');
- let dirs = RNFetchBlob.fs.dirs;
- export default class Home extends Component {
- constructor() {
- super();
- var dataSource = new ListView.DataSource({
- rowHasChanged: (r1, r2) => r1 !== r2
- });
- this.state = {
- isLoading: true,
- dataSource: dataSource.cloneWithRows([]),
- }
- fetchPosts();
- }
- componentDidMount() {
- if(Platform.OS === 'ios') {
- 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';
- let arr = fileUri.split('/');
- const dirs = RNFetchBlob.fs.dirs;
- filePath = `${dirs.CacheDir}/${arr[arr.length-1]}`;
- } else {
- filePath: '/data/user/0/{com.your-bundle-id}/cache/{projectName}';
- }
- RNFetchBlob.fs
- .readFile(filePath, 'utf8')
- .then((res) => {
- jsonData = JSON.parse(res);
- return jsonData;
- })
- .then((jsonData) => {
- this.setState({
- isLoading: false,
- dataSource: this.state.dataSource.cloneWithRows(jsonData.posts)
- })
- });
- }
- render() {
- null
- );
- }
- }
Add Comment
Please, Sign In to add comment