From e4b24499a9ce21ec09431814754d812ab856eea6 Mon Sep 17 00:00:00 2001 From: wangmaolin Date: Tue, 30 Jan 2024 10:06:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Issues:=20#I8YWCY]=20=E6=B7=BB=E5=8A=A0rea?= =?UTF-8?q?ct-native-base64=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1224/react-native-base64.md | 132 ++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 1224/react-native-base64.md diff --git a/1224/react-native-base64.md b/1224/react-native-base64.md new file mode 100644 index 00000000..257d40ed --- /dev/null +++ b/1224/react-native-base64.md @@ -0,0 +1,132 @@ +> 模板版本:v0.1.2 + +

+

react-native-base64

+

+

+ + License + +

+ +> [!tip] [Github 地址](https://github.com/eranbo/react-native-base64) + +## 安装与使用 + +进入到工程目录并输入以下命令: + + + +#### **npm** + +```bash +npm i react-native-base64@0.2.1 + +// typescript 项目需下载对应包的类型声明 +npm i @types/react-native-base64 -D +``` + + +下面的代码展示了这个库的基本使用场景: + +```js +import React, { useState } from 'react'; +import base64 from 'react-native-base64'; +import { + ScrollView, + StyleSheet, + Text, + TextInput, + useColorScheme, + View, +} from 'react-native'; + +import { + Colors, +} from 'react-native/Libraries/NewAppScreen'; + +export function Base64Page(): JSX.Element { + const isDarkMode = useColorScheme() === 'dark'; + + // 输入文字 + const [word, setWord] = useState('react native'); + // 编码输入文字 + const encodeWord = base64.encode(word); + // 解码输入文字 + const decodeWord = base64.decode(encodeWord); + // 解码结果 是否 和原文字相同 + const wordEqualDecodeWord = `word equal decode word: ${word === decodeWord}` + // 将word 转为 unit8 array + const byteArrayWord = Uint8Array.from(word.split(''), w => w.charCodeAt(0)); + // 对 unit 8 array 进行编码 + const encodeWordFromByteArray = base64.encodeFromByteArray(byteArrayWord); + // 对 上一步结果进行解码 + const decodeFromByteArray = base64.decode(encodeWordFromByteArray); + + const backgroundStyle = { + backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, + }; + + return ( + <> + + + + Test Word: + + encode Result: {encodeWord} + decode Result: {decodeWord} + encodeFromByteArray Result: {encodeWordFromByteArray} + decode the value above Result: {decodeFromByteArray} + + + + + ); + +} + +const styles = StyleSheet.create({ + cardView: { margin: 10, backgroundColor: '#f0f0f0', display: 'flex', padding: 10, borderRadius: 8 }, + TextInput: {height: 40, borderColor: '#ccc', borderWidth: 1, borderRadius: 4, width: '90%'}, + highlight: { + fontWeight: '700', + }, +}); + +``` + +## 兼容性 + +在以下版本验证通过: + + IDE: 4.1.3.500 + SDK: HarmonyOS NEXT Devloper Preview1 + 测试设备: Mate60 (BRA-AL00 ) + Rom: 204.1.0.59(SP2DEVC00E60R4P1) + RNOH: 0.72.13 + + +### base64 提供的方法: + +| 名称 | 说明 | 参数类型 | 是否必填 | 原库平台 | 鸿蒙支持 | +| ---- | ---- | ---- | -------- | -------- | -------- | +| encode| 对字符串编码 |string| No | / | Yes | +| decode | 对base64编码串解码 | string | No | / | Yes | +| encodeFromByteArray | 对二进制数据(unit8 Array) 编码 | Unit8Array | No | / | Yes | + + +## 遗留问题 + +## 其他 + +## 开源协议 + +本项目基于 [MIT License](https://github.com/eranbo/react-native-base64/blob/master/LICENSE) ,请自由地享受和参与开源。 -- Gitee From b7d9ab2ba933ee27fb40293f3d5edcf282927e54 Mon Sep 17 00:00:00 2001 From: wangmaolin Date: Tue, 30 Jan 2024 10:52:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Issues:=20#I8YWCY]=20=E4=BF=AE=E6=94=B9rea?= =?UTF-8?q?ct-native-base64=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1224/react-native-base64.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/1224/react-native-base64.md b/1224/react-native-base64.md index 257d40ed..b5b68595 100644 --- a/1224/react-native-base64.md +++ b/1224/react-native-base64.md @@ -107,20 +107,21 @@ const styles = StyleSheet.create({ 在以下版本验证通过: - IDE: 4.1.3.500 - SDK: HarmonyOS NEXT Devloper Preview1 - 测试设备: Mate60 (BRA-AL00 ) - Rom: 204.1.0.59(SP2DEVC00E60R4P1) + 1. SDK: HarmonyOS NEXT Devloper Preview1; + 测试设备: Mate60 (BRA-AL00); + Rom: 204.1.0.59(SP2DEVC00E60R4P1); + IDE: 4.1.3.500; RNOH: 0.72.13 ### base64 提供的方法: -| 名称 | 说明 | 参数类型 | 是否必填 | 原库平台 | 鸿蒙支持 | -| ---- | ---- | ---- | -------- | -------- | -------- | -| encode| 对字符串编码 |string| No | / | Yes | -| decode | 对base64编码串解码 | string | No | / | Yes | -| encodeFromByteArray | 对二进制数据(unit8 Array) 编码 | Unit8Array | No | / | Yes | + +| Name | Description | Type | Required | HarmonyOS Support | +| ---- | ---- | ---- | -------- | -------- | +| encode| encode from string |string| No | Yes | +| decode | decode base64 strings | string | No | Yes | +| encodeFromByteArray | encode from Unit8Array | Unit8Array | No | Yes | ## 遗留问题 -- Gitee