I am using the TextInput of React Native Paper (https://callstack.github.io/react-native-paper/text-input.html)
Is there a way to not show the label on the border line when we are focusing on a TextInput?
<TextInput
mode="outlined"
label="Email"
value={email}
onChangeText={email => setEmail(email)}
theme={{ colors: { primary: APP_COLORS.primary }}}
selectionColor={APP_COLORS.primary}
outlineColor={APP_COLORS.grey_low}
left={<TextInput.Icon name={() => <AntDesign name="mail" size={22} color="black" />} />}
/>
The label "Email" in black in your picture appears to come from another component not included in your code snippet.
If you wish to keep the "Email" label in black, remove the "Email" label in red, but retain the outlined style of the TextInput, you can simply remove the label key of the component:
<TextInput
mode="outlined"
value={email}
onChangeText={email => setEmail(email)}
theme={{
colors: { primary: APP_COLORS.primary }
}}
selectionColor={APP_COLORS.primary}
outlineColor={APP_COLORS.grey_low}
left={
<TextInput.Icon name={() =>
<AntDesign
name="mail"
size={22}
color="black"
/>
}/>
}
/>
Related
I'm using react-native-paper TextInput to show email icon on the left side of text input and that icon should be green (#22C55E) but it's still showing the default color.
<TextInput
placeholder={t('Email')}
style={styles.textInput}
mode="outlined"
outlineColor={Colors.transparent}
activeOutlineColor={Colors.hostessGreen}
theme={{ roundness: 16 }}
left={
<TextInput.Icon
icon={'email-outline'}
color="#22C55E"
style={styles.leftIcon as StyleProp<ViewStyle>}
size={responsiveFontSize(3)}
/>
}
/>
You have to add iconColor='#22C55E' add in place of color="#22C55E" props in TextInput.Icon.you will be able to change color easily.
<TextInput
placeholder={t('Email')}
style={styles.textInput}
mode="outlined"
outlineColor={Colors.transparent}
activeOutlineColor={Colors.hostessGreen}
theme={{ roundness: 16 }}
left={
<TextInput.Icon
icon={'email-outline'}
iconColor="#22C55E"
style={styles.leftIcon as StyleProp<ViewStyle>}
size={responsiveFontSize(3)}
/>
}
/>
I have a form where I am using KeyboardAvoidingView and ScrollView so that when a user clicks on an input field the screen will scroll to that particular field
Within my form I have an input field that is searchable and I am using a FlatList to display the results for the user to choose from. Currently I am getting the error:
VirtualizedLists should never be nested inside plain ScrollViews
I've looked at many posts around this but am yet to find a solution (unless I've missed something):
1 - How to put FlatList inside of the ScrollView in React-native?
2 - FlatList inside ScrollView doesn't scroll
3 - How to make a FlatList scrollable inside of a ScrollView in react native?
This is what I have so far:
export const SignUpMember = ({navigation}) => {
const renderHeader = formikProps => {
return (
<>
<FormField
keyboardType={'default'}
fieldName={'firstName'}
label={'First Name'}
/>
<FormField
keyboardType={'default'}
fieldName={'lastName'}
label={'Last Name'}
/>
<FormField
onChangeText={text => {
formikProps.values.clubName = text;
searchItems(text);
}}
value={formikProps.values.clubName}
keyboardType={'default'}
fieldName={'clubName'}
label={'Club Name'}
placeholder={'Search Club By Name...'}
/>
</>
);
};
const renderFooter = formikProps => {
return (
<>
<FormField
keyboardType={'phone-pad'}
fieldName={'telephone'}
label={'Telephone'}
/>
<FormField
keyboardType={'email-address'}
fieldName={'email'}
label={'Email'}
/>
<FormField
keyboardType="default"
secureTextEntry={true}
fieldName={'password'}
label={'Password'}
type={'password'}
/>
<FormField
keyboardType="default"
secureTextEntry={true}
fieldName={'passwordConfirmation'}
label={'Confirm Password'}
type={'password'}
/>
<Button
mt="2"
bg="brand.blue"
type="submit"
onPress={formikProps.handleSubmit}>
Sign Up
</Button>
</>
);
};
return (
<KeyboardAvoidingView
keyboardVerticalOffset={headerHeight}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
<ScrollView
_contentContainerStyle={styles.container}
nestedScrollEnabled={true}>
<Box p="1" py="8" w="90%" maxW="290">
<VStack space={3} mt="5">
<Formik
initialValues={initialFormValues}
onSubmit={values => handleFormSubmit(values)}
validationSchema={userValidationSchema}>
{formikProps => (
<View>
<FlatList
nestedScrollEnabled={true}
data={flatListData}
renderItem={({item}) => (
<Pressable
onPress={() => {
formikProps.values.clubName = item.name;
setFlatListData([]);
}}>
<Text style={styles.flatList}>{item.name}</Text>
</Pressable>
)}
keyExtractor={item => item.name}
ListHeaderComponent={renderHeader(formikProps)}
ListFooterComponent={renderFooter(formikProps)}
/>
</View>
)}
</Formik>
</VStack>
</Box>
</ScrollView>
</KeyboardAvoidingView>
);
};
export default SignUpMember;
How can I piece this together?
I have created a signup form in react native with formik and yup.According to the documentation I have added the react native picker.
<Formik
initialValues={{ password: '', first_name: '', email: '', passwordConfirmation: '' }}
onSubmit={values => handleSubmit(values)}
validationSchema={registerSchema}
>
{({ handleChange, handleBlur, handleSubmit, values, touched, errors }) => (
<View>
<TextInput
style={styles.textInputTop}
onChangeText={handleChange('first_name')}
onBlur={handleBlur('first_name')}
value={values.first_name}
label="First Name"
mode="outlined"
/>
<Text style={styles.errorMsg}>{touched.first_name && errors.first_name}</Text>
//Other Fields I have not mentioned in the code
<View style={styles.pickerContainer}>
<Text style={styles.depText}>Department</Text>
<Picker
style={{ height: 50, width: 150 }}
onValueChange={(itemValue, itemIndex) => setdepartment(itemValue)}
mode={"dropdown"}
>
<Picker.Item label="Management" value="Management" />
<Picker.Item label="HR" value="HR" />
<Picker.Item label="Accounting" value="Accounting" />
<Picker.Item label="Sales" value="Sales" />
</Picker>
</View>
<Button style={styles.btn} mode="contained" onPress={handleSubmit}>
<Text style={{ color: "white" }}>Sign Up</Text>
</Button>
</View>
)}
</Formik>
I need to add formik and yup to the picker to make it a required field. How do I do it?
If it is not possible with formik and yup, then how I can make the picker required.
on the registerSchema make:
department: Yup.string().required('this field is required')
department will hold the selected value from the picker, you may change the type from string to array depending on the selected value.
I am not able to identify how to display Menu items when clicked on Icon in React Native
Expo Link
Code
_onPressItem = () => {
this.setState({ opened: true });
};
render() {
return (
<View style={styles.container}>
<ListItem
title={
<View>
<Text style={{ fontWeight: "bold" }}>Mason Laon Roah</Text>
<Text>9886012345</Text>
</View>
}
subtitle={
<View>
<Text>445 Mount Eden Road, Mount Eden, Auckland. </Text>
<Text>Contact No: 134695584</Text>
</View>
}
leftAvatar={{ title: 'MD' }}
rightContentContainerStyle={{ alignSelf: 'flex-start'}}
rightTitle={<Icon type="material" color="red" name="more-vert" />}
/>
</View>
);
}
getMenuView() {
const { opened } = this.state;
return (
<MenuProvider style={{flexDirection: 'column', padding: 30}}>
<Menu
opened={opened}
onBackdropPress={() => this.onBackdropPress()}
onSelect={value => this.onOptionSelect(value)}>
<MenuTrigger onPress={() => this._onPressItem()} text="Menu Icon Here" />
<MenuOptions>
<MenuOption value={1} text='One' />
<MenuOption value={2}>
<Text style={{color: 'red'}}>Two</Text>
</MenuOption>
<MenuOption value={3} disabled={true} text='Three' />
</MenuOptions>
</Menu>
</MenuProvider>
);
}
Please let me know how to integrate Menu with Icon..
Basically all the items are displayed in FlatList where each item have its own Menu Item
Just Update Code below:
instead of:
rightTitle={<Icon type="material" color="red" name="more-vert" />}
update to:
rightTitle={this.getMenuView()}
Because this Method returns view not Menu popup.
and instead of:
<MenuTrigger onPress={() => this._onPressItem()} text="Menu Icon Here" />
update to:
<MenuTrigger onPress={() => this._onPressItem()}>
<Icon type="material" color="red" name="more-vert" />
</MenuTrigger>
so that instead of printing text, it shows icon.
I tried this code on your given link, it works..
I want to make a text input readonly in my RN application. I tried to set an editable prop but it did not work properly. How can I achieve this?
<DetailInput
inputStyle={styles.inputStyles}
height={120}
width={width - 40}
multiline={true}
numberOfLines={6}
underlineColorAndroid="transparent"
maxLength={500}
editable={!userRegistrationInProgress}
onChangeText={value => this.statementChangedHandler(value)}
/>
const detailInput = props => {
return (
<TextInput
{...props}
style=
{[
props.inputStyle,
{ height: props.height, width: props.width},
!props.valid && props.touched ? props.invalidInput : null
]}
/>
);
}
export default detailInput;
<TextInput
value = "Read Only"
editable = {false}
/>
Set editable false to read only TextInput.
A better readonly Text input:
<View pointerEvents="none">
<TextInput value="I am read only" editable={false} />
</View>
https://facebook.github.io/react-native/docs/view#pointerevents