1
1
import React , { Component } from 'react' ;
2
2
import { StyleSheet } from 'react-native' ;
3
- import { Assets , Colors , View , Text , Checkbox } from 'react-native-ui-lib' ; //eslint-disable-line
3
+ import { Assets , Colors , View , Text , Button , Checkbox , CheckboxRef } from 'react-native-ui-lib' ; //eslint-disable-line
4
4
5
5
export default class CheckboxScreen extends Component {
6
6
state = {
@@ -10,7 +10,28 @@ export default class CheckboxScreen extends Component {
10
10
value4 : true ,
11
11
value5 : false ,
12
12
value6 : false ,
13
- value7 : true
13
+ value7 : false ,
14
+ validationText : '' ,
15
+ validationColor : Colors . $textDefault
16
+ } ;
17
+
18
+ checkbox = React . createRef < CheckboxRef > ( ) ;
19
+
20
+ onPress = ( ) => {
21
+ this . checkbox . current ?. validate ( ) ;
22
+ } ;
23
+
24
+ onValueChange = ( value : boolean ) => {
25
+ this . setState ( { value7 : value } , ( ) => {
26
+ console . log ( 'onValueChange: ' , value ) ;
27
+ } ) ;
28
+ } ;
29
+
30
+ onChangeValidity = ( value ?: boolean ) => {
31
+ this . setState ( {
32
+ validationText : String ( value ) ,
33
+ validationColor : value === true ? Colors . $textSuccess : Colors . $textDangerLight
34
+ } ) ;
14
35
} ;
15
36
16
37
render ( ) {
@@ -77,6 +98,24 @@ export default class CheckboxScreen extends Component {
77
98
iconColor = { Colors . green10 }
78
99
/>
79
100
</ View >
101
+
102
+ < View marginT-20 >
103
+ < Text text60 $textDefault marginB-10 >
104
+ Validation
105
+ </ Text >
106
+ < Text marginB-4 color = { this . state . validationColor } > { this . state . validationText } </ Text >
107
+ < View row centerV spread marginB-10 >
108
+ < Checkbox
109
+ required
110
+ onChangeValidity = { this . onChangeValidity }
111
+ ref = { this . checkbox }
112
+ value = { this . state . value7 }
113
+ onValueChange = { this . onValueChange }
114
+ label = { 'This is a checkbox' }
115
+ />
116
+ < Button size = { 'small' } label = { 'Validate' } onPress = { this . onPress } />
117
+ </ View >
118
+ </ View >
80
119
</ View >
81
120
) ;
82
121
}
0 commit comments