JSFiddle - React, Tailwind, and code Playground
JavaScript
import React, { Component } from 'react'
import { Text, View, StyleSheet, FlatList } from 'react-native'
import { Table, TableWrapper, Row, Rows, Col, Cols, Cell } from 'react-native-table-component';
const ws = new WebSocket('ws://177.876.972.243:83023', 'binary')
function stringFromUTF8Array (data) {
data = new Uint8Array(data)
const extraByteMap = [ 1, 1, 1, 1, 2, 2, 3, 0 ]
var count = data.length
var str = ''
for (var index = 0; index < count;) {
var ch = data[ index++ ]
if (ch & 0x80) {
var extra = extraByteMap[ (ch >> 3) & 0x07 ]
if (!(ch & 0x40) || !extra || ((index + extra) > count))
return null
ch = ch & (0x3F >> extra)
for (; extra > 0; extra -= 1) {
var chx = data[ index++ ]
if ((chx & 0xC0) != 0x80)
return null
ch = (ch << 6) | (chx & 0x3F)
}
}
str += String.fromCharCode(ch)
}
return str
}
export default class App extends Component {
constructor (props) {
super(props)
this.state = {
lastReceivedData: [],
connectionOpened: false,
}
this.initWS = this.initWS.bind(this)
}
componentDidMount () {
this.initWS()
}
render () {
return (
<View style={styles.root}>
<FlatList
data={this.state.lastReceivedData}
renderItem={this.renderItem}
ListHeaderComponent={this.renderHeader}
keyExtractor={(item, index) => index}
/>
</View>
)
}
renderHeader () {
const tableHead = ['Date', 'Address', 'IP', 'Описание', 'ID', 'PORT', 'state'];
return (
<Table>
<Row data={tableHead} style={styles.head} textStyle={styles.text} flexArr={[2, 3, 2, 3, 1, 1, 2]}/>
</Table>
)
}
renderItem ({ item }) {
const tableData = [String(item).split(';')]
return (
<Table borderStyle={{borderWidth: 0.5, borderColor: '#c8e1ff'}}>
<Rows data={tableData} style={styles.row} textStyle={styles.text}...