Skip to content

Commit ccde846

Browse files
author
hy
committed
fix(VerificationCode):优化VerificationCode倒计时组件代码和文档
1 parent f8838bf commit ccde846

File tree

2 files changed

+42
-59
lines changed
  • example/examples/src/routes/VerificationCode
  • packages/core/src/VerificationCode

2 files changed

+42
-59
lines changed
Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,80 @@
1-
import React, { Component, useState } from 'react';
2-
import { VerificationCode } from '@uiw/react-native';
3-
import Layout, { Container } from '../../Layout';
4-
import { ComProps } from '../../routes';
1+
import React, {Component, useState} from 'react';
2+
import {VerificationCode} from '@uiw/react-native';
3+
import Layout, {Container} from '../../Layout';
4+
import {ComProps} from '../../routes';
55

6-
const { Header, Body, Card, Footer } = Layout;
6+
const {Header, Body, Card, Footer} = Layout;
77

88
export interface VerificationCodeProps extends ComProps {
99
onBefore?: () => Promise<boolean>;
1010
onSend?: () => Promise<boolean> | boolean;
1111
}
1212

13-
const VerificationCodeDemo: React.FC<VerificationCodeProps> = ({ route }) => {
13+
const VerificationCodeDemo: React.FC<VerificationCodeProps> = ({route}) => {
1414
const [value, setValue] = useState('');
1515
const description = route.params.description;
1616
const title = route.params.title;
1717

1818
const onChange = (val: string) => {
1919
console.log('onChange--> 输入改变事件 ', val);
20-
setValue(val)
20+
setValue(val);
2121
};
2222

2323
const onBefore = async () => {
2424
console.log('onBefore--> 发验证码之前的回调 ');
2525
return true;
26-
}
26+
};
2727

2828
const onSend = async () => {
2929
console.log('onSend--> 发送验证码');
3030
return true;
31-
}
31+
};
3232

3333
const onEnd = () => {
3434
console.log('onEnd--> 倒计时结束后的回调');
35-
}
35+
};
3636

