|
| 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'; |
| 5 | + |
| 6 | +const { Header, Body, Card, Footer } = Layout; |
| 7 | + |
| 8 | +export interface VerificationCodeProps extends ComProps { |
| 9 | + onBefore?: () => Promise<boolean>; |
| 10 | + onSend?: () => Promise<boolean> | boolean; |
| 11 | +} |
| 12 | + |
| 13 | +const VerificationCodeDemo: React.FC<VerificationCodeProps> = ({ route }) => { |
| 14 | + const [value, setValue] = useState(''); |
| 15 | + const description = route.params.description; |
| 16 | + const title = route.params.title; |
| 17 | + |
| 18 | + const onChange = (val: string) => { |
| 19 | + console.log('onChange--> 输入改变事件 ', val); |
| 20 | + setValue(val) |
| 21 | + }; |
| 22 | + |
| 23 | + const onBefore = async () => { |
| 24 | + console.log('onBefore--> 发验证码之前的回调 '); |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + const onSend = async () => { |
| 29 | + console.log('onSend--> 发送验证码'); |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + const onEnd = () => { |
| 34 | + console.log('onEnd--> 倒计时结束后的回调'); |
| 35 | + } |
| 36 | + |
| 37 | + return ( |
| 38 | + <Container> |
| 39 | + <Layout> |
| 40 | + <Header title={title} description={description} /> |
| 41 | + <Body style={{ paddingLeft: 16, paddingRight: 16 }}> |
| 42 | + <Card title="基础实例"> |
| 43 | + <VerificationCode |
| 44 | + value={value} |
| 45 | + count={3} |
| 46 | + onChange={(text: string) => onChange(text)} |
| 47 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 48 | + |
| 49 | + /> |
| 50 | + </Card> |
| 51 | + <Card title="无边框"> |
| 52 | + <VerificationCode |
| 53 | + bordered={false} |
| 54 | + label='我没框框哦' |
| 55 | + count={3} |
| 56 | + onChange={(text: string) => onChange(text)} |
| 57 | + outerStyle={{ backgroundColor: '#FFF' }} |
| 58 | + /> |
| 59 | + </Card> |
| 60 | + <Card title="自定义倒计时文字和重新发送文字"> |
| 61 | + <VerificationCode |
| 62 | + label='点我' |
| 63 | + resendLabel='好了' |
| 64 | + value={value} |
| 65 | + count={3} |
| 66 | + onChange={(text: string) => onChange(text)} |
| 67 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 68 | + /> |
| 69 | + </Card> |
| 70 | + <Card title="自定义倒计时时长"> |
| 71 | + <VerificationCode |
| 72 | + count={10} |
| 73 | + value={value} |
| 74 | + onChange={(text: string) => onChange(text)} |
| 75 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 76 | + /> |
| 77 | + </Card> |
| 78 | + <Card title="输入改变事件"> |
| 79 | + <VerificationCode |
| 80 | + value={value} |
| 81 | + count={3} |
| 82 | + onChange={(text: string) => onChange(text)} |
| 83 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 84 | + /> |
| 85 | + </Card> |
| 86 | + <Card title="发验证码之前的回调"> |
| 87 | + <VerificationCode |
| 88 | + value={value} |
| 89 | + count={3} |
| 90 | + onChange={(text: string) => onChange(text)} |
| 91 | + onBefore={onBefore} |
| 92 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 93 | + /> |
| 94 | + </Card> |
| 95 | + <Card title="发送验证码"> |
| 96 | + <VerificationCode |
| 97 | + value={value} |
| 98 | + count={3} |
| 99 | + onChange={(text: string) => onChange(text)} |
| 100 | + onSend={onSend} |
| 101 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 102 | + /> |
| 103 | + </Card> |
| 104 | + <Card title="倒计时结束后的回调"> |
| 105 | + <VerificationCode |
| 106 | + value={value} |
| 107 | + count={3} |
| 108 | + onChange={(text: string) => onChange(text)} |
| 109 | + onEnd={onEnd} |
| 110 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 111 | + /> |
| 112 | + </Card> |
| 113 | + <Card title="自定义外层输入框样式"> |
| 114 | + <VerificationCode |
| 115 | + value={value} |
| 116 | + count={3} |
| 117 | + onChange={(text: string) => onChange(text)} |
| 118 | + outerStyle={{ backgroundColor: '#FFD21D', borderWidth: 1, borderColor: "#ccc" }} |
| 119 | + /> |
| 120 | + </Card> |
| 121 | + <Card title="自定义内层按钮样式"> |
| 122 | + <VerificationCode |
| 123 | + bordered={false} |
| 124 | + value={value} |
| 125 | + count={3} |
| 126 | + onChange={(text: string) => onChange(text)} |
| 127 | + buttonStyle={{ backgroundColor: '#F86E21' }} |
| 128 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 129 | + /> |
| 130 | + </Card> |
| 131 | + <Card title="自定义按钮文字样式"> |
| 132 | + <VerificationCode |
| 133 | + value={value} |
| 134 | + count={3} |
| 135 | + onChange={(text: string) => onChange(text)} |
| 136 | + outerStyle={{ borderWidth: 1, borderColor: "#ccc" }} |
| 137 | + /> |
| 138 | + </Card> |
| 139 | + <Card title="自定义输入框提示文字"> |
| 140 | + <VerificationCode |
| 141 | + bordered={false} |
| 142 | + value={value} |
| 143 | + count={3} |
| 144 | + onChange={(text: string) => onChange(text)} |
| 145 | + placeholder='请输入112233.....' |
| 146 | + outerStyle={{ borderBottomWidth: 1, borderBottomColor: '#CCC' }} |
| 147 | + /> |
| 148 | + </Card> |
| 149 | + </Body> |
| 150 | + <Footer /> |
| 151 | + </Layout> |
| 152 | + </Container> |
| 153 | + ); |
| 154 | +} |
| 155 | + |
| 156 | +export default VerificationCodeDemo; |
| 157 | + |
0 commit comments