11import React , { useState } from 'react'
2- import { StyleSheet , View , Text , TouchableOpacity } from 'react-native'
2+ import { StyleSheet , View , Text , Pressable } from 'react-native'
33
44const rotation = ( percent : number , base : number ) => ( {
55 transform : [ { rotateZ : `${ base + ( percent > 50 ? 50 : percent ) * 3.6 } deg` } ] ,
@@ -20,14 +20,18 @@ const styles = StyleSheet.create({
2020 justifyContent : 'center' ,
2121 alignItems : 'center' ,
2222 } ,
23+ highlight : {
24+ borderColor : '#474747' ,
25+ } ,
2326 firstProgressLayer : {
2427 width : 200 ,
2528 height : 200 ,
2629 borderWidth : 20 ,
2730 borderRadius : 100 ,
2831 position : 'absolute' ,
29- borderLeftColor : 'transparent' ,
30- borderBottomColor : 'transparent' ,
32+ // Transparent borders not working on Android, use an almost transparent color.
33+ borderLeftColor : 'rgba(0, 0, 0, 0.01)' ,
34+ borderBottomColor : 'rgba(0, 0, 0, 0.01)' ,
3135 borderRightColor : 'gray' ,
3236 borderTopColor : 'gray' ,
3337 transform : [ { rotateZ : '-135deg' } ] ,
@@ -38,8 +42,8 @@ const styles = StyleSheet.create({
3842 position : 'absolute' ,
3943 borderWidth : 20 ,
4044 borderRadius : 100 ,
41- borderLeftColor : 'transparent ' ,
42- borderBottomColor : 'transparent ' ,
45+ borderLeftColor : 'rgba(0, 0, 0, 0.01) ' ,
46+ borderBottomColor : 'rgba(0, 0, 0, 0.01) ' ,
4347 borderRightColor : 'gray' ,
4448 borderTopColor : 'gray' ,
4549 transform : [ { rotateZ : '45deg' } ] ,
@@ -50,12 +54,16 @@ const styles = StyleSheet.create({
5054 position : 'absolute' ,
5155 borderWidth : 20 ,
5256 borderRadius : 100 ,
53- borderLeftColor : 'transparent ' ,
54- borderBottomColor : 'transparent ' ,
57+ borderLeftColor : 'rgba(0, 0, 0, 0.01) ' ,
58+ borderBottomColor : 'rgba(0, 0, 0, 0.01) ' ,
5559 borderRightColor : 'black' ,
5660 borderTopColor : 'black' ,
5761 transform : [ { rotateZ : '-135deg' } ] ,
5862 } ,
63+ highlightOffset : {
64+ borderRightColor : '#474747' ,
65+ borderTopColor : '#474747' ,
66+ } ,
5967 textOverlay : {
6068 position : 'absolute' ,
6169 alignItems : 'center' ,
@@ -64,9 +72,12 @@ const styles = StyleSheet.create({
6472 text : {
6573 fontSize : 40 ,
6674 } ,
75+ textBold : {
76+ fontWeight : 'bold' ,
77+ } ,
6778} )
6879
69- const ThirdLayer = ( { percent } : { percent : number } ) => {
80+ const ThirdLayer = ( { percent, pressed } : { percent : number ; pressed : boolean } ) => {
7081 if ( percent > 50 ) {
7182 return (
7283 < View
@@ -76,7 +87,7 @@ const ThirdLayer = ({ percent }: { percent: number }) => {
7687 )
7788 }
7889
79- return < View style = { styles . offsetLayer } />
90+ return < View style = { [ styles . offsetLayer , pressed && styles . highlightOffset ] } />
8091}
8192
8293export type Props = {
@@ -89,15 +100,17 @@ export const <%= pascal %> = ({ initialCount = 0 }: Props) => {
89100
90101 return (
91102 < View style = { styles . view } >
92- < TouchableOpacity onPress = { ( ) => setCount ( count + 1 ) } >
93- < View style = { styles . container } >
94- < View key = { percent } style = { [ styles . firstProgressLayer , rotation ( percent , - 135 ) ] } />
95- < ThirdLayer percent = { percent } />
96- < View pointerEvents = "none" style = { styles . textOverlay } >
97- < Text style = { styles . text } > { count } </ Text >
103+ < Pressable onPress = { ( ) => setCount ( count + 1 ) } >
104+ { ( { pressed } ) => (
105+ < View style = { [ styles . container , pressed && styles . highlight ] } >
106+ < View key = { percent } style = { [ styles . firstProgressLayer , rotation ( percent , - 135 ) ] } />
107+ < ThirdLayer percent = { percent } pressed = { pressed } />
108+ < View pointerEvents = "none" style = { styles . textOverlay } >
109+ < Text style = { [ styles . text , pressed && styles . textBold ] } > { count } </ Text >
110+ </ View >
98111 </ View >
99- </ View >
100- </ TouchableOpacity >
112+ ) }
113+ </ Pressable >
101114 </ View >
102115 )
103116}
0 commit comments