11import * as HtmlElements from '@expo/html-elements' ;
22import Link from 'next/link' ;
3- import { PropsWithChildren , PropsWithRef , useContext , useRef } from 'react' ;
4- import { StyleSheet , TextStyle , View } from 'react-native' ;
5- import { useHover , useDimensions , useActive } from 'react-native-web-hooks' ;
3+ import { PropsWithChildren , useContext , useState } from 'react' ;
4+ import { StyleSheet , TextStyle , View , useWindowDimensions } from 'react-native' ;
65
76import CustomAppearanceContext from '../context/CustomAppearanceContext' ;
87
@@ -11,9 +10,7 @@ export const layout = {
1110} ;
1211
1312export const useLayout = ( ) => {
14- const {
15- window : { width } ,
16- } = useDimensions ( ) ;
13+ const { width } = useWindowDimensions ( ) ;
1714 return {
1815 isSmallScreen : width < 800 ,
1916 isBelowMaxWidth : width < layout . maxWidth ,
@@ -80,13 +77,11 @@ const textStyles = StyleSheet.create({
8077
8178type TextStyles = TextStyle | TextStyle [ ] ;
8279
83- type TextProps = PropsWithRef <
84- PropsWithChildren < {
85- style ?: TextStyles ;
86- id ?: string ;
87- numberOfLines ?: number ;
88- } >
89- > ;
80+ type TextProps = PropsWithChildren < {
81+ style ?: TextStyles ;
82+ id ?: string ;
83+ numberOfLines ?: number ;
84+ } > ;
9085
9186const createTextComponent = ( Element : any , textStyle ?: TextStyles ) => {
9287 const TextComponent = ( { children, style, id, numberOfLines } : TextProps ) => {
@@ -130,8 +125,7 @@ type AProps = PropsWithChildren<{
130125
131126export const A = ( { href, target = '_blank' , children, style, hoverStyle, ...rest } : AProps ) => {
132127 const { isDark } = useContext ( CustomAppearanceContext ) ;
133- const linkRef = useRef ( ) ;
134- const isHovered = useHover ( linkRef ) ;
128+ const [ isHovered , setIsHovered ] = useState ( false ) ;
135129
136130 const linkStyles = getLinkStyles ( isDark ) ;
137131 const linkHoverStyles = getLinkHoverStyles ( isDark ) ;
@@ -146,22 +140,22 @@ export const A = ({ href, target = '_blank', children, style, hoverStyle, ...res
146140 ...( isHovered && linkHoverStyles ) ,
147141 ...( style as any ) ,
148142 ...( isHovered && hoverStyle ) ,
149- } }
150- ref = { linkRef } >
143+ } } >
151144 { children }
152145 </ Link >
153146 ) ;
154147 }
155148
156149 return (
157- < HtmlElements . A
158- { ...rest }
159- href = { href }
160- target = { target }
161- style = { [ linkStyles , isHovered && linkHoverStyles , style , isHovered && hoverStyle ] }
162- ref = { linkRef } >
163- { children }
164- </ HtmlElements . A >
150+ < View onPointerEnter = { ( ) => setIsHovered ( true ) } onPointerLeave = { ( ) => setIsHovered ( false ) } >
151+ < HtmlElements . A
152+ { ...rest }
153+ href = { href }
154+ hrefAttrs = { { target } }
155+ style = { [ linkStyles , isHovered && linkHoverStyles , style , isHovered && hoverStyle ] } >
156+ { children }
157+ </ HtmlElements . A >
158+ </ View >
165159 ) ;
166160} ;
167161
@@ -180,14 +174,16 @@ const getLinkHoverStyles = (isDark: boolean) => ({
180174} ) ;
181175
182176export const HoverEffect = ( { children } ) => {
183- const ref = useRef ( ) ;
184- const isHovered = useHover ( ref ) ;
185- const isActive = useActive ( ref ) ;
177+ const [ isHovered , setIsHovered ] = useState ( false ) ;
178+ const [ isActive , setIsActive ] = useState ( false ) ;
186179
187180 return (
188181 < View
189- ref = { ref }
190182 style = { [ isHovered && { opacity : 0.8 } , isActive && { opacity : 0.5 } ] }
183+ onPointerEnter = { ( ) => setIsHovered ( true ) }
184+ onPointerLeave = { ( ) => setIsHovered ( false ) }
185+ onPointerDown = { ( ) => setIsActive ( true ) }
186+ onPointerUp = { ( ) => setIsActive ( false ) }
191187 accessible = { false } >
192188 { children }
193189 </ View >
0 commit comments