-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.tsx
128 lines (121 loc) · 3.19 KB
/
Example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React, {FunctionComponent, useRef, useState} from 'react';
import {TouchableOpacity, ScrollView, Text, TextInput} from 'react-native';
import {CreditCard3D} from 'react-native-3d-card';
const Example: FunctionComponent = () => {
const [name, setName] = useState('');
const [number, setNumber] = useState('');
const [valid, setValid] = useState('');
const [cvv, setCVV] = useState('');
const cardRef = useRef<any>(null);
function rotateBackward() {
cardRef?.current?.rotateBackward();
}
function rotateForward() {
cardRef?.current?.rotateForward();
}
return (
<ScrollView
contentContainerStyle={{paddingHorizontal: 16, paddingVertical: 16}}>
<CreditCard3D
numberValue={number}
nameValue={name}
cvvValue={cvv}
expiracyValue={valid}
ref={cardRef}
/>
<TextInput
placeholder="Número do cartão"
maxLength={number.includes(' ') ? 19 : 16}
style={{
marginTop: 16,
borderColor: '#c1c2c3',
padding: 8,
borderRadius: 8,
borderWidth: 1,
marginBottom: 10,
}}
value={number}
onChangeText={value => setNumber(value)}
/>
<TextInput
placeholder="Nome"
style={{
textTransform: 'capitalize',
borderColor: '#c1c2c3',
padding: 8,
borderRadius: 8,
borderWidth: 1,
marginBottom: 10,
}}
value={name}
onChangeText={value => {
setName(value);
}}
/>
<TextInput
placeholder="Valid thru"
style={{
textTransform: 'capitalize',
borderColor: '#c1c2c3',
padding: 8,
borderRadius: 8,
borderWidth: 1,
marginBottom: 10,
}}
value={valid}
onChangeText={value => {
setValid(value);
}}
/>
<TextInput
onFocus={() => {
rotateBackward();
}}
onBlur={() => {
rotateForward();
}}
maxLength={4}
placeholder="CVV"
style={{
borderColor: '#c1c2c3',
padding: 8,
borderRadius: 8,
borderWidth: 1,
}}
value={cvv}
onChangeText={value => setCVV(value)}
/>
<TouchableOpacity
style={{
backgroundColor: '#c1ccff',
elevation: 2,
alignSelf: 'center',
borderRadius: 8,
width: 130,
height: 40,
marginTop: 16,
justifyContent: 'center',
alignItems: 'center',
}}
onPress={() => rotateBackward()}>
<Text style={{color: '#333345'}}>Rotate Backward</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#c1ccff',
elevation: 2,
alignSelf: 'center',
borderRadius: 8,
width: 130,
marginTop: 16,
height: 40,
}}
onPress={() => rotateForward()}>
<Text style={{color: '#333345'}}>Rotate Forward</Text>
</TouchableOpacity>
</ScrollView>
);
};
export default Example;