@@ -5,25 +5,34 @@ import { EaseView } from 'react-native-ease';
55import { Section } from '../components/Section' ;
66import { Button } from '../components/Button' ;
77
8+ const states = [
9+ { borderWidth : 0 , borderColor : '#4a90d9' , label : 'None' } ,
10+ { borderWidth : 4 , borderColor : '#e74c3c' , label : 'Red' } ,
11+ { borderWidth : 4 , borderColor : '#4ade80' , label : 'Green' } ,
12+ ] as const ;
13+
14+ const nextLabel = [ 'Add Red' , 'Go Green' , 'Remove' ] as const ;
15+
816export function BorderDemo ( ) {
9- const [ active , setActive ] = useState ( false ) ;
17+ const [ index , setIndex ] = useState ( 0 ) ;
18+ const state = states [ index ] ! ;
1019 return (
1120 < Section title = "Border" >
1221 < EaseView
1322 animate = { {
14- borderWidth : active ? 4 : 0 ,
15- borderColor : active ? '#e74c3c' : '#4a90d9' ,
23+ borderWidth : state . borderWidth ,
24+ borderColor : state . borderColor ,
1625 } }
1726 transition = { {
1827 border : { type : 'spring' , damping : 15 , stiffness : 120 } ,
1928 } }
2029 style = { styles . box }
2130 >
22- < Text style = { styles . text } > { active ? 'Red' : 'None' } </ Text >
31+ < Text style = { styles . text } > { state . label } </ Text >
2332 </ EaseView >
2433 < Button
25- label = { active ? 'Remove' : 'Add Border' }
26- onPress = { ( ) => setActive ( ( v ) => ! v ) }
34+ label = { nextLabel [ index ] ! }
35+ onPress = { ( ) => setIndex ( ( i ) => ( i + 1 ) % states . length ) }
2736 />
2837 </ Section >
2938 ) ;
0 commit comments