Import React
Wimer PaulinoPráctica o problema22 de Octubre de 2018
2.301 Palabras (10 Páginas)189 Visitas
import React, { Component } from 'react';
import { DetailScreen } from '../screenNames';
import { Text, StyleSheet, View, ListView, TextInput, ActivityIndicator, ToolbarAndroid } from 'react-native';
export default class PantallaPrincipal extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
text: '',
}
this.arrayholder = [];
}
renderItem = ({ rowData }) => {
const { navigation } = this.props;
let dataSendToDetail = {
id: JSON.stringify(rowData.id_producto),
pendiente: JSON.stringify(rowData.pendiente_despacho),
name: JSON.stringify(rowData.desc_producto),
cod: JSON.stringify(rowData.cod_barra),
precio: JSON.stringify(rowData.precio_base),
existencia: JSON.stringify(rowData.existencia),
disponible: JSON.stringify(rowData.disponible)
};
return (
<TouchableOpacity style={{ flex: 1, paddingLeft: 10, marginTop: 15 }}
onPress={() => {
navigation.navigate(DetailScreen, dataSendToDetail);
}}>
<Text style={{ fontSize: 16, marginBottom: 10 }}>
{rowData.cod_barra} {rowData.desc_producto}
Text>
TouchableOpacity>
)
}
componentDidMount() {
return fetch('http://137.117.70.87:9999/ords/transaccional/inventario/inventario')
.then((response) => response.json())
.then((responseJson) => {
let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(responseJson.items),
}, function () {
this.arrayholder = responseJson.items;
});
})
.catch((error) => {
console.error(error);
});
}
Buscador(text) {
const newData = this.arrayholder.filter(function (item) {
const itemData = item.desc_producto.toUpperCase()
const textData = text.toUpperCase()
return itemData.indexOf(textData) > -1
})
this.setState({
dataSource: this.state.dataSource.cloneWithRows(newData),
text: text
})
}
ListViewItemSeparator = () => {
return (
<View
style={{
height: .5,
width: "100%",
backgroundColor: "#000",
}}
/>
);
}
render() {
const { navigation } = this.props;
return (
this.state.isLoading
?
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size="large" color="#330066" animating />
View>
:
<View style={styles.container}>
<ToolbarAndroid
style={styles.toolbar}
title="Articulos"
onActionSelected={this.onActionSelected}
...