The best way to control Claude Code, Codex and more from any computer or phone

main
ts 78 lines 2.21 KB
Raw
1 import { I18nManager, type StyleProp, StyleSheet, type TextStyle } from "react-native";
2 import type { NativeFontWeight } from "./T3SourceTextRunNativeComponent";
3
4 export function flattenStyles(rootStyle: TextStyle, style: StyleProp<TextStyle>) {
5 const flattenedStyle = StyleSheet.flatten([rootStyle, style]) as TextStyle;
6 const textDecorationLine = flattenedStyle.textDecorationLine;
7 return {
8 ...flattenedStyle,
9 textAlign:
10 flattenedStyle.textAlign === "start"
11 ? I18nManager.isRTL
12 ? ("right" as const)
13 : ("left" as const)
14 : flattenedStyle.textAlign === "end"
15 ? I18nManager.isRTL
16 ? ("left" as const)
17 : ("right" as const)
18 : flattenedStyle.textAlign,
19 textDecorationStyle:
20 flattenedStyle.textDecorationStyle === "wavy" ? "solid" : flattenedStyle.textDecorationStyle,
21 textDecorationLine:
22 textDecorationLine === "underline" || textDecorationLine === "line-through"
23 ? textDecorationLine
24 : ("none" as const),
25 fontWeight: fontWeightToNativeProp(flattenedStyle.fontWeight ?? "normal"),
26 backgroundColor: flattenedStyle.backgroundColor
27 ? flattenedStyle.backgroundColor
28 : "transparent",
29 shadowOffset: flattenedStyle.shadowOffset
30 ? flattenedStyle.shadowOffset
31 : { width: 0, height: 0 },
32 };
33 }
34
35 // Codegen cannot use integer enums; convert font weights to native props.
36 function fontWeightToNativeProp(fontWeight: TextStyle["fontWeight"]): NativeFontWeight {
37 switch (fontWeight) {
38 case "normal":
39 return "normal";
40 case "bold":
41 return "bold";
42 case 100:
43 case "100":
44 case "ultralight":
45 return "ultraLight";
46 case 200:
47 case "200":
48 return "ultraLight";
49 case 300:
50 case "300":
51 case "light":
52 return "light";
53 case 400:
54 case "400":
55 case "regular":
56 return "normal";
57 case 500:
58 case "500":
59 case "medium":
60 return "medium";
61 case 600:
62 case "600":
63 case "semibold":
64 return "semibold";
65 case 700:
66 case "700":
67 return "bold";
68 case 800:
69 case "800":
70 return "bold";
71 case 900:
72 case "900":
73 case "heavy":
74 return "heavy";
75 default:
76 return "normal";
77 }
78 }