custom Icons in NativeBase - react-native

I want to use my own icon group in native-base.i read this post How to add custom Icons to NativeBase
bu nothing to show. this is my code I want to use, in first Item after added icon placeholder remove:
<View style={styles.view}>
<Item floatingLabel style={{ width: w / 1.9, height: w / 7, borderColor: '#507783', marginBottom: 0, }} >
<Icon><MyIcon name="ico_user" style={{ color: "#fff" }}/></Icon>
<Input returnKeyType='next' autoCapitalize="none" onChangeText={text => setUsername(text)} style={{ paddingBottom: 0, color: '#fff', textAlign: 'left', fontFamily: 'IRANSansMobile', fontSize: 12, marginLeft: 8, }} placeholderTextColor="#507783" placeholder='نام کاربری' />
</Item>
<Item floatingLabel secureTextEntry={true} style={{ width: w / 1.9, height: w / 7, borderColor: '#507783' }} >
<Icon type="Fontisto" name="locked" fontSize={25} style={{ color: "#fff" }} />
<Input returnKeyType='next' autoCapitalize="none" onChangeText={text => setUsername(text)} style={{ color: '#fff', textAlign: 'left', fontFamily: 'IRANSansMobile', fontSize: 12, marginLeft: 8, }} placeholderTextColor="#507783" placeholder='رمز عبور' />
</Item>
<Button block style={{ width: w / 1.9, height: 40, backgroundColor: '#59c5b9', marginTop: 56 }} onPress={() => internet.isConnected ? _goLogin() : Alert.alert('لطفا اتصال به اینترنت خود را بررسی نمایید')}>
<Text style={styles.btntext}>ورود</Text>
</Button>
</View>
and this is my icon-fon.js:
import {createIconSetFromFontello} from 'react-native-vector-icons';
import fontelloConfig from './ecfco.json';
const Icon = createIconSetFromFontello(fontelloConfig,'ecfco');
export default Icon;
and i check this directory in android:android/app/src/main/assets/fonts font correctly added.
and check ios version evry think is ok but not working.
and native-base version : "native-base": "^2.13.12",
UPDATE:
when using MyIcon outside of Item work perfectly but when used an icon for Input nothing to show
thank for helping solve this problem.

I solved it. read this post on gihub : Trying to add an Image on the right of a Label. It's working fine with stackedlabel but floating label is making the image
change my way, replace Icon to Thumbnail and correct code below:
<Item floatingLabel >
<Thumbnail square source={require('../../assets/Newimage/Login/ico_user.png')} resizeMode='center' />
<Label>نام کاربری</Label>
<Input returnKeyType='next' autoCapitalize="none" onChangeText={text => setUsername(text)} />
</Item>

Related

backgroundColor hiding the clearButtonMode's X in Input of react-native-elements

<Input
autoFocus
containerStyle={styles.search}
placeholder="Search..."
onChangeText={this.Search}
inputContainerStyle={{ borderBottomWidth: 0 }}
clearButtonMode="always"
placeholderTextColor={theme.firstColor.hex}
/>
const styles = StyleSheet.create({
search: {
backgroundColor: "white", // <--- This is hiding the X button
paddingLeft: 20,
borderRadius: 10,
borderColor: theme.secondColor,
width: 300,
height: 50,
}
});
Basically, backgroundColor: "white" is hiding the clearButtonMode's X button, is there any workaround for this?
As my researching, react-native-elements does not support Input clear button styling, yet.
So, I think you should try to customize it, something like this:
import {Icon, Input} from 'react-native-elements';
<Input
...
rightIcon={
<Icon
containerStyle={{
marginRight: normalize(10)
}}
name={'ios-close'} type={'ionicon'} color="#7384B4" size={22}
onPress={() => {
this.setState({email: ''});
}}
/>
}
/>
Hope it help ^^.

How can i disable a material UI dropdown in react native?