3737
return (
3838
<Container>
3939
<Layout>
4040
<Header title={title} description={description} />
41-
<Body style={{ paddingLeft: 16, paddingRight: 16 }}>
41+
<Body style={{paddingLeft: 16, paddingRight: 16}}>
4242
<Card title="基础实例">
43-
<VerificationCode
44-
value={value}
45-
count={3}
46-
onChange={(text: string) => onChange(text)}
47-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
48-
49-
/>
43+
<VerificationCode value={value} count={3} onChange={(text: string) => onChange(text)} outerStyle={{borderWidth: 1, borderColor: '#ccc'}} />
5044
</Card>
5145
<Card title="无边框">
5246
<VerificationCode
5347
bordered={false}
54-
label='我没框框哦'
48+
label="我没框框哦"
5549
count={3}
5650
onChange={(text: string) => onChange(text)}
57-
outerStyle={{ backgroundColor: '#FFF' }}
51+
outerStyle={{backgroundColor: '#FFF'}}
52+
buttonStyle={{backgroundColor: '#fff'}}
5853
/>
5954
</Card>
6055
<Card title="自定义倒计时文字和重新发送文字">
6156
<VerificationCode
62-
label='点我'
63-
resendLabel='好了'
57+
label="点我"
58+
resendLabel="好了"
6459
value={value}
6560
count={3}
6661
onChange={(text: string) => onChange(text)}
67-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
62+
outerStyle={{borderWidth: 1, borderColor: '#ccc'}}
6863
/>
6964
</Card>
7065
<Card title="自定义倒计时时长">
71-
<VerificationCode
72-
count={10}
73-
value={value}
74-
onChange={(text: string) => onChange(text)}
75-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
76-
/>
66+
<VerificationCode count={10} value={value} onChange={(text: string) => onChange(text)} outerStyle={{borderWidth: 1, borderColor: '#ccc'}} />
7767
</Card>
7868
<Card title="输入改变事件">
79-
<VerificationCode
80-
value={value}
81-
count={3}
82-
onChange={(text: string) => onChange(text)}
83-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
84-
/>
69+
<VerificationCode value={value} count={3} onChange={(text: string) => onChange(text)} outerStyle={{borderWidth: 1, borderColor: '#ccc'}} />
8570
</Card>
8671
<Card title="发验证码之前的回调">
8772
<VerificationCode
8873
value={value}
8974
count={3}
9075
onChange={(text: string) => onChange(text)}
9176
onBefore={onBefore}
92-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
77+
outerStyle={{borderWidth: 1, borderColor: '#ccc'}}
9378
/>
9479
</Card>
9580
<Card title="发送验证码">
@@ -98,7 +83,7 @@ const VerificationCodeDemo: React.FC<VerificationCodeProps> = ({ route }) => {
9883
count={3}
9984
onChange={(text: string) => onChange(text)}
10085
onSend={onSend}
101-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
86+
outerStyle={{borderWidth: 1, borderColor: '#ccc'}}
10287
/>
10388
</Card>
10489
<Card title="倒计时结束后的回调">
@@ -107,15 +92,15 @@ const VerificationCodeDemo: React.FC<VerificationCodeProps> = ({ route }) => {
10792
count={3}
10893
onChange={(text: string) => onChange(text)}
10994
onEnd={onEnd}
110-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
95+
outerStyle={{borderWidth: 1, borderColor: '#ccc'}}
11196
/>
11297
</Card>
11398
<Card title="自定义外层输入框样式">
11499
<VerificationCode
115100
value={value}
116101
count={3}
117102
onChange={(text: string) => onChange(text)}
118-
outerStyle={{ backgroundColor: '#FFD21D', borderWidth: 1, borderColor: "#ccc" }}
103+
outerStyle={{backgroundColor: '#FFD21D', borderWidth: 1, borderColor: '#ccc'}}
119104
/>
120105
</Card>
121106
<Card title="自定义内层按钮样式">
@@ -124,34 +109,28 @@ const VerificationCodeDemo: React.FC<VerificationCodeProps> = ({ route }) => {
124109
value={value}
125110
count={3}
126111
onChange={(text: string) => onChange(text)}
127-
buttonStyle={{ backgroundColor: '#F86E21' }}
128-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
112+
buttonStyle={{backgroundColor: '#F86E21'}}
113+
outerStyle={{borderWidth: 1, borderColor: '#ccc'}}
129114
/>
130115
</Card>
131116
<Card title="自定义按钮文字样式">
132-
<VerificationCode
133-
value={value}
134-
count={3}
135-
onChange={(text: string) => onChange(text)}
136-
outerStyle={{ borderWidth: 1, borderColor: "#ccc" }}
137-
/>
117+
<VerificationCode value={value} count={3} onChange={(text: string) => onChange(text)} outerStyle={{borderWidth: 1, borderColor: '#ccc'}} />
138118
</Card>
139119
<Card title="自定义输入框提示文字">
140120
<VerificationCode
141121
bordered={false}
142122
value={value}
143123
count={3}
144124
onChange={(text: string) => onChange(text)}
145-
placeholder='请输入112233.....'
146-
outerStyle={{ borderBottomWidth: 1, borderBottomColor: '#CCC' }}
125+
placeholder="请输入112233....."
126+
outerStyle={{borderBottomWidth: 1, borderBottomColor: '#CCC'}}
147127
/>
148128
</Card>
149129
</Body>
150130
<Footer />
151131
</Layout>
152132
</Container>
153133
);
154-
}
134+
};
155135

156136
export default VerificationCodeDemo;
157-

packages/core/src/VerificationCode/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ interface VerificationCodeProps {
2323
}
2424

2525
const VerificationCode: FC<VerificationCodeProps> = ({
26-
bordered = true,
26+
bordered = false,
2727
label = '获取验证码',
2828
resendLabel = '重新发送',
2929
count = 60,
3030
value = '',
31-
onChange = () => { },
31+
onChange = () => {},
3232
onBefore = async () => true,
3333
onSend = async () => true,
34-
onEnd = () => { },
34+
onEnd = () => {},
3535
outerStyle = {},
3636
buttonStyle = {},
3737
placeholder = '请输入验证码',
@@ -40,7 +40,6 @@ const VerificationCode: FC<VerificationCodeProps> = ({
4040
const [disabled, setDisabled] = useState(false);
4141
const theme = useTheme<Theme>();
4242

43-
4443
useEffect(() => {
4544
let interval: ReturnType<typeof setInterval>;
4645
if (timer > 0 && disabled) {
@@ -66,18 +65,23 @@ const VerificationCode: FC<VerificationCodeProps> = ({
6665
return (
6766
<Input
6867
border={null}
69-
containerStyle={[{ height: 50 }, outerStyle]}
68+
containerStyle={[{ height: 40 }, outerStyle]}
7069
placeholder={placeholder}
7170
value={value}
7271
onChangeText={(text) => onChange(text)}
7372
extraEnd={
74-
<Button bordered={bordered} disabled={disabled} onPress={handleClick} color={theme.colors.background || '#fff'} style={buttonStyle}>
75-
<Text color={disabled ? "disabled" : "text"}>{disabled ? `${resendLabel}(${timer}s)` : label}</Text>
73+
<Button
74+
bordered={bordered}
75+
disabled={disabled}
76+
onPress={handleClick}
77+
color={theme.colors.background || '#fff'}
78+
style={buttonStyle}
79+
>
80+
<Text color={disabled ? 'disabled' : 'text'}>{disabled ? `${resendLabel}(${timer}s)` : label}</Text>
7681
</Button>
7782
}
7883
/>
7984
);
8085
};
8186

8287
export default VerificationCode;
83-

0 commit comments

Comments
 (0)