11// @flow
2- import React , { Component } from 'react'
2+ import React , { useState } from 'react'
33import { StyleSheet , View , Text , TouchableOpacity } from 'react-native'
44
5- export type Props = {
6- initialCount : number ,
7- }
8-
9- type State = {
10- count : number ,
11- }
12-
13- export default class < %= pascal % > extends Component < Props , State > {
14- static defaultProps = {
15- initialCount : 0 ,
16- }
17-
18- state = {
19- count : this . props . initialCount ,
20- }
21-
22- handlePress = ( ) => {
23- this . setState ( {
24- count : this . state . count + 1 ,
25- } )
26- }
27-
28- renderThirdLayer ( percent : number ) {
5+ const ThirdLayer = ( { percent } ) => {
296 if ( percent > 50 ) {
307 return (
318 < View
@@ -36,29 +13,32 @@ export default class <%= pascal %> extends Component<Props, State> {
3613 }
3714
3815 return < View style = { styles . offsetLayer } />
39- }
16+ }
17+
18+ export type Props = {
19+ initialCount : number ,
20+ }
4021
41- render ( ) {
42- const { count } = this . state
43- let percent = count % 100
22+ export const < %= pascal % > = ( { initialCount = 0 } : Props ) => {
23+ const [ count , setCount ] = useState ( initialCount )
24+ const percent = count % 100
4425
4526 return (
4627 < View style = { styles . view } >
47- < TouchableOpacity onPress = { this . handlePress } >
28+ < TouchableOpacity onPress = { ( ) => setCount ( count + 1 ) } >
4829 < View style = { styles . container } >
4930 < View
5031 key = { percent }
5132 style = { [ styles . firstProgressLayer , rotation ( percent , - 135 ) ] }
5233 />
53- { this . renderThirdLayer ( percent ) }
34+ < ThirdLayer percent = { percent } />
5435 < View pointerEvents = "none" style = { styles . textOverlay } >
5536 < Text style = { styles . text } > { count } </ Text >
5637 </ View >
5738 </ View >
5839 </ TouchableOpacity >
5940 </ View >
6041 )
61- }
6242}
6343
6444const rotation = ( percent : number , base : number ) => ( {
0 commit comments