Borders in textInput in React-Native autocomplete-input - react-native

I'm trying to delete the top, right and left borders of my textInput (so obviously, I'd like to have just the bottom border :) ) with the package react-native-autocomplete-input
I tried borderTop : 0 / and 'transparent' but it's not working I still have the borders on top and sides.
borderStyle didn't work either
I get this:
https://zupimages.net/viewer.php?id=20/03/ovck.bmp
my code is this:
<ScrollView style={styles.containerScroll}>
<Text style={styles.h1}>{i18n.t("tripsform.title")}</Text>
<Autocomplete
containerStyle={styles.container}
inputContainerStyle={styles.inputContainer}
autoCapitalize="none"
autoCorrect={false}
data={this.findAirports(query_arrival)}
defaultValue={this.findAirports(query_start)}
onChangeText={text => this.setState({ query_start: text })}
placeholder="Enter Start airports"
renderItem={({ airport }) => (
<TouchableOpacity
onPress={() => this.setState({ query_start: airport })}
>
<Text style={styles.h2}>{airport}-</Text>
</TouchableOpacity>
)}
/>
<Autocomplete
containerStyle={styles.container}
inputContainerStyle={styles.inputContainer}
autoCapitalize="none"
autoCorrect={false}
data={this.findAirports(query_arrival)}
defaultValue={this.findAirports(query_arrival)}
onChangeText={text => this.setState({ query_arrival: text })}
placeholder="Enter Arrival airports"
renderItem={({ airport }) => (
<TouchableOpacity
onPress={() => this.setState({ query_arrival: airport })}
>
<Text style={styles.h2}>{airport}-</Text>
</TouchableOpacity>
)}
/>
<Form ref={c => (this._form = c)} type={Trip} options={options} />
<Text>{"\n"}</Text>
<Text>{"\n"}</Text>
<Button
containerStyle={[styles.mybtnContainer]}
style={styles.mybtn}
onPress={this.handleSubmit}
>
{i18n.t("tripsform.item.add").toUpperCase()}
</Button>
<Button
onPress={() => this.props.navigation.navigate("MyTrips")}
containerStyle={[styles.mybtnContainer]}
style={styles.mybtn}
>
Return to my trips
</Button>
<Text>
{"\n"}
{"\n"}
</Text>
</ScrollView>
with this style:
inputContainer: {
minWidth: 300,
width: "90%",
height: 55,
backgroundColor: "transparent",
color: "#6C6363",
fontSize: 18,
fontFamily: "Roboto",
borderBottomWidth: 1,
borderBottomColor: "rgba(108, 99, 99, .7)"
},
If I can get any help that's really nice, thanks for reading and for any help !

You need to use inputContainerStyle property to apply styles to the input.
You can also use containerStyle to style the container around the AutoComplete so you also don't need to wrap the Autocomplete with View tag.
<Autocomplete
inputContainerStyle={styles.inputContainer}
/>

This Should give you the desired output :) :
<Autocomplete
inputContainerStyle={{width:"100%",borderBottomWidth:1}}
inputStyle={{borderWidth:0}}
data={Options}
handleSelectItem={(item,id)=>optionHandler(item.value,id)}
valueExtractor={item => item.value}
/>

It seems that it's impossible with that package.
I could do what I wanted to do with 'native base autocomplete'.
So, it doesn't completely answer the question but it allows you to do the right thing!

You can set the inputContainer style borderWidth to 0:
// other styles
inputContainer: {
borderWidth: 0,
},

Related

How to add '$' symbol in TextInput when user enter any value in react-native

when I entered any number value in textInput then automatically '$' symbol is generating
<TextInput
style={styles.touchmodelstyle}
autoFocus={true}
keyboardType='number-pad'
>
</TextInput>
Its a little tricky but does the job
<TextInput
value={this.state.value}
onChangeText={(text) => {
text = text.split('$').join('')
this.setState({
value: `${text}$`
})
}
}
/>
I found my question answer so I want to post it.
handleDollar = (value) => {
this.setState({ dollar: value })
};
<View style={styles.touchmodelstyle}>
<Text style={{ marginLeft: RFValue(60),
marginVertical: RFValue(20),
width: wp('4%'),
height: hp('5%'),
elevation: 1 }}>
{this.state.dollar === "" ? "" : "$"}</Text>
<TextInput
autoFocus={true}
placeholder={"other Amount"}
keyboardType='number-pad'
maxLength={3}
value={this.state.dollar}
onChangeText={(value) => this.handleDollar(value)}
>
</TextInput>
</View>

ReactNative multiline TextInput not detecting taps on empty lines

