aboutsummaryrefslogtreecommitdiffstats
path: root/src/screens/ProductScannerScreen.js
blob: 7cead47cc6f85317d81228796a7fc1609a7ca3c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { useState } from 'react';
import { View, Text, Button, StyleSheet, Alert } from 'react-native';
import BarcodeScanner from '../components/BarcodeScanner';

const ProductScannerScreen = ({ navigation }) => {
  const [scannedProduct, setScannedProduct] = useState(null);

  const handleScan = (product) => setScannedProduct(product);

  const handleAddToCart = () => {
    navigation.navigate('Cart');
  };

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Scan a Product</Text>
      
      <View style={styles.scannerContainer}>
        <BarcodeScanner onScan={handleScan} />
      </View>
      
      {scannedProduct && (
        <View style={styles.productDetails}>
          <Text style={styles.productName}>{scannedProduct.name}</Text>
          <Text style={styles.productPrice}>${scannedProduct.price}</Text>
          <Button title="Add to Cart" onPress={handleAddToCart} />
        </View>
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 16,
    backgroundColor: '#f8f8f8',
  },
  title: {
    fontSize: 24,
    fontWeight: 'bold',
    marginBottom: 20,
    textAlign: 'center',
    color: '#333',
  },
  scannerContainer: {
    flex: 1,
    width: '100%',
    justifyContent: 'center',
    alignItems: 'center',
    overflow: 'hidden',
    borderRadius: 10,
    backgroundColor: '#fff',
  },
  productDetails: {
    alignItems: 'center',
    padding: 20,
    backgroundColor: '#fff',
    borderRadius: 10,
    elevation: 2,
    marginTop: 20,
  },
  productName: {
    fontSize: 20,
    fontWeight: 'bold',
    color: '#333',
    marginBottom: 8,
  },
  productPrice: {
    fontSize: 18,
    color: '#888',
    marginBottom: 16,
  },
});

export default ProductScannerScreen;