I want to call an API on save button, the thing which i need is that i need the disable the dropdown and edit it using a button.
But i am not able to find how do i disable and edit the 'react-native-material-dropdown'. How can i make it toggle or change between edit and disable ?
I am not able to find anything on google and in the documentation.
<View style={styles.margin}>
<Dropdown
textColor={color.textWhiteColor}
textAlign='center'
fontSize={14}
itemCount={4}
value={prop.current_inventory}
baseColor={color.textWhiteColor}
fontWeight='bold'
fontFamily='Lato'
textAlign='left'
left={10}
top={5}
dropdownPosition={-3.5}
pickerStyle={{
backgroundColor: color.textWhiteColor,
width: '80%',
marginLeft: 20
}}
containerStyle={{
borderRadius: 10,
backgroundColor: color.headerDropdown,
width: '100%',
marginTop: 5
}}
onChangeText={(value) => this.checkValue(value, index)}
itemTextStyle={{
fontWeight: 'bold',
fontFamily: 'Lato',
}}
inputContainerStyle={{ borderBottomColor: 'transparent' }}
itemColor='black'
selectedItemColor='black'
dropdownOffset={
{ top: 0, left: 0 }}
data={this.currentInventory}
/>
</View>
<View>
<TouchableHiglight onPress= >
<Text>SAVE</Text>
</TouchableHiglight>
<TouchableHiglight onPress= >
<Text>EDIT</Text>
</TouchableHiglight>
</View>
You can try passing a variable (since this is related to UI, we expect to pass a state) to handle the "disable property". The only thing you have to do is to give your View wrapper a prop called pointerEvents.
So, it would be like the following:
<View style={styles.margin} pointerEvents={isDisabled ? "none" : undefined}>
<Dropdown
textColor={color.textWhiteColor}
textAlign='center'
fontSize={14}
itemCount={4}
value={prop.current_inventory}
baseColor={color.textWhiteColor}
fontWeight='bold'
fontFamily='Lato'
textAlign='left'
left={10}
top={5}
dropdownPosition={-3.5}
pickerStyle={{
backgroundColor: color.textWhiteColor,
width: '80%',
marginLeft: 20
}}
containerStyle={{
borderRadius: 10,
backgroundColor: color.headerDropdown,
width: '100%',
marginTop: 5
}}
onChangeText={(value) => this.checkValue(value, index)}
itemTextStyle={{
fontWeight: 'bold',
fontFamily: 'Lato',
}}
inputContainerStyle={{ borderBottomColor: 'transparent' }}
itemColor='black'
selectedItemColor='black'
dropdownOffset={
{ top: 0, left: 0 }}
data={this.currentInventory}
/>
</View>
Also, I encourage you to use a linting tool like ESLint, you are repeating the same prop "textAlign" twice. See more

Can't blur out of FormInput when clicking outside of the textbox

I have a short form that has two FormInput fields (from react-native-elements). I've tried using several methods to remove focus (and hide keyboard) when touching anywhere on the screen outside of the text input.
<View style={{flex:1}}>
<ScrollView keyboardShouldPersistTaps="handled">
<FormInput
placeholder='Phone Number'
errorStyle={{ color: 'red' }}
inputStyle={{ color: 'white', fontSize: 20, fontFamily: 'Roboto-Thin', borderBottomColor: 'transparent'}}
placeholderTextColor='white'
onChangeText = {this.onPhoneChange.bind(this)}
containerStyle = {{ borderBottomWidth: 1, borderBottomColor: '#4DB1AD', width: '90%'}}
keyboardType='numeric'
maxLength={10}
/>
</ScrollView>
</View>
I also tried
<TouchableWithoutFeedback style={{flex: 1}} onPress={Keyboard.dismiss} accessible={false}>
<View>
<FormInput
placeholder='Phone Number'
errorStyle={{ color: 'red' }}
inputStyle={{ color: 'white', fontSize: 20, fontFamily: 'Roboto-Thin', borderBottomColor: 'transparent'}}
placeholderTextColor='white'
onChangeText = {this.onPhoneChange.bind(this)}
containerStyle = {{ borderBottomWidth: 1, borderBottomColor: '#4DB1AD', width: '90%'}}
keyboardType='numeric'
maxLength={10}
onSubmitEditing={Keyboard.dismiss}
onBlur={Keyboard.dismiss}
blurOnSubmit={true}
/>
</View>
</TouchableWithoutFeedback>
and this method
<TouchableOpacity activeOpacity={1} onPress={() => Keyboard.dismiss()}>
<FormInput
placeholder='Phone Number'
errorStyle={{ color: 'red' }}
inputStyle={{ color: 'white', fontSize: 20, fontFamily: 'Roboto-Thin', borderBottomColor: 'transparent'}}
placeholderTextColor='white'
onChangeText = {this.onPhoneChange.bind(this)}
containerStyle = {{ borderBottomWidth: 1, borderBottomColor: '#4DB1AD', width: '90%'}}
keyboardType='numeric'
maxLength={10}
/>
</TouchableOpacity>
Unfortunately, none of these solutions worked for me.

