jrshikoku/TestArea.js
harukin/DeskMini 9442a59feb InitialCommit
2021-04-02 18:38:05 +09:00

49 lines
1.6 KiB
JavaScript

import React, { Component, useEffect, useState } from 'react';
import {StatusBar,View,ScrollView,Linking,Text } from 'react-native';
import Constants from 'expo-constants';
import { ListItem } from 'react-native-elements';
import Icon from 'react-native-vector-icons/Entypo';
import StatusbarDetect from './StatusbarDetect';
var Status = StatusbarDetect();
let a=[];
export default function TestArea(props) {
const [data,setdata] = useState(null);
useEffect(()=>{
data==null ? test().then(res=>{
//console.log(res);
setdata(res);
}):null
},[data])
return (
<View style={{height:"100%",paddingTop: Constants.statusBarHeight,}}>
{Status}
<ScrollView>
<Text>TEST AREA!!</Text>
{data}
</ScrollView>
</View>
);
}
async function test(){
return fetch('https://train.jr-shikoku.co.jp/g?arg1=train&arg2=train', {
headers: {
'authority': 'train.jr-shikoku.co.jp',
'cache-control': 'no-cache',
'pragma': 'no-cache',
'if-modified-since': 'Thu, 01 Jun 1970 00:00:00 GMT',
'accept': '*/*',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'referer': 'https://train.jr-shikoku.co.jp/sp.html'
}
}).then(res=>res.json()).then(D=>{
let d =[];
D.forEach(element => {
console.log(element)
d.push(<ListItem title={"Direction:"+element.Direction+" Index:"+element.Index+" Line:"+element.Line+" Pos:"+element.Pos+" PosNum:"+element.PosNum+" TrainNum:"+element.TrainNum+" Type:"+element.Type+" Delay:"+element.delay}/>);
});
a=d;
return d;
});
}