React Native-如何用粗体共享消息



我正在使用react原生Share API,我想用粗体字共享消息我似乎找不到做这件事的方法有人知道怎么做吗?

我还没有发现任何关于共享粗体文本的信息,但您可以在这里使用Unicode字符中已经分配的粗体字符:

https://unicode.org/charts/nameslist/n_1D400.html

我使用以下方法制作了将字符转换为粗体的函数:

const toBold = text =>{
const charSet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '?', '.', ',', '"', "'"];
const targetCharSet = ['𝐚', '𝐛', '𝐜', '𝐝', '𝐞', '𝐟', '𝐠', '𝐡', '𝐢', '𝐣', '𝐤', '𝐥', '𝐦', '𝐧', '𝐨', '𝐩', '𝐪', '𝐫', '𝐬', '𝐭', '𝐮', '𝐯', '𝐰', '𝐱', '𝐲', '𝐳', '𝐀', '𝐁', '𝐂', '𝐃', '𝐄', '𝐅', '𝐆', '𝐇', '𝐈', '𝐉', '𝐊', '𝐋', '𝐌', '𝐍', '𝐎', '𝐏', '𝐐', '𝐑', '𝐒', '𝐓', '𝐔', '𝐕', '𝐖', '𝐗', '𝐘', '𝐙', '𝟎', '𝟏', '𝟐', '𝟑', '𝟒', '𝟓', '𝟔', '𝟕', '𝟖', '𝟗', '❗', '❓', '.', ',', '"', "'"];
const textArray = text.split('');
let boldText = '';
textArray.forEach((letter) => {
const index = charSet.findIndex((_letter) => _letter === letter);
if (index !== -1) {
boldText = boldText + targetCharSet[index];
} else {
boldText = boldText + letter;
}
});
return boldText;
}

用法:

toBold('Hi Mom');

输出:

𝐇𝐢 𝐌𝐨𝐦

注意:文本可能不会显示在控制台中。

最新更新