react-native: Picker in Modal not showing

When my Picker is embedded in Modal, it doesn't appear on screen (only tested for android)
renderModal() {
return (
<Modal
transparent={true}
visible={this.state.showModal}
onRequestClose={() => this.setState({ modalIsVisible: false })}
animationType={'fade'}>
<View
style={{ backgroundColor:'rgba(0, 0, 0, 0.7)', flex: 1, justifyContent: 'center', padding: 20, height:100 }}>
<View style={{ borderRadius:10, alignItems: 'center', backgroundColor: '#fff', padding: 20 }}>
<Text>
Choisissez la priorité de cet emplacement
</Text>
<Picker
selectedValue={this.state.storagePriority}
onValueChange={(priority) => this.setState({storagePriority: priority})}>
<Picker.Item label="Basse" value="LOW" />
<Picker.Item label="Normale" value="MEDIAN" />
<Picker.Item label="Haute" value="HIGH" />
<Picker.Item label="Réserve" value="STOCK" />
</Picker>
</View>
</View>
</Modal>
);
}
Any suggestion?
Give proper styling for picker and run it.
Here is a sample code for styling picker.
<Picker
style={styles.picker}
mode="dropdown"
itemStyle={styles.itemStyle}>
<Item label="Basse" value="LOW" />
<Item label="Normale" value="MEDIAN" />
</Picker>
styles:
itemStyle: {
fontSize: 15,
height: 75,
color: 'black',
textAlign: 'center',
fontWeight: 'bold'
}
picker: {
width: 100
},
Setting a style={{ width: 100 }} for Picker solved it

TextInput border and width within a React-Native view

I have a react-native view that has this piece:
<View style={styles.section}>
<Text style={styles.h2}>
NAME
</Text>
<TextInput style={styles.input} placeholder="Name" />
<Text style={styles.h2}>
EMAIL
</Text>
<TextInput style={styles.input} placeholder="Password" />
</View>
input: {
height: 30,
flex: 0.7,
fontSize: 13,
padding: 4,
borderBottomColor: '#fff',
borderRightColor: 'transparent',
borderLeftColor: 'transparent',
borderTopColor: 'transparent',
borderTopWidth: 0,
borderBottomWidth: 0.5,
},
Unfortunately, this shows no border (instead of the desired underline border), and both input boxes take up the full screen (instead of the 0.7 flex I want). How do I fix this?
You cannot declare a specific border directly on the TextInput unless multiline is enabled you can checkout this link.
I wrap my TextInput in a view and then add a border to the view and in your case you don't want your text input to be full width I just add a margin on the left and right.
Wrapping the TextInput inside views:
<View style={styles.section}>
<Text style={styles.h2}>
NAME
</Text>
<View style={styles.inputView}>
<TextInput style={styles.input} placeholder="Name" />
</View>
<Text style={styles.h2}>
EMAIL
</Text>
<View style={styles.inputView}>
<TextInput style={styles.input} placeholder="Password" />
</View>
</View>
The styles for those views:
input: {
height: 40,
fontSize: 13,
padding: 4,
},
section:{
marginLeft:10,
marginRight:10,
},
inputView:{
borderBottomColor: '#fff',
borderBottomWidth: 0.5,
}