mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Text as RNText, TextProps} from 'react-native'
3import {s, lh} from 'lib/styles'
4import {useTheme, TypographyVariant} from 'lib/ThemeContext'
5import {isIOS, isWeb} from 'platform/detection'
6import {UITextView} from 'react-native-ui-text-view'
7
8export type CustomTextProps = TextProps & {
9 type?: TypographyVariant
10 lineHeight?: number
11 title?: string
12 dataSet?: Record<string, string | number>
13 selectable?: boolean
14}
15
16const fontFamilyStyle = {
17 fontFamily:
18 '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Liberation Sans", Helvetica, Arial, sans-serif',
19}
20
21export function Text({
22 type = 'md',
23 children,
24 lineHeight,
25 style,
26 title,
27 dataSet,
28 selectable,
29 ...props
30}: React.PropsWithChildren<CustomTextProps>) {
31 const theme = useTheme()
32 const typography = theme.typography[type]
33 const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined
34
35 if (selectable && isIOS) {
36 return (
37 <UITextView
38 style={[s.black, typography, lineHeightStyle, style]}
39 {...props}>
40 {children}
41 </UITextView>
42 )
43 }
44
45 return (
46 <RNText
47 style={[
48 s.black,
49 typography,
50 isWeb && fontFamilyStyle,
51 lineHeightStyle,
52 style,
53 ]}
54 // @ts-ignore web only -esb
55 dataSet={Object.assign({tooltip: title}, dataSet || {})}
56 selectable={selectable}
57 {...props}>
58 {children}
59 </RNText>
60 )
61}