forked from GingerBear/react-native-barcode-pdf417
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
69 lines (58 loc) · 1.49 KB
/
index.js
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
import React, { Component } from "react";
import { View, ActivityIndicator, StyleSheet } from "react-native";
import { Group, Shape, Surface } from "@react-native-community/art";
import createPDF417 from "./lib/pdf417-min";
export default class RNPDF417 extends Component {
state = {
isLoading: true
};
componentDidMount() {
requestAnimationFrame(() => {
this.setState({
isLoading: false
});
});
}
render() {
const { width, height, text } = this.props;
if (this.state.isLoading) {
return (
<View style={[S.loadingContainer, { width, height }]}>
<ActivityIndicator style={S.loadingIndicator} />
</View>
);
}
const PDF417 = createPDF417();
PDF417.init(text);
const barcode = PDF417.getBarcodeArray();
const w = width / barcode.num_cols;
const h = height / barcode.num_rows;
const shapes = [];
barcode.bcode.forEach((line, i) => {
line.forEach((code, j) => {
if (code === "1") {
shapes.push(
`M ${j * w} ${i * h} h ${w} v ${h} h -${w} L ${j * w} ${i * h}`
);
}
});
});
return (
<Surface width={width} height={height}>
<Group x={0} y={0}>
<Shape d={shapes} fill="#000000" />
</Group>
</Surface>
);
}
}
const S = StyleSheet.create({
loadingContainer: {
flexDirection: "row",
justifyContent: "center",
alignItems: "center"
},
loadingIndicator: {
marginRight: 10
}
});