@@ -4,12 +4,13 @@ import Link from 'next/link';
44import { type ComponentType , type CSSProperties , type PropsWithChildren , useState } from 'react' ;
55import {
66 StyleSheet ,
7- type TextStyle ,
8- View ,
7+ Pressable ,
98 useWindowDimensions ,
109 type StyleProp ,
1110 type ViewStyle ,
11+ type PressableProps ,
1212} from 'react-native' ;
13+ import { type Style } from 'twrnc' ;
1314
1415import tw from '~/util/tailwind' ;
1516
@@ -42,7 +43,7 @@ type CustomTextProps = TextProps &
4243
4344export function createTextComponent (
4445 Element : ComponentType < TextProps > ,
45- textStyle ?: StyleProp < TextStyle >
46+ textStyle ?: StyleProp < Style >
4647) {
4748 function TextComponent ( { children, style, id, numberOfLines } : CustomTextProps ) {
4849 const elementStyle = Element ?. displayName
@@ -55,7 +56,7 @@ export function createTextComponent(
5556 numberOfLines = { numberOfLines }
5657 style = { [
5758 tw `font-sans font-normal my-0 text-black dark:text-white` ,
58- elementStyle as StyleProp < TextStyle > ,
59+ elementStyle as StyleProp < Style > ,
5960 textStyle ,
6061 style ,
6162 ] } >
@@ -81,10 +82,10 @@ export const Caption = createTextComponent(HtmlElements.P, textStyles.caption);
8182export const Label = createTextComponent ( HtmlElements . P , textStyles . label ) ;
8283
8384type AProps = PropsWithChildren < {
84- style ?: StyleProp < TextStyle > ;
85+ style ?: StyleProp < Style > ;
8586 target ?: string ;
8687 href : string ;
87- hoverStyle ?: StyleProp < TextStyle > ;
88+ hoverStyle ?: StyleProp < Style > ;
8889 containerStyle ?: CSSProperties ;
8990} > ;
9091
@@ -98,6 +99,7 @@ export function A({ href, target, children, style, hoverStyle, containerStyle, .
9899 const passedStyle = StyleSheet . flatten ( style ) ;
99100 return (
100101 < Link
102+ { ...rest }
101103 href = { href }
102104 onPointerEnter = { ( ) => setIsHovered ( true ) }
103105 onPointerLeave = { ( ) => setIsHovered ( false ) }
@@ -130,26 +132,23 @@ export function A({ href, target, children, style, hoverStyle, containerStyle, .
130132 ) ;
131133}
132134
133- type HoverEffectProps = PropsWithChildren < { style ?: StyleProp < ViewStyle > } > ;
134-
135- export function HoverEffect ( { children, style } : HoverEffectProps ) {
136- const [ isHovered , setIsHovered ] = useState ( false ) ;
137- const [ isActive , setIsActive ] = useState ( false ) ;
135+ type HoverEffectProps = PressableProps & { style ?: StyleProp < ViewStyle > } ;
138136
137+ export function HoverEffect ( { children, style, onPress, ...rest } : HoverEffectProps ) {
139138 return (
140- < View
141- style = { [
139+ < Pressable
140+ style = { ( { hovered , pressed } ) => [
142141 { transition : 'opacity 0.33s' } ,
143- isHovered && tw `opacity-75` ,
144- isActive && tw `opacity-50` ,
142+ hovered && tw `opacity-75` ,
143+ pressed && tw `opacity-50` ,
145144 style ,
146145 ] }
147- onPointerEnter = { ( ) => setIsHovered ( true ) }
148- onPointerLeave = { ( ) => setIsHovered ( false ) }
149- onPointerDown = { ( ) => setIsActive ( true ) }
150- onPointerUp = { ( ) => setIsActive ( false ) }
151- accessible = { false } >
146+ accessible = { false }
147+ focusable = { false }
148+ tabIndex = { onPress ? 0 : - 1 }
149+ onPress = { onPress }
150+ { ... rest } >
152151 { children }
153- </ View >
152+ </ Pressable >
154153 ) ;
155154}
0 commit comments