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