I've been trying to get my TextInput to focus (open keyboard) when I tap anywhere within the (gray) multiline box, but it is only detecting taps on lines with text (or the placeholder).
Is there any way to force the TextInput to focus when I click anywhere on the gray area?
<ScrollView style={{ flex: 1}}>
<View style = {Style.dropdownField}>
<Dropdown
label={'Motivo'}
data={this.props.remiseExcusesData}
value={this.state.remiseExcuses.value}
onChangeText={(value,index, data)=> this.setState({remiseExcuses:data[index]})}
/>
</View>
<View style = {{ height:150, marginHorizontal:20, backgroundColor:'#f9f9f9', marginTop:20}}>
<TextInput
style={Style.minitextInput}
placeholder={'Escribir motivo'}
textAlign={'left'}
autoCorrect={false}
autoCapitalize={'none'}
underlineColorAndroid='transparent'
multiline
onChangeText={(text) => this.setState({motive:text}) }
value={this.state.motive}
onFocus={() => console.log('Fire only on tap')}
/>
</View>
</ScrollView>
You can use this for handle the focus of gray box.
<TouchableOpacity style = {{ height:150, marginHorizontal:20, backgroundColor:'#f9f9f9', marginTop:20}} onPress={this.onPressGrayBox}>
<TextInput
ref="textInput"
style={{ height: 150, textAlignVertical: 'top' }}
placeholder={'Escribir motivo'}
textAlign={'left'}
autoCorrect={false}
autoCapitalize={'none'}
underlineColorAndroid='transparent'
multiline
onChangeText={(text) => this.setState({motive:text}) }
value={this.state.motive}
/>
</TouchableOpacity>
declare the method to handle the action, this will help to set textinput focus automatically.
onPressGrayBox=()=>{
this.refs.textInput.focus()
}
This steps helps me, please use
You can handle something like
<View style = {{ height:150, marginHorizontal:20, backgroundColor:'#f9f9f9', marginTop:20}}>
<TextInput
style={{ height: 150, textAlignVertical: 'top' }}
placeholder={'Escribir motivo'}
textAlign={'left'}
autoCorrect={false}
autoCapitalize={'none'}
underlineColorAndroid='transparent'
multiline
onChangeText={(text) => this.setState({motive:text}) }
value={this.state.motive}
onFocus={() => console.log('Fire only on tap')}
/>
</View>

react native AwesomeAlert customView throwing an error

I am using react-native-awesome-alerts plugin to show an alert in my screen. I've created a custom view for the alert but it throws me this error
Cannot add a child that doesn't have a YogaNode to a parent without a measure function! (Trying to add a 'RCTRawText [text: }]' to a 'RCTView')
My code is like this :
_displayNotifyAlert(){
if(this.state.notifyAlert == true){
return (
<AwesomeAlert
show={true}
title="Service Cancellation"
message="Tell the shop why are you cancelling their services."
messageStyle={{ textAlign: 'center' }}
customView={this.renderCustomAlertView()}
showCancelButton={true}
showConfirmButton={true}
cancelText="Cancel"
confirmText="Cancel Service"
confirmButtonColor={Colors.default}
onCancelPressed={() => this._closeNotifyAlert()}
onConfirmPressed={() => this._cancelServices()}
/>
)
}
}
renderCustomAlertView = () => (
<View style={[ AppStyles.input ]}>
<TextInput
placeholder="Write your reason briefly."
underlineColorAndroid="transparent"
style={{ textAlignVertical: 'top', height: 100 }}
numberOfLines={5}
multiline={true}
maxLength={200}
onChangeText={(cancel_reason) => this.setState({cancel_reason})} />
}
</View>
)
If I remove this line customView={this.renderCustomAlertView()}, the error will disappear. I don't see any incorrect code that I put in the renderCustomAlertView function. So I cannot track down the cause of the error. Is there anybody that faced the same problem before?
There's an extra "}" at the end of your renderCustomAlertView function. Change this function to the following and it should work:
renderCustomAlertView = () => (
<View style={[ AppStyles.input ]}>
<TextInput
placeholder="Write your reason briefly."
underlineColorAndroid="transparent"
style={{ textAlignVertical: 'top', height: 100 }}
numberOfLines={5}
multiline={true}
maxLength={200}
onChangeText={(cancel_reason) => this.setState({cancel_reason})} />
</View>
)
I can't comment in your post because of low reputations so I'm making it as an answer.
As per my knowledge in react native and based on your code You are missing return in renderCustomAlertView .
so your code must be something like
renderCustomAlertView = () => {
return(
<View style={[ AppStyles.input ]}>
<TextInput
placeholder="Write your reason briefly."
underlineColorAndroid="transparent"
style={{ textAlignVertical: 'top', height: 100 }}
numberOfLines={5}
multiline={true}
maxLength={200}
onChangeText={(cancel_reason) => this.setState({cancel_reason})} />
</View>
)
}

Double Tap Button issue when keyBoard opens React native

