11import * as HtmlElements from '@expo/html-elements' ;
22import { TextProps } from '@expo/html-elements/build/primitives/Text' ;
33import Link from 'next/link' ;
4- import { ComponentType , PropsWithChildren , useContext , useState } from 'react' ;
5- import { StyleSheet , TextStyle , View , useWindowDimensions , ViewStyle } from 'react-native' ;
4+ import { type ComponentType , type PropsWithChildren , useContext , useState } from 'react' ;
5+ import {
6+ StyleSheet ,
7+ TextStyle ,
8+ View ,
9+ useWindowDimensions ,
10+ ViewStyle ,
11+ StyleProp ,
12+ } from 'react-native' ;
613
714import CustomAppearanceContext from '../context/CustomAppearanceContext' ;
815
@@ -87,16 +94,16 @@ type CustomTextProps = TextProps &
8794const createTextComponent = ( Element : ComponentType < TextProps > , textStyle ?: TextStyles ) => {
8895 const TextComponent = ( { children, style, id, numberOfLines } : CustomTextProps ) => {
8996 const { isDark } = useContext ( CustomAppearanceContext ) ;
97+
98+ const elementStyle = Element ?. displayName
99+ ? StyleSheet . flatten ( textStyles [ Element . displayName as keyof typeof textStyles ] )
100+ : undefined ;
101+
90102 return (
91103 < Element
92104 id = { id }
93105 numberOfLines = { numberOfLines }
94- style = { [
95- textStyles [ Element . displayName ] ,
96- textStyle ,
97- { color : isDark ? colors . white : colors . black } ,
98- style ,
99- ] } >
106+ style = { [ elementStyle , textStyle , { color : isDark ? colors . white : colors . black } , style ] } >
100107 { children }
101108 </ Element >
102109 ) ;
@@ -118,30 +125,22 @@ export const Caption = createTextComponent(HtmlElements.P, textStyles.caption);
118125export const Label = createTextComponent ( HtmlElements . P , textStyles . label ) ;
119126
120127type AProps = PropsWithChildren < {
121- style ?: TextStyles ;
128+ style ?: StyleProp < TextStyle > ;
122129 target ?: string ;
123130 href : string ;
124- hoverStyle ?: TextStyles ;
125- containerStyle ?: ViewStyle ;
131+ hoverStyle ?: StyleProp < TextStyle > ;
132+ containerStyle ?: StyleProp < ViewStyle > ;
126133} > ;
127134
128- export const A = ( {
129- href,
130- target,
131- children,
132- style,
133- hoverStyle,
134- containerStyle,
135- ...rest
136- } : AProps ) => {
135+ export function A ( { href, target, children, style, hoverStyle, containerStyle, ...rest } : AProps ) {
137136 const { isDark } = useContext ( CustomAppearanceContext ) ;
138137 const [ isHovered , setIsHovered ] = useState ( false ) ;
139138
140139 const linkStyles = getLinkStyles ( isDark ) ;
141140 const linkHoverStyles = getLinkHoverStyles ( ) ;
142141
143142 if ( ( target === '_self' && ! href . startsWith ( '#' ) ) || href . startsWith ( '/' ) ) {
144- const passedStyle = Array . isArray ( style ) ? StyleSheet . flatten ( style ) : style ;
143+ const passedStyle = StyleSheet . flatten ( style ) ;
145144 return (
146145 < Link
147146 href = { href }
@@ -151,7 +150,7 @@ export const A = ({
151150 ...linkStyles ,
152151 ...( passedStyle as any ) ,
153152 ...( isHovered && linkHoverStyles ) ,
154- ...( isHovered && hoverStyle ) ,
153+ ...( isHovered && hoverStyle && StyleSheet . flatten ( hoverStyle ) ) ,
155154 } } >
156155 { children }
157156 </ Link >
@@ -174,18 +173,22 @@ export const A = ({
174173 </ HtmlElements . A >
175174 </ View >
176175 ) ;
177- } ;
176+ }
178177
179- const getLinkStyles = ( isDark : boolean ) => ( {
180- color : isDark ? colors . white : colors . black ,
181- textDecorationColor : isDark ? colors . gray5 : colors . pewter ,
182- textDecorationLine : 'underline' ,
183- fontFamily : 'inherit' ,
184- } ) ;
178+ function getLinkStyles ( isDark : boolean ) : TextStyle {
179+ return {
180+ color : isDark ? colors . white : colors . black ,
181+ textDecorationColor : isDark ? colors . gray5 : colors . pewter ,
182+ textDecorationLine : 'underline' ,
183+ fontFamily : 'inherit' ,
184+ } ;
185+ }
185186
186- const getLinkHoverStyles = ( ) => ( {
187- textDecorationColor : colors . primaryDark ,
188- } ) ;
187+ function getLinkHoverStyles ( ) : TextStyle {
188+ return {
189+ textDecorationColor : colors . primaryDark ,
190+ } ;
191+ }
189192
190193export function HoverEffect ( { children } : PropsWithChildren ) {
191194 const [ isHovered , setIsHovered ] = useState ( false ) ;
0 commit comments