1import React, {useState} from 'react'; 2import {StyleSheet, View} from 'react-native'; 3import rpx, {vmax} from '@/utils/rpx'; 4import {fontSizeConst} from '@/constants/uiConst'; 5import useColors from '@/hooks/useColors'; 6 7import ThemeText from '@/components/base/themeText'; 8import {ScrollView, TextInput} from 'react-native-gesture-handler'; 9import PanelBase from '../base/panelBase'; 10import {hidePanel} from '../usePanel'; 11import PanelHeader from '../base/panelHeader'; 12 13interface ISimpleInputProps { 14 title?: string; 15 onOk: (text: string, closePanel: () => void) => void; 16 hints?: string[]; 17 onCancel?: () => void; 18 maxLength?: number; 19 placeholder?: string; 20 autoFocus?: boolean; 21} 22 23export default function SimpleInput(props: ISimpleInputProps) { 24 const { 25 onOk, 26 onCancel, 27 placeholder, 28 maxLength = 80, 29 hints, 30 title, 31 autoFocus = true, 32 } = props; 33 34 const [input, setInput] = useState(''); 35 const colors = useColors(); 36 37 return ( 38 <PanelBase 39 keyboardAvoidBehavior="height" 40 height={vmax(30)} 41 renderBody={() => ( 42 <> 43 <PanelHeader 44 title={title || ''} 45 onCancel={() => { 46 onCancel?.(); 47 hidePanel(); 48 }} 49 onOk={async () => { 50 onOk(input, hidePanel); 51 }} 52 /> 53 54 <TextInput 55 value={input} 56 accessible 57 autoFocus={autoFocus} 58 accessibilityLabel="输入框" 59 accessibilityHint={placeholder} 60 onChangeText={_ => { 61 setInput(_); 62 }} 63 style={[ 64 style.input, 65 { 66 color: colors.text, 67 backgroundColor: colors.placeholder, 68 }, 69 ]} 70 placeholderTextColor={colors.textSecondary} 71 placeholder={placeholder ?? ''} 72 maxLength={maxLength} 73 /> 74 <ScrollView> 75 {hints?.length ? ( 76 <View style={style.hints}> 77 {hints.map((_, index) => ( 78 <ThemeText 79 key={`hint-index-${index}`} 80 style={style.hintLine} 81 fontSize="subTitle" 82 fontColor="textSecondary"> 83 ○ {_} 84 </ThemeText> 85 ))} 86 </View> 87 ) : null} 88 </ScrollView> 89 </> 90 )} 91 /> 92 ); 93} 94 95const style = StyleSheet.create({ 96 wrapper: { 97 width: rpx(750), 98 }, 99 opeartions: { 100 width: rpx(750), 101 paddingHorizontal: rpx(24), 102 flexDirection: 'row', 103 height: rpx(100), 104 alignItems: 'center', 105 justifyContent: 'space-between', 106 }, 107 input: { 108 margin: rpx(24), 109 borderRadius: rpx(12), 110 fontSize: fontSizeConst.content, 111 lineHeight: fontSizeConst.content * 1.5, 112 padding: rpx(12), 113 }, 114 hints: { 115 marginTop: rpx(24), 116 paddingHorizontal: rpx(24), 117 }, 118 hintLine: { 119 marginBottom: rpx(12), 120 }, 121}); 122