reza completed Custom Text Input

RezaAshrafi77 3 years ago
parent e5da5e8058
commit 3bf7d8da4b
  1. BIN
      android/app/src/main/res/drawable/heart.png
  2. 68
      src/components/CustomTextInput/index.js
  3. 19
      src/views/Home/index.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

@ -1,37 +1,51 @@
import React, {useState} from 'react'; import React, {useState} from 'react';
import {TextInput, View, Text, Dimensions} from 'react-native'; import {TextInput, View, Text, Dimensions, StyleSheet} from 'react-native';
const FloatingLabelInput = ({label}) => { const FloatingLabelInput = ({
label,
textAlign,
direction,
onInputChange,
labelBackgroundColor,
onChangeText,
value,
...props
}) => {
const [isFocused, setIsFocused] = useState(false); const [isFocused, setIsFocused] = useState(false);
const styles = StyleSheet.create({
const labelStyle = { labelStyle: {
position: 'absolute', position: 'absolute',
right: 10, right: 15,
backgroundColor : '#eee', backgroundColor: labelBackgroundColor,
zIndex: 100, zIndex : 100,
paddingHorizontal : 5, paddingHorizontal: 5,
top: !isFocused ? '50%' : 0, textAlign: 'center',
fontSize: !isFocused ? Dimensions.get('window').width / 25 : 14, top: !isFocused ? '50%' : 0,
transform: [{translateY: -Dimensions.get('window').width / 35}], fontSize: !isFocused ? Dimensions.get('window').width / 25 : 14,
color: !isFocused ? '#000' : '#000', transform: [{translateY: -Dimensions.get('window').width / 35}],
}; color: !isFocused ? '#000' : '#6CBE44',
// transition: Transitions.all(Transitions.)
},
inputStyle: {
fontSize: Dimensions.get('window').width / 25,
color: '#000',
borderWidth: 0.5,
borderColor: isFocused ? '#6CBE44' : '#555',
borderRadius: 10,
padding: 10,
direction: direction,
textAlign: textAlign,
},
});
return ( return (
<View style={{marginTop: 18}}> <View style={{marginTop: 18}}>
<Text style={labelStyle}>{label}</Text> <Text style={styles.labelStyle}>{label}</Text>
<TextInput <TextInput
// {...props} {...props}
style={{ style={styles.inputStyle}
// height: 26, onChangeText={text => onChangeText(text)}
fontSize: Dimensions.get('window').width / 25,
color: '#000',
borderWidth: 0.5,
borderColor: '#555',
borderRadius: 10,
padding: 10,
textAlign: 'right'
}}
onFocus={() => setIsFocused(true)} onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)} onBlur={() => (value ? setIsFocused(true) : setIsFocused(false))}
/> />
</View> </View>
); );

@ -1,11 +1,24 @@
import React from 'react'; import React, {useState} from 'react';
import {View} from 'react-native'; import {View, Text} from 'react-native';
import CustomTextInput from '../../components/CustomTextInput/index'; import CustomTextInput from '../../components/CustomTextInput/index';
function Home({}) { function Home({}) {
const [firstName, setFirstName] = useState('');
return ( return (
<View> <View>
<CustomTextInput label="نام" /> <CustomTextInput
label="نام"
textAlign="right"
direction="rtl"
labelBackgroundColor="#eee"
onChangeText={setFirstName}
value={firstName}
name="firstName"
numberOfLines={1}
multiline={false}
inlineLeftImage="heart"
/>
<Text>{firstName}</Text>
</View> </View>
); );
} }

Loading…
Cancel
Save