Expo App on Android device some onPress() not firing - react-native

Several issues are happening here:
Only the delete icon fires onPress()
I've tried different nesting of JSX components to get the update icon to fire with no luck
If it matters, for some reason the 'back' arrow in the StackNavigator on this same page doesn't work either.
This code works perfectly on AVD and IOS simulator
The alpha effect of the TouchableOpacity component isn't being rendered
I've googled extensively, and the only similar problem has to with absolute positioning the TouchableOpacity component, which isn't my case.
I've also tried to onPress = {() Alert('click')} and nothing happened on the Android device.
return (
<View style={styles.container}>
<View style={styles.detailsPanel}>
{/* first row */}
<View style={styles.rowContainer}>
<View style={styles.firstColumn}>
<AppText size={16} color={STYLES.blue} weight='bold'>
{route.params.item.date}
</AppText>
</View>
<View style={styles.secondColumn}>
<View style={{ flex: 1, flexDirection: "row" }}>
<AppText size={16} color={STYLES.blue} weight='bold'>
{route.params.item.aircraft_type}
</AppText>
<AppText>{" "}</AppText>
<AppText size={16} color={STYLES.blue} weight='bold'>
{route.params.item.registration}
</AppText>
</View>
</View>
<View style={styles.thirdColumn}>
<AppText size={16} color={STYLES.blue} weight='bold'>
{route.params.item.duration}
</AppText>
</View>
</View>
{/* second row */}
<Separator />
<View style={styles.rowContainer}>
<View style={styles.firstColumn}>
<AppText size={16} color={STYLES.black}>
{route.params.item.route}
</AppText>
</View>
<View style={styles.thirdColumn}>
<AppText size={16} color={STYLES.black}>
{route.params.item.pilot_in_command ? "PIC" : ""}
{route.params.item.second_in_command ? "SIC" : ""}
{route.params.item.solo ? "Solo" : ""}
{route.params.item.dual ? "Dual" : ""}
</AppText>
</View>
</View>
{/* third row */}
<View style={styles.rowContainer}>
<View style={styles.firstColumn}>
<View style={styles.rowContainer}>
<AppText size={16} color={STYLES.black}>
Landings:
</AppText>
{route.params.item.landings_day ? (
<AppText size={16} color={STYLES.black}>
{" "}
Day {route.params.item.landings_day}
</AppText>
) : null}
{route.params.item.landings_night ? (
<AppText size={16} color={STYLES.black}>
{" "}
Night {route.params.item.landings_night}
</AppText>
) : null}
</View>
</View>
<View style={styles.secondColumn}></View>
<View style={styles.thirdColumn}>
<AppText size={16} color={STYLES.black}>
{route.params.item.instructor ? " CFI" : ""}
</AppText>
</View>
</View>
{/* fourth row */}
<View style={styles.rowContainer}>
<View style={styles.firstColumn}>
<View style={styles.rowContainer}>
{route.params.item.night ? (
<AppText size={16} color={STYLES.black}>
Night {route.params.item.night}
{" "}
</AppText>
) : null}
{route.params.item.instrument ? (
<AppText size={16} color={STYLES.black}>
Inst {route.params.item.instrument}
{" "}
</AppText>
) : null}
{route.params.item.simulated_instrument ? (
<AppText size={16} color={STYLES.black}>
Hood {route.params.item.simulated_instrument}
{" "}
</AppText>
) : null}
</View>
</View>
<View style={styles.thirdColumn}>
<AppText size={16} color={STYLES.black}>
{route.params.item.cross_country ? "XC" : ""}
{route.params.item.simulator ? " Sim" : ""}
</AppText>
</View>
</View>
<View style={styles.rowContainer}>
<View style={styles.firstColumn}>
<View style={styles.rowContainer}>
{approaches.map((appr, index) => (
<AppText size={16} color={STYLES.black} key={index}>
{appr.approach_type}-{appr.number}{" "}
</AppText>
))}
</View>
</View>
<View style={styles.thirdColumn}>
{route.params.item.hold ? <AppText size={16}>Hold</AppText> : null}
</View>
</View>
{/* fifth row */}
<View style={styles.rowContainer}>
<View style={styles.firstColumn}>
<AppText>{route.params.item.remarks}</AppText>
</View>
</View>
{/* sixth row */}
<Separator />
<View style={{ flexDirection: "row", marginBottom: 5 }}>
<TouchableOpacity
style={{
flex: 2,
backgroundColor: STYLES.danger,
alignItems: "center",
justifyContent: "center",
}}
onPress={() => {
showAlert(
route.params.item.id,
route.params.item.date,
route.params.item.route
);
}}
>
<View>
<MaterialCommunityIcons
name={"delete"}
size={30}
color={STYLES.white}
/>
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
navigation.navigate("FlightUpdate", {
item: route.params.item,
});
}}
style={{
flex: 2,
backgroundColor: STYLES.blue,
alignItems: "center",
justifyContent: "center",
}}
>
<View>
<MaterialCommunityIcons
name={"update"}
size={30}
color={STYLES.white}
style={{ padding: 5 }}
/>
</View>
</TouchableOpacity>
</View>
</View>
<MapView
style={styles.map}
mapPadding={{
top: 60,
bottom: 10,
right: 40,
left: 40,
}}
ref={mapRef}
>
{markers.map((marker) => (
<Marker
key={marker.key}
coordinate={marker.coordinates}
title={marker.title}
/>
))}
<Polyline
strokeColor={STYLES.blue}
strokeWidth={3}
geodesic={true}
coordinates={polylines}
/>
</MapView>
<ActivityModal visible={Context.activityVisibleValue}></ActivityModal>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: "column",
},
detailsPanel: {
flexDirection: "column",
width: "100%",
margin: 0,
backgroundColor: STYLES.white,
borderRadius: STYLES.borderRadius,
padding: STYLES.borderRadius,
backgroundColor: STYLES.white,
borderRadius: STYLES.borderRadius,
},
rowContainer: {
flexDirection: "row",
paddingBottom: 5,
},
firstColumn: {
flex: 1,
flexDirection: "column",
},
secondColumn: {
flex: 2,
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
},
thirdColumn: {
flex: 1,
flexDirection: "column",
alignItems: "flex-end",
},
text: {
fontFamily: STYLES.font,
color: STYLES.blue,
},
map: {
flex: 1,
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
borderRadius: STYLES.borderRadius,
},
});```

As you're using Expo and React Navigation, I expected that react-native-gesture-handler package is already installed.
Try to import any touchable component ( TouchableOpacity or TouchableHighlight) from react-native-gesture-handler in place of react-native
import {TouchableOpacity, TouchableHighlight} from "react-native-gesture-handler"
Make sure that your code is not wrapped inside any modal component or Bottom Sheet.
Some of those modals wrapped child components inside another touchable component which blocks touch events to propagate to nested children components.

I had the same issue. I would recommend importing {ScrollView, TouchableOpacity} from react-native, not react-native-gesture-handler; Worked for me; Expo Version 45

Related

How to rotate Fontisto icon in react native

I Import Fontisto import { Fontisto } from "#expo/vector-icons";
Add an Icon <Fontisto style={styles.windDirectionArrow} name='arrow-up' />
and the styling to rotate it
const styles = StyleSheet.create({
windDirectionArrow: {
fontSize: 40,
transform: [{ rotate: "90deg" }],
},
});
But the transform is not working, does anyone know any other solutions for this?
The view I am rendering looks like this
return (
<View style={styles.container}>
{error ? (
<View style={styles.centeredContainer}>
<Text style={styles.text}>Unable to load weather data</Text>
<Text style={styles.text}>{error}</Text>
</View>
) : isLoading ? (
<View style={styles.centeredContainer}>
<Text style={styles.text}>Loading Weather Data</Text>
<ActivityIndicator
style={styles.activityIndicator}
size='large'
color='rgb(255,179,25)'
/>
</View>
) : (
<View style={[styles.centeredContainer]}>
<Fontisto style={styles.text} name={icon} />
<Text style={styles.text}>{temperature}˚C</Text>
<Text style={styles.text}>
<Fontisto name='arrow-up' style={styles.windDirectionArrow} />
{windSpeed}mph
</Text>
<Text style={styles.text}>{weatherCondition}</Text>
</View>
)}
</View>
);
It works if I have the Icon element wrapped in its own but I think that is not a clean solution
<Text style={styles.text}>
<View>
<Fontisto name='arrow-up' style={styles.windDirectionArrow} />
</View>
{windSpeed}mph
</Text>
It works perfectly for me
// With Rotation
<Fontisto name="arrow-up" style={styles.windDirectionArrow} />
// Without Rotation
<Fontisto name="arrow-up" style={styles.withoutRottion} />
// When icon is wrapped inside a View and that View is rotated
<View style={styles.windDirectionArrow}>
<Fontisto name="arrow-up" style={{ fontSize: 40 }} />
</View>
My Styles :
windDirectionArrow: {
fontSize: 40,
transform: [{ rotate: '90deg' }],
},
withoutRottion: {
fontSize: 40,
},
Working Example
And also why don't you use arrow-right from Fontisto
And for Text Side by side
<View style={{ justifyContent: 'center', alignItems: 'center', flexDirection: 'row' }}>
<View style={styles.windDirectionArrow}>
<Fontisto name="arrow-up" style={{ fontSize: 40 }} />
</View>
<Text style={styles.text}>{windSpeed}mph</Text>
</View>

navigate screen overlaying with other screen

hello I am new to react native I am facing an abnormal behavior on navigation which happens between two modal screens first modal screen as shown in the picture on navigate it goes into next screen works fine
here is second modal picture on navigate
problem comes when I press on div upload cnic picture front and back then screens getting merged both are different component , previous screen modal appear as you seen in photo I marked in the screen with two modal screens
here is my CNIC upload screen code
<TouchableWithoutFeedback
onPress={() => {
displayModal(!modalVisible);
}}>
<View style={styles.container}>
<Modal
onBackdropPress={() => setModalVisible(false)}
onSwipeComplete={() => setModalVisible(false)}
swipeDirection={['down']}
useNativeDriverForBackdrop
style={{margin: 0}}
isVisible={modalVisible}>
<View
style={{
flex: 1,
borderTopLeftRadius: 25,
borderTopRightRadius: 25,
marginTop:
steper === 'step' ? deviceHeight * 0.1 : deviceHeight * 0.2,
backgroundColor: 'white',
alignItems: 'center',
}}>
<View
style={{
width: '100%',
height: '100%',
// alignItems: 'center',
marginTop: 3,
justifyContent: 'space-evenly',
}}>
<View style={{width: '100%', alignItems: 'center'}}>
<PopupBorder />
</View>
{/* first half */}
<View
style={{
width: '100%',
alignItems: 'center',
height: '18%',
justifyContent: 'flex-end',
}}>
<View style={styles.subContainer}>
<Image
style={{width: '40%', height: '50%', resizeMode: 'contain'}}
source={require('../assests/finger-print.png')}
/>
<Text style={{fontSize: 18}}>Verify your account </Text>
<SubTitle
amount
color="#636363"
title="We require CNIC and Selfie for the verification"
/>
</View>
</View>
{/* steper */}
<View
style={{
height: '10%',
justifyContent: 'center',
}}>
<DocumentSteper step={steper} />
</View>
{/* steper */}
{/* second half */}
<View
style={{
width: '100%',
height: '70%',
alignItems: 'center',
justifyContent: 'center',
}}>
<View style={styles.subContainer}>
<TouchableOpacity
style={{
width: '100%',
height: '80%',
alignItems: 'center',
}}>
{steper === 'step' ? (
<>
<TouchableOpacity
activeOpacity={0.6}
onPress={takeFrontPhotoFromCamera}
style={styles.imageContainer}>
<ImageBackground
style={styles.uploadStyle}
// resizeMode="contain"
source={
frontImage === null ? null : {uri: frontImage}
}>
<Image source={require('../assests/upload.png')} />
<View style={{paddingTop: 5}}>
<SubTitle
title="CNIC FRONT"
font
color="#06B2BC"
fontSize={14}
amount
/>
</View>
</ImageBackground>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={1}
onPress={takeBackFrontPhotoFromCamera}
style={styles.imageContainer}>
<ImageBackground
style={styles.uploadStyle}
// resizeMode="contain"
source={
backImage === null ? null : {uri: backImage}
}>
<Image source={require('../assests/upload.png')} />
<View style={{paddingTop: 5}}>
<SubTitle
title="CNIC FRONT"
font
color="#06B2BC"
fontSize={14}
amount
/>
</View>
</ImageBackground>
</TouchableOpacity>
</>
) : (
<TouchableOpacity
onPress={takeSelfie}
style={styles.singleimageContainer}>
<ImageBackground
style={styles.uploadStyle}
// resizeMode="contain"
source={selfie === null ? null : {uri: selfie}}>
<Image source={require('../assests/upload.png')} />
<View style={{paddingTop: 5}}>
<SubTitle
title="CNIC FRONT"
font
color="#06B2BC"
fontSize={14}
amount
/>
</View>
</ImageBackground>
</TouchableOpacity>
)}
</TouchableOpacity>
<View
style={{
width: '100%',
height: '20%',
justifyContent: 'flex-end',
}}>
<Button
click={verify}
title={
steper === 'step' ? ' Verify CNIC' : 'Verify SELFIE'
}
backgroundColor="white"
marginBottom={15}
color="#06B2BC"
/>
</View>
</View>
</View>
</View>
</View>
</Modal>
<TouchableWithoutFeedback onPress={() => !modalVisible}>
<TouchableOpacity style={styles.map}>
<Image source={require('../assests/map.png')} />
</TouchableOpacity>
</TouchableWithoutFeedback>
</View>
</TouchableWithoutFeedback>
We can't see from your code sample where you are calling the second step "upload cnic picture". It seems that you are calling another modal on top of the first one.
If you have planned to have a full process within this modal, it is probably best to integrate a proper navigator rather than "navigate" between modals.

ImageBackground not showing image on some devices

I am trying to use a CustomCallout with a ImageBackground in it. I notice a really strange behavior when testing the application on two different devices (both Android). The image is showed correctly on the older device with lower display, but on the new device (p30 lite) the image is not appearing.. any ideas? here is my code:
class CustomCallout extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.calloutStyle}>
<View>
<View style={{ ...styles.placeRow, ...styles.placeHeader }}>
<ImageBackground
source={{ uri: this.props.image }}
style={styles.bgImage}
>
<View style={styles.titleContainer}>
<Text style={styles.title} numberOfLines={1}>
{this.props.placeName}
</Text>
</View>
</ImageBackground>
</View>
<View style={{ ...styles.placeRow, ...styles.placeDetail }}>
<Text>{this.props.distance}m</Text>
<Text>{this.getPlaceType(this.props.placeType)}</Text>
</View>
<View style={{ ...styles.placeRow, ...styles.placeRating }}>
<StarRating
disabled={false}
emptyStar={'ios-star-outline'}
fullStar={'ios-star'}
halfStar={'ios-star-half'}
iconSet={'Ionicons'}
maxStars={7}
rating={4}
fullStarColor={'#FDCC0D'}
starSize={20}
/>
</View>
</View>
</View>
);
}
}
CustomCallout.propTypes = propTypes;
const styles = StyleSheet.create({
calloutStyle: {
height: 200,
width: 280,
backgroundColor: '#61adc8',
shadowOffset: { width: 0, height: 2},
shadowRadius: 6,
shadowOpacity: 0.26,
elevation: 55,
padding: 12,
borderRadius: 20,
shadowColor: 'black',
overflow: 'hidden'
},
bgImage: {
width: '100%',
height: '100%',
justifyContent: 'flex-end',
},
placeRow: {
flexDirection: 'row'
},
placeHeader: {
height: '80%'
},
placeDetail: {
justifyContent: 'space-between',
height: '10%'
},
placeRating: {
height: '10%',
justifyContent:'flex-start',
},
titleContainer: {
backgroundColor: 'rgba(0,0,0,0.5)',
shadowOffset: { width: 0, height: 2},
shadowRadius: 6,
shadowOpacity: 0.26,
elevation: 55,
borderRadius: 10,
alignItems: 'center'
},
title: {
color: 'white',
fontSize: 20
}
});
export default CustomCallout;
We cant put ImageBackground wherever we want.. I don't know the exact theory. But Just put the ImageBackgroung tag outside the view and try to even put on different views too.. If anyone know plz correct me. Here is a working example.
Put ImageBackground to entire component
render() {
return (
<View style={styles.calloutStyle}>
<View>
<ImageBackground
source={{ uri: 'https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg' }}
style={styles.bgImage}
>
<View style={{ ...styles.placeRow, ...styles.placeHeader }}>
<View style={styles.titleContainer}>
<Text style={styles.title} numberOfLines={1}>
{this.props.placeName}
</Text>
</View>
</View>
</ImageBackground>
<View style={{ ...styles.placeRow, ...styles.placeDetail }}>
<Text>{this.props.distance}m</Text>
<Text>{this.getPlaceType(this.props.placeType)}</Text>
</View>
<View style={{ ...styles.placeRow, ...styles.placeRating }}>
<StarRating
disabled={false}
emptyStar={'ios-star-outline'}
fullStar={'ios-star'}
halfStar={'ios-star-half'}
iconSet={'Ionicons'}
maxStars={7}
rating={4}
fullStarColor={'#FDCC0D'}
starSize={20}
/>
</View>
</View>
</View>
);
}
}
Or you can put to only both components
render() {
return (
<View style={styles.calloutStyle}>
<View>
<ImageBackground
source={{ uri: 'https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg' }}
style={styles.bgImage}
>
<View style={{ ...styles.placeRow, ...styles.placeHeader }}>
<View style={styles.titleContainer}>
<Text style={styles.title} numberOfLines={1}>
{this.props.placeName}
</Text>
</View>
</View>
<View style={{ ...styles.placeRow, ...styles.placeDetail }}>
<Text>{this.props.distance}m</Text>
<Text>{this.getPlaceType(this.props.placeType)}</Text>
</View>
<View style={{ ...styles.placeRow, ...styles.placeRating }}>
<StarRating
disabled={false}
emptyStar={'ios-star-outline'}
fullStar={'ios-star'}
halfStar={'ios-star-half'}
iconSet={'Ionicons'}
maxStars={7}
rating={4}
fullStarColor={'#FDCC0D'}
starSize={20}
/>
</View>
</ImageBackground>
</View>
</View>
);
}
}
or put ImageBackground to inside view only
render() {
return (
<View style={styles.calloutStyle}>
<View>
<ImageBackground
source={{ uri: 'https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg' }}
style={styles.bgImage}
>
<View style={{ ...styles.placeRow, ...styles.placeHeader }}>
<View style={styles.titleContainer}>
<Text style={styles.title} numberOfLines={1}>
{this.props.placeName}
</Text>
</View>
</View>
</ImageBackground>
<View style={{ ...styles.placeRow, ...styles.placeDetail }}>
<Text>{this.props.distance}m</Text>
<Text>{this.getPlaceType(this.props.placeType)}</Text>
</View>
<View style={{ ...styles.placeRow, ...styles.placeRating }}>
<StarRating
disabled={false}
emptyStar={'ios-star-outline'}
fullStar={'ios-star'}
halfStar={'ios-star-half'}
iconSet={'Ionicons'}
maxStars={7}
rating={4}
fullStarColor={'#FDCC0D'}
starSize={20}
/>
</View>
</View>
</View>
);
}
}
Try this out and let me know the result.. :)

Invariant violation: Text strings must be rendered within a <Text> component React native

I basically copied the ingredients portion which works and am trying to duplicate it with the tag section. I get error on line that says
<View style={styles.section}>
which is opening view container for the tag section. Everything is identical to the ingredients section so in my mind it should be working.
There is *** on line where error is being flagged just for the sake of finding it easier. Those stars are not actually in my code.
render() {
return (
<View style={{ flex: 1 }}>
<View>
<ActionNavbar title="Add Recipe"
leftAction={this.cancelRecipe}
leftIcon={require("app/assets/icons/cancel.png")}
rightAction={this.saveRecipe}
rightIcon={require("app/assets/icons/check.png")} />
</View>
<ScrollView style={{ flex: 1, maxHeight: this.state.height }} contentContainerStyle={{ paddingBottom: 1000}}>
<View>
<AddImage />
<Input label="Name of Recipe"
value={this.state.name}
onChangeText={name => this.setState({name})}
style={styles.nameInput}/>
<View style={{ width: "100%", flexDirection: "row", justifyContent: "space-evenly", marginTop: 30}}>
<View style={{ alignItems: "center"}}>
<Text style={styles.title}>TOTAL COOK TIME</Text>
<TouchableOpacity onPress={() => {
this.props.navigation.navigate("DurationPicker", {
hours: this.state.hours,
minutes: this.state.minutes,
});
}}>
<View style={styles.secondaryButton}>
<Text style={styles.textStyle}>{this.state.durationLabel}</Text>
</View>
</TouchableOpacity>
</View>
<View style={{ alignItems: "center"}}>
<Text style={styles.title}>Total Servings</Text>
<TouchableOpacity onPress={() => {
this.props.navigation.navigate("ServingsPicker", {
servings: this.state.servings,
});
}}>
<View style={styles.secondaryButton}>
<Text style={styles.textStyle}>{this.state.servingsLabel}</Text>
</View>
</TouchableOpacity>
</View>
</View>
<View style={styles.section}>
<Text style={styles.sectionHeader}>Ingredients</Text>
<Divider style={styles.sectionDivider} />
{
this.state.ingredients.map((ingredient, index) => (
<View style={{ marginBottom: 3, flexDirection: 'row', alignItems: 'center'}} key={'ingredient-' + index}>
<View style={styles.ingredientSize}>
<Text style={{ padding: 10}}>{ingredient.number} {fractionMap[ingredient.fraction]} {ingredient.unitLabel}</Text>
</View>
<Text style={{ fontSize: 18 }}>{ingredient.name}</Text>
<Divider></Divider>
</View>
))
}
<ActionButton icon={require("app/assets/icons/whiteAdd.png")}
text="Add Ingredient"
onPress={() => {
this.props.navigation.navigate("AddIngredients", {
ingredients: this.state.ingredients,
units: this.props.units,
});
}} />
</View>
{
this.state.steps.map((step, index) => (
<View style={styles.section} key={step-${index}}>
<Text style={styles.sectionHeader}>Step {index + 1}</Text>
<Divider style={styles.sectionDivider}/>
<Text>{step}</Text>
</View>
))
}
<View style={styles.section}>
<Text style={styles.sectionHeader}>Step {this.state.steps.length + 1}</Text>
<Divider style={styles.sectionDivider} />
<ActionButton icon={require("app/assets/icons/whiteAdd.png")}
text="Add Step"
onPress={() => {
this.props.navigation.navigate("AddStep", {
ingredients: this.state.ingredients
});
}} />
</View>
<View style={styles.section}>
<Text style={styles.sectionHeader}>Notes</Text>
<Divider style={styles.sectionDivider} />
{
this.state.notes === '' ?
<ActionButton icon={require("app/assets/icons/whiteAdd.png")}
text="Add Note"
onPress={() => {
this.props.navigation.navigate("AddNote", {
note: this.state.note
});
}} /> :
<Text>{this.state.notes}</Text>
}
</View>
***<View style={styles.section}>***
<Text style={styles.sectionHeader}>Tags</Text>
<Divider style={styles.sectionDivider} />
{
this.state.tag.map((tag, index) => (
<View style={{ marginBottom: 3, flexDirection: 'row', alignItems: 'center'}} key={'tag-' + index}>
<Text style={{ fontSize: 18 }}>{ tag }</Text>
<Divider></Divider>
</View>
))
}
<ActionButton icon={require("app/assets/icons/whiteAdd.png")}
text="Add Tag"
onPress={() => {
this.props.navigation.navigate("AddTag", {
tag: this.state.tag
});
}} /> :
<Text>{this.state.tag}</Text>
}
</View>
<View style={{ flexDirection: "row", margin: 10, justifyContent: "center", alignItems: "center" }}>
<Text style={{ flex: 1, fontSize: 16 }}>
Private Recipe?
</Text>
<Switch
value={this.state.isPrivate}
onValueChange={priv => this.setState({ isPrivate : priv })}
/>
</View>
</View>
</ScrollView>
</View>);
}
}
It looks like you have an additional } in your code. I have marked it with <- this shouldn't be here. The reason it is saying that the error is at that line, is because that is where the View opens where the error is contained within.
render () {
return (
<View style={{ flex: 1 }}>
<View>
<ActionNavbar title="Add Recipe"
leftAction={this.cancelRecipe}
leftIcon={require('app/assets/icons/cancel.png')}
rightAction={this.saveRecipe}
rightIcon={require('app/assets/icons/check.png')} />
</View>
<ScrollView style={{ flex: 1, maxHeight: this.state.height }} contentContainerStyle={{ paddingBottom: 1000 }}>
<View>
<AddImage />
<Input label="Name of Recipe"
value={this.state.name}
onChangeText={name => this.setState({ name })}
style={styles.nameInput}/>
<View style={{ width: '100%', flexDirection: 'row', justifyContent: 'space-evenly', marginTop: 30 }}>
<View style={{ alignItems: 'center' }}>
<Text style={styles.title}>TOTAL COOK TIME</Text>
<TouchableOpacity onPress={() => {
this.props.navigation.navigate('DurationPicker', {
hours: this.state.hours,
minutes: this.state.minutes
});
}}>
<View style={styles.secondaryButton}>
<Text style={styles.textStyle}>{this.state.durationLabel}</Text>
</View>
</TouchableOpacity>
</View>
<View style={{ alignItems: 'center' }}>
<Text style={styles.title}>Total Servings</Text>
<TouchableOpacity onPress={() => {
this.props.navigation.navigate('ServingsPicker', {
servings: this.state.servings
});
}}>
<View style={styles.secondaryButton}>
<Text style={styles.textStyle}>{this.state.servingsLabel}</Text>
</View>
</TouchableOpacity>
</View>
</View>
<View style={styles.section}>
<Text style={styles.sectionHeader}>Ingredients</Text>
<Divider style={styles.sectionDivider} />
{
this.state.ingredients.map((ingredient, index) => (
<View style={{ marginBottom: 3, flexDirection: 'row', alignItems: 'center' }} key={'ingredient-' + index}>
<View style={styles.ingredientSize}>
<Text style={{ padding: 10 }}>{ingredient.number} {fractionMap[ingredient.fraction]} {ingredient.unitLabel}</Text>
</View>
<Text style={{ fontSize: 18 }}>{ingredient.name}</Text>
<Divider></Divider>
</View>
))
}
<ActionButton icon={require('app/assets/icons/whiteAdd.png')}
text="Add Ingredient"
onPress={() => {
this.props.navigation.navigate('AddIngredients', {
ingredients: this.state.ingredients,
units: this.props.units
});
}} />
</View>
{
this.state.steps.map((step, index) => (
<View style={styles.section} key={`step-${index}`}>
<Text style={styles.sectionHeader}>Step {index + 1}</Text>
<Divider style={styles.sectionDivider}/>
<Text>{step}</Text>
</View>
))
}
<View style={styles.section}>
<Text style={styles.sectionHeader}>Step {this.state.steps.length + 1}</Text>
<Divider style={styles.sectionDivider} />
<ActionButton icon={require('app/assets/icons/whiteAdd.png')}
text="Add Step"
onPress={() => {
this.props.navigation.navigate('AddStep', {
ingredients: this.state.ingredients
});
}} />
</View>
<View style={styles.section}>
<Text style={styles.sectionHeader}>Notes</Text>
<Divider style={styles.sectionDivider} />
{
this.state.notes === ''
? <ActionButton icon={require('app/assets/icons/whiteAdd.png')}
text="Add Note"
onPress={() => {
this.props.navigation.navigate('AddNote', {
note: this.state.note
});
}} />
: <Text>{this.state.notes}</Text>
}
</View>
***<View style={styles.section}>***
<Text style={styles.sectionHeader}>Tags</Text>
<Divider style={styles.sectionDivider} />
{
this.state.tag.map((tag, index) => (
<View style={{ marginBottom: 3, flexDirection: 'row', alignItems: 'center' }} key={'tag-' + index}>
<Text style={{ fontSize: 18 }}>{ tag }</Text>
<Divider></Divider>
</View>
))
}
<ActionButton icon={require('app/assets/icons/whiteAdd.png')}
text="Add Tag"
onPress={() => {
this.props.navigation.navigate('AddTag', {
tag: this.state.tag
});
}} /> :
<Text>{this.state.tag}</Text>
} <- this shouldn't be here
</View>
<View style={{ flexDirection: 'row', margin: 10, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ flex: 1, fontSize: 16 }}>
Private Recipe?
</Text>
<Switch
value={this.state.isPrivate}
onValueChange={priv => this.setState({ isPrivate: priv })}
/>
</View>
</View>
</ScrollView>
</View>);
}
I suggest you set up linting so that you can catch errors like this.

warning each child in an array or iterator should have a unique key prop. react native

I have build React Native App and I face Problem for "Api" t did not give
me an error but i gives me a warring or Each items should have unique key I
didn't find any solution for how i solve this.
how to I use unique key in function
**
How to fix reactjs warning: each child in an array should have a unique prop…? 2**
<View style={styles.contanier}>
{this.props.data.map(function(videoData, index) {
console.log(videoData, "fetch3");
return (
<View style={styles.card_contanier}>
<TouchableOpacity
style={{ flex: 1 }}
// onPress={() => this.onforward()}
>
<View style={{ height: "45%" }}>
<Image
source={require("../img/special-page-banner.jpg")}
style={{
flex: 1,
width: imageWidth,
resizeMode: "stretch"
}}
/>
</View>
<View style={styles.title}>
<Text
style={{ color: "black" }}
numberOfLines={2}
ellipsizeMode={"tail"}
>
{videoData.name}
</Text>
</View>
<View style={{ height: "20%" }}>
<View style={styles.buttom_contanier}>
<View style={styles.logo}>
<Thumbnail
source={require("../img/andy-sm.png")}
style={{ height: 32, width: 32 }}
/>
</View>
<View style={{ flexDirection: "column" }}>
<View style={{ flexDirection: "row", left: 5 }}>
<Text
style={{ color: "black" }}
numberOfLines={1}
ellipsizeMode={"tail"}
>
{videoData.created_by_user.name}
</Text>
</View>
<View style={styles.iconic_contanier}>
<Icon name="calendar" size={10} style={{ top: 2 }} />
<Text style={styles.text}>10 Oct 2018</Text>
</View>
<View style={styles.iconic_contanier}>
<Icon name="eye" size={10} style={{ top: 2 }} />
<Text style={styles.text}>11 views</Text>
</View>
</View>
</View>
</View>
</TouchableOpacity>
</View>
);
})}
</View>
First and not the recommended approach will be tu use your index you get as second argument in your .map callback
<View style={styles.contanier}>
{this.props.data.map(function(videoData, index) {
console.log(videoData, "fetch3");
return (
<View key={index} style={styles.card_contanier}>
But using index is not recommended. If you have an id coming from your backend I will use it. This can cause problem with animation and thing like that if you use index.
<View style={styles.contanier}>
{this.props.data.map(function(videoData, index) {
console.log(videoData, "fetch3");
return (
<View key={videodata.id} style={styles.card_contanier}>
You can read about all this here https://reactjs.org/docs/lists-and-keys.html#keys
And article here about why not use index https://medium.com/#robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318