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
Related
I am developing a password management app in react-native(expo). I Today, I encountered this glitch/bug where the keyboard automatically hides if a TextInput is below the keyboard level. It works if I position it, above keyboard level. I tried Wrapping it with KeyboardAvoidingView but then, I could not interact with TextInput anymore. Also, I am using Input component from "react-native-elements". Here is the demonstration of the problem.
Below is my code:-
<View
style={{
display: "flex",
flexDirection: "column",
position: "relative",
top: "25%",
marginLeft: 12,
}}
>
<View style={{ display: "flex", flexDirection: "row" }}>
<CheckBox
value={this.state.useAlpha}
onValueChange={(val) => this.setState({ useAlpha: val })}
></CheckBox>
<Text style={{ color: "#002c3e" }}>Use Alphabets</Text>
</View>
<View
style={{
display: "flex",
flexDirection: "row",
marginTop: 8,
}}
>
<CheckBox
value={this.state.useNum}
onValueChange={(val) => this.setState({ useNum: val })}
></CheckBox>
<Text style={{ color: "#002c3e" }}>Use Numbers</Text>
</View>
<View
style={{
display: "flex",
flexDirection: "row",
marginTop: 8,
}}
>
<CheckBox
value={this.state.useSym}
onValueChange={(val) => this.setState({ useSym: val })}
></CheckBox>
<Text style={{ color: "#002c3e" }}>Use Symbols</Text>
</View>
<View
style={{ display: "flex", flexDirection: "row", marginLeft: 6 }}
>
<Text style={{ color: "#002c3e" }}>Password Length:-</Text>
<Input
containerStyle={{ marginTop: -6, marginRight: 6 }}
keyboardType="numeric"
inputContainerStyle={{
borderBottomWidth: 2,
width: 60,
fontSize: 12,
borderBottomColor: "#002c3e",
}}
style={{ marginBottom: -10, fontSize: 12 }}
value={this.state.passwordLength}
onChangeText={(txt) => this.setState({ passwordLength: txt })}
></Input>
</View>
</View>
I'm trying to implement this type of text input, anyone has an idea to how to implement this ?
You can create a customInput like this, you will have to switch to props, currently I have hardcoded the values
const CustomTextInput = () => {
return (
<View style={{ paddingTop: 10 }}>
<Text
style={{
position: 'absolute',
top: 0,
left: 10,
zIndex: 100,
backgroundColor: 'white',
paddingHorizontal: 20,
}}>
Phone
</Text>
<View
style={{
borderWidth: 1,
borderColor: 'red',
flexDirection: 'row',
borderRadius: 10,
paddingHorizontal:5,
paddingTop: 5,
}}>
<AntDesign
name="star"
size={20}
color="black"
style={{ marginRight: 5 }}
/>
<TextInput value="12313" />
</View>
</View>
);
};
Output would be like
You can change the styles anyway you want.
You can try out the snack here
https://snack.expo.io/#guruparan/custominput
I want to start showing the text inside the picker component from the start without any padding applied. I researched but couldn't find a solution. I'm debugging in android.
My code:
<View style={[styles.pickerContainer]}>
<Picker
selectedValue={this.state.phoneCountryCode}
style={[styles.pickerText(text),{backgroundColor:'transparent', width: 80 }]}
itemStyle={{padding:0, backgroundColor:'yellow'}}
mode="dropdown"
onValueChange={(itemValue, itemIndex) =>
this.setState({ phoneCountryCode: itemValue })
}>
{Constants.CountryCodes.map((item, index) => (
<Picker.Item key={item} label={item.label} value={item.value} />
))}
</Picker>
</View>
Style:
pickerContainer:{
marginTop: 10,
position: 'absolute', left:0, bottom:0, zIndex:10,
},
pickerText:(text)=>({
color:'gray',
height: 40,
textAlign: 'left',
padding:0,
margin: 0,
}),
I had same issue with Picker component, it's quite tricky to style it correctly, I'm leaving some of my findings.
use negative marginLeft to remove padding on the left.
use width and wrapper view to manage padding on right.
use height to fix vertical padding.
Just in case you can afford one dependency check some third-party components like
this
it's highly customizable
PS: You may have figured it by now, but I'm still leaving a remark for anyone else.
Disclaimer: Works for Android and I do not know if it works for IOS.
In my case it was sufficient to set margin to -16 (as padding is set to 16 for picker) and to wrap picker into view with following things set in style: overflow: 'hidden', justifyContent: 'center', display: 'flex'.
Now it is possible to set up padding by setting up padding on view. BTW setting height on view also works for picker.
<View
style={{
width: '70%',
borderStyle: 'solid',
borderWidth: 1,
borderColor: 'black',
height: 20,
padding: 6,
overflow: 'hidden',
justifyContent: 'center',
display: 'flex',
}}>
<Picker
mode="dropdown"
style={{
backgroundColor: 'yellow',
margin: -16,
}}
onValueChange={(itemValue, itemIndex) => {}}>
<Picker.Item label="Java" value="java" style={{fontSize: 10}} />
<Picker.Item label="JavaScript" value="js" style={{fontSize: 10}} />
</Picker>
</View>
I am new to react native.
I have used a Flat Grid and I want to access a Image component on click event. I want to update its image and I am unable to access that image tag.
On click of gird item I want to update image src.
Scenario :-
I have got list of recipes and on click of these I want show them selected by making the Icon to tick.
below is Flat Grid I have used.
<FlatGrid
itemDimension={130}
items={this.state.recipie_listing}
renderItem={({ item, index }) => (
<TouchableOpacity
onPress={() => this.AddRecipe(index, item.id)}>
<View>
<ImageBackground
style={{
height: 250,
width: "100%"
}}
imageStyle={{ borderRadius: 10 }}
source={{
uri: item.image
}}
>
<Icon
name={this.state.icon_name}
style={{
color: this.state.icon_color,
position: "absolute",
right: 2,
top: 2
}}
/>
<View
style={{
backgroundColor: "rgba(220, 222, 224, 0.8)",
height: 60,
width: "100%",
borderBottomEndRadius: 10,
borderBottomStartRadius: 10,
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
position: "absolute",
bottom: 0
}}
>
<CustomText
style={{
marginStart: 10,
marginEnd: 5,
color: "white",
fontSize: 15,
fontWeight: "bold"
}}
>
{item.name}
</CustomText>
</View>
</ImageBackground>
</View>
</TouchableOpacity>
)}
/>
At first, add a state variable like showImage to false and then
In AddRecipe method call the setState method and toggle the variable value and then where you want to load the image src add conditional rendering
here is a code example
state = { showImage : false}
------
AddRecipe = () =>{
this.setState({
showImage:!this.state.showImage
})
render(){
return(
----------
<ImageBackground
style={{
height: 250,
width: "100%"
}}
imageStyle={{ borderRadius: 10 }}
source={{
uri: this.state.showImage === true ? src1 : src2
}}
>
----------
)
}
I think that will help you as far as I understand your problem.
I have made a simple view with a background image and some icons on top of it. Clicking on icons navigate to different pages. It is working fine. Problem is when I navigate to other pages come back to home page and do this for 7-8 times the background image just disappears from all the screens. Below is the code of home screen and Screenshots
<Image
source={require('../images/background.jpg')}
style={{
justifyContent:'center',
resizeMode: "stretch",
height: height,
width: width,
alignItems: "center"
}} >
<StatusBar
backgroundColor="#4e0870"
barStyle="light-content"
/>
<Image style={{ height: 125, width: 125 }} source={require('../images/guru_logo.png')} />
<View style={{
marginTop: 30,
flexDirection: 'row'
}}>
<TouchableOpacity activeOpacity={.5} onPress={() => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
navigate("LiveTV")
}
}
>
<Image
source={require('../images/live.png')}
style={{
resizeMode: "stretch",
height: 75,
width: 75
}} /></TouchableOpacity>
<TouchableOpacity activeOpacity={.5} onPress={() => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
navigate("VideoPage")
}}>
<Image
source={require('../images/youtube.png')}
style={{
marginTop: 5,
resizeMode: "stretch",
marginLeft: 100,
height: 75,
width: 75
}} />
</TouchableOpacity>
</View>
<View
style={{
flexDirection: 'row',
marginTop: 20
}}>
<Text
style={{
marginLeft: -5,
fontSize: 20,
color: "#FFF"
}}>Live Tv</Text>
<Text
style={{
fontSize: 20,
color: "#FFF",
marginLeft: 125
}}>Video</Text>
</View>
<View
style={{
flexDirection: 'row',
marginTop: 20
}}>
<TouchableOpacity activeOpacity={.5} onPress={() => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
navigate("FacebookPage")
}}>
<Image
source={require('../images/facebook-logo.png')}
style={{
resizeMode: "stretch",
height: 75,
width: 75
}} /></TouchableOpacity>
<TouchableOpacity activeOpacity={.5} onPress={() => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
navigate("AudioPage")
}}>
<Image
source={require('../images/icon.png')}
style={{
resizeMode: "stretch",
marginLeft: 100,
height: 75,
width: 75
}} /></TouchableOpacity>
</View>
<View
style={{
flexDirection: 'row',
marginTop: 20
}}>
<Text
style={{
marginLeft: -20,
fontSize: 20,
color: "#FFF"
}}>Facebook</Text>
<Text
style={{
fontSize: 20,
color: "#FFF",
marginLeft: 110
}}>Audio</Text>
</View>
<TouchableOpacity activeOpacity={.5} onPress={() => {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
navigate("ContactPage")
}}>
<Image
source={require('../images/contact.png')}
style={{
marginTop: 20,
resizeMode: "stretch",
height: 75,
width: 75
}} /></TouchableOpacity>
<Text style={{
fontSize: 20,
color: "#FFF"
}}>Contact Us</Text>
</Image>
Every time you navigate to that screen, it calls a re-render. I work around i've found in the past is to define your image sources as a variable, and simply reference it in the source = {HERE} section. I've provided some sample code below. This has fixed this issue in the past, let me know how it goes.
var images = {
live: {img: require('../images/live.png')},
guru: {img: require('../images/guru_logo.png')},
background: {img: require('../images/background.jpg')},
//and so on
}
class SelectionScreen extends Component {
//all your other code
and then in your Image components
<Image source = {images[background].img}.../>
I think it could be related to this react-native issue: https://github.com/facebook/react-native/issues/13600
I would try to:
Run the app on different phones / emulators to see if it depends on
device specifications (like RAM and others). If the app is for both Android and iOS I would also try to see if it's same behaviour on both platforms;
Replace temporary the images with some other smaller/larger images to see if it changes somehow the issue;
Upgrade React Native if necessary and use BackgroundImage component for background images instead of Image.