模板版本:v0.4.0

react-native-barcode-builder

本项目基于 react-native-barcode-builder 开发。

该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:@react-native-ohos/react-native-barcode-builder 版本所属关系如下:

三方库名称 三方库版本 发布信息 支持RN版本 Autolink 编译API版本 社区基线版本 npm地址
@react-native-ohos/react-native-barcode-builder ~2.1.0 Gitcode Releases 0.77.* / 0.82.* API12+ 2.0.0 Npm Address
@react-native-oh-tpl/react-native-barcode-builder ~2.0.0-0.0.1 Github Releases 0.72.* API12+ 2.0.0 Npm Address

1. 安装与使用

进入到工程目录并输入以下命令:

npm

# 0.72
npm install @react-native-oh-tpl/react-native-barcode-builder

# 0.77/0.82
npm install @react-native-ohos/react-native-barcode-builder

yarn

# 0.72
yarn add @react-native-oh-tpl/react-native-barcode-builder

# 0.77/0.82
yarn add @react-native-ohos/react-native-barcode-builder

下面的代码展示了这个库的基本使用场景:

使用时 import 的库名不变。

import React, { useEffect } from "react";
import { StyleSheet, View, Text } from "react-native";
import Barcode from "react-native-barcode-builder";
export const BarcodeBuilderExample = () => {
  const error = (e) => {
    console.log(e, "click");
  };
  return (
    <View
      style={{
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
        backgroundColor: "#F5FCFF",
      }}
    >
      <Text style={{ fontSize: 50 }}>This is a Barcode Builder</Text>
      <Barcode
        value=" hello~~~"
        format="CODE128"
        text="hello world"
        onError={error}
        width={5}
        height={200}
      />
    </View>
  );
};

2. 约束与限制

本库鸿蒙侧实现依赖 react-native-svg 的原生端代码,如已在鸿蒙工程中引入过该库,则无需再次引入,如未引入请参照react-native-svg 文档进行引入。

2.1. 兼容性

本文档内容基于以下版本验证通过:

  1. RNOH:0.72.86;SDK:HarmonyOS 6.0.0.47 (API Version 20);IDE:DevEco Studio 6.0.0.858;ROM:6.0.0.107;
  2. RNOH:0.77.18;SDK:HarmonyOS 6.0.0.47 (API Version 20);IDE:DevEco Studio 6.0.0.858;ROM:6.0.0.107;
  3. RNOH:0.82.7;SDK:HarmonyOS 6.0.1 Release SDK;IDE:DevEco Studio 6.0.1 Release;ROM:6.0.0.328 SP26;

3. 属性

Barcode

"Platform"列表示该属性在原三方库上支持的平台。

"HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

该库为 UI 组件库,通过配置属性标签,实现对应的功能。

Name Type Description Required Platform HarmonyOS Support
value string 条形码所代表的值。 yes iOS/Android yes
format string 使用哪种条形码类型。了解更多 no iOS/Android yes
width number 单个条的宽度。 no iOS/Android yes
height number 条形码的高度。 no iOS/Android yes
text string 覆盖显示的文本。 no iOS/Android yes
lineColor string 条纹的颜色。 no iOS/Android yes
textColor string 文本的颜色。 no iOS/Android yes
background string 条形码的背景颜色。 no iOS/Android yes
onError function 当所选格式的条形码无效时的回调函数。 no iOS/Android yes

4. 开源协议

本项目基于 The Apache License (Apache) ,请自由地享受和参与开源。