Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @react-native-community/art in favor of react-native-svg for Expo support #64

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modify drawing for SVG compatibility
chiubaka committed Jan 30, 2021
commit 439f3086230c136d156cc8e025163ffa1a1ebead
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ export default class Barcode extends PureComponent {
}

drawRect(x, y, width, height) {
return `M${x},${y}h${width}v${height}h-${width}z`;
return `M${x} ${y} h${width} v${height} h-${width} z`;
}

getTotalWidthOfEncodings(encodings) {
@@ -165,16 +165,32 @@ export default class Barcode extends PureComponent {
return encoded;
}

renderSvg() {
return (
<Svg height={this.props.height} width={this.state.barCodeWidth}>
{this.renderBars()}
</Svg>
);
}

renderBars() {
return this.state.bars.map(this.renderBar);
}

renderBar(bar) {
return (
<Path d={bar} stroke={this.props.lineColor} fill="none"/>
);
}

render() {
this.update();
const backgroundStyle = {
backgroundColor: this.props.background
};
return (
<View style={[styles.svgContainer, backgroundStyle]}>
<Svg height={this.props.height} width={this.state.barCodeWidth}>
<Path d={this.state.bars} fill={this.props.lineColor} />
</Svg>
{this.renderSvg()}
{ typeof (this.props.text) !== 'undefined' &&
<Text style={{color: this.props.textColor, width: this.state.barCodeWidth, textAlign: 'center'}} >{this.props.text}</Text>
}