Reputation: 143
I can not find anywhere how to write text in border like in photo below with react native
Upvotes: 3
Views: 3763
Reputation: 8794
import React from 'react';
import { View, Text, TextInput, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
container: {
height: 65,
position: 'relative',
},
labelContainer: {
position: 'absolute',
backgroundColor: '#FFF',
top: -8,
left: 25,
padding: 5,
zIndex: 50,
},
textInput: {
flex: 1,
borderWidth: 1,
borderColor: "steel",
justifyContent: 'flex-end',
height: 44,
borderRadius: 65,
paddingHorizontal: 25,
}
})
const CustomTextInput = ({ label, style, ...props}) => (
<View style={styles.container}>
<View style={styles.labelContainer}>
<Text>{label}</Text>
</View>
<TextInput style={styles.textInput}/>
</View>
);
export default CustomTextInput;
Usage:
import TextInput from './TextInput';
<TextInput label="User name" />
You can tweak the styles depending on your needs.
Here's how that looks:
Upvotes: 9