-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextWithBorder.tsx
113 lines (107 loc) · 2.86 KB
/
TextWithBorder.tsx
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { Canvas, Text as SkiaText, useFont } from "@shopify/react-native-skia";
import React from "react";
import type { TextStyle } from "react-native";
import { View, Text } from "react-native";
export interface TextWithBorderProps {
text: string;
color: string;
fontSize: number;
frontWidth?: undefined | number;
backWidth?: undefined | number;
showForeground?: undefined | boolean;
showFront?: undefined | boolean;
showBack?: undefined | boolean;
frontColor?: undefined | string;
backColor?: undefined | string;
textStyle?: undefined | TextStyle;
fontFamily?: string;
}
export const TextWithBorderSkia = function TextWithBorderSkia({
backColor = "black",
backWidth = 1.5,
color,
fontFamily = "Boogaloo",
fontSize,
frontColor = "white",
frontWidth = 1,
showBack = true,
showForeground = true,
showFront = true,
text,
textStyle = {},
}: TextWithBorderProps) {
const font_req =
fontFamily == "Boogaloo"
? require(`./assets/Boogaloo.ttf`)
: require(`./assets/Comicy.ttf`);
const font = useFont(font_req, fontSize);
const strokeWidth = frontWidth * 2;
//https://github.com/Shopify/react-native-skia/discussions/924
const textWidth = font?.getTextWidth(text) ?? 0; //argh this measurement is inaccurate. shitty.
// const textWidth = useComputedValue(() => {
// return font?.getTextWidth(text)
// }, [font, text, fontSize]) ?? 0
return (
<View
style={{
height: fontSize + strokeWidth * 2,
width: textWidth + strokeWidth * 2,
alignItems: "center",
}}
pointerEvents={"none"}
>
{font ? (
<Canvas
style={{
position: "absolute",
left: -strokeWidth,
right: -strokeWidth - 500,
top: -strokeWidth,
bottom: -strokeWidth,
}}
//
>
{/* <Group
//
// transform={[{ translateX: "5" }]}
> */}
<SkiaText
text={text}
font={font}
x={strokeWidth}
// y={fontSize*0.9}
y={fontSize + strokeWidth}
strokeWidth={strokeWidth}
color={frontColor}
style="stroke"
/>
<SkiaText
text={text}
font={font}
x={strokeWidth}
y={fontSize + strokeWidth}
color={color}
/>
{/* </Group> */}
</Canvas>
) : (
<Text
style={{
//
color,
fontSize,
fontFamily,
alignSelf: "center",
position: "absolute",
textShadowColor: "black",
textShadowOffset: { width: 0, height: 0 },
textShadowRadius: 3,
}}
numberOfLines={1}
>
{text}
</Text>
)}
</View>
);
};