11import React from 'react' ;
2- import { Linking , Pressable , StyleSheet , Text } from 'react-native' ;
2+ import { Linking , Pressable , Text , useColorScheme } from 'react-native' ;
33
44type HyperlinkProps = {
55 url : string ;
66 text ?: string ;
77} ;
88function Hyperlink ( { url, text} : HyperlinkProps ) : JSX . Element {
9- const styles = StyleSheet . create ( {
10- hyperlinkIdle : {
11- color : 'blue' ,
12- textDecorationLine : 'underline' ,
13- } ,
14- hyperlinkHovering : {
15- color : 'darkblue' ,
16- textDecorationLine : 'underline' ,
17- } ,
18- hyperlinkPressing : {
19- color : 'black' ,
20- textDecorationLine : 'underline' ,
21- } ,
22- } ) ;
239 const [ hovering , setHovering ] = React . useState ( false ) ;
2410 const [ pressing , setPressing ] = React . useState ( false ) ;
11+ const colorScheme = useColorScheme ( ) ;
12+ const isDark = colorScheme === 'dark' ;
2513
14+ const colors = {
15+ idle : isDark ? '#6CB6FF' : '#0066CC' ,
16+ hover : isDark ? '#8ECAFF' : '#004499' ,
17+ press : isDark ? '#A8D8FF' : '#003366' ,
18+ } ;
19+
20+ const linkColor = pressing ? colors . press : hovering ? colors . hover : colors . idle ;
2621 let displayText = text ?? url ;
2722
2823 return (
@@ -36,14 +31,7 @@ function Hyperlink({url, text}: HyperlinkProps): JSX.Element {
3631 onPressOut = { ( ) => setPressing ( false ) }
3732 onHoverIn = { ( ) => setHovering ( true ) }
3833 onHoverOut = { ( ) => setHovering ( false ) } >
39- < Text
40- style = {
41- pressing
42- ? styles . hyperlinkPressing
43- : hovering
44- ? styles . hyperlinkHovering
45- : styles . hyperlinkIdle
46- } >
34+ < Text style = { { color : linkColor , textDecorationLine : 'underline' } } >
4735 { displayText }
4836 </ Text >
4937 </ Pressable >
0 commit comments