I know there are already so many queries on this topic, I have tried every step but still won't be able to fix the issue.
Here is the code :
render() {
const {sContainer, sSearchBar} = styles;
if (this.props.InviteState.objectForDeleteList){
this.updateList(this.props.InviteState.objectForDeleteList);
}
return (
<View style={styles.mainContainer}>
<CustomNavBar
onBackPress={() => this.props.navigation.goBack()}
/>
<View
style={sContainer}
>
<ScrollView keyboardShouldPersistTaps="always">
<TextInput
underlineColorAndroid={'transparent'}
placeholder={'Search'}
placeholderTextColor={'white'}
selectionColor={Color.colorPrimaryDark}
style={sSearchBar}
onChangeText={(searchTerm) => this.setState({searchTerm})}
/>
</ScrollView>
{this.renderInviteUserList()}
</View>
</View>
);
}
renderInviteUserList() {
if (this.props.InviteState.inviteUsers.length > 0) {
return (
<SearchableFlatlist
searchProperty={'fullName'}
searchTerm={this.state.searchTerm}
data={this.props.InviteState.inviteUsers}
containerStyle={styles.listStyle}
renderItem={({item}) => this.renderItem(item)}
keyExtractor={(item) => item.id}
/>
);
}
return (
<View style={styles.emptyListContainer}>
<Text style={styles.noUserFoundText}>
{this.props.InviteState.noInviteUserFound}
</Text>
</View>
);
}
renderItem(item) {
return (
this.state.userData && this.state.userData.id !== item.id
?
<TouchableOpacity
style={styles.itemContainer}
onPress={() => this.onSelectUser(item)}>
<View style={styles.itemSubContainer}>
<Avatar
medium
rounded
source={
item.imageUrl === ''
? require('../../assets/user_image.png')
: {uri: item.imageUrl}
}
onPress={() => console.log('Works!')}
activeOpacity={0.7}
/>
<View style={styles.userNameContainer}>
<Text style={styles.userNameText} numberOfLines={1}>
{item.fullName}
</Text>
</View>
<CustomButton
style={{
flexWrap: 'wrap',
alignSelf: 'flex-end',
marginTop: 10,
marginBottom: 10,
width: 90,
}}
showIcon={false}
btnText={'Add'}
onPress={() => this.onClickSendInvitation(item)}
/>
</View>
</TouchableOpacity> : null
);
}
**I even tried with bellow code as suggested by #Nirmalsinh **:
<ScrollView keyboardShouldPersistTaps="always" style={sContainer}>
<CustomNavBar
onBackPress={() => this.props.navigation.goBack()}
/>
<TextInput underlineColorAndroid={'transparent'}
placeholder={'Search'}
placeholderTextColor={'white'}
selectionColor={Color.colorPrimaryDark}
style={sSearchBar}
onChangeText={(searchTerm) => this.setState({searchTerm})} />
{this.renderInviteUserList()}
</ScrollView>
I have followed this article:
https://medium.com/react-native-training/todays-react-native-tip-keyboard-issues-in-scrollview-8cfbeb92995b
I have tried with keyboardShouldPersistTaps=handled also but still, I have to tap twice on my Custom Button to perform an action. Can anybody tell me what I am doing wrong inside the code?
Thanks.
You need to add give value always in keyboardShouldPersistTaps to allow user tap without closing the keyboard.
keyboardShouldPersistTaps='always'
For example:
<ScrollView keyboardShouldPersistTaps='always'>
// Put your component
</ScrollView>
NOTE: Kindly put your tappable component inside the ScrollView. Otherwise it won't work.
You can use keyboardShouldPersistTaps='handled' in a ScrollView or Scrollables like FlatList SectionList etc. and embed a TouchableWithoutFeedBack to handle the case for dismiss on outside clicks.
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<ScrollView keyboardShouldPersistTaps='handled'>
// Rest of the content.
</ScrollView/>
</TouchableWithoutFeedback>
For FlatList and SectionList you will have to handle KeyBoard.dismiss separately.
Please try this, It's working for me, it will works you also, i hope it helps...

Clear btn in Text input is not working well in android devices

I've a btn that clears the text in input which works when the button is touched. But the problem is that the text previously inputted also appear when new text is inputted. How can I solve this problem?
Code:
<View style={styles.textInputStyle}>
<TextInput onChangeText={(text) => this.setState({searchText: text}, () => {
this.state.searchText.length > 1 ? this._getSearchedData() : null
})}
value={this.state.searchText}
placeholder='Search restaurant or cuisine'
/>
<TouchableOpacity onPress= {() => this.setState({searchText: ''})}>
<Icon name="md-close-circle" style={{color: 'gray', fontSize: 15,}}/>
</TouchableOpacity>
</View>
I've only tested in android devices. Simply unfocusing the textInput solves the problem.
<TouchableOpacity onPress={() => {
this.setState({searchText: ''}),
Keyboard.dismiss()
}}>
<Icon name="md-close-circle" style={{color: 'gray', fontSize: 15,}}/>
</TouchableOpacity>