Unable to display content inside a SwipeRow - react-native

I am trying to wrap the data present in a list and make the list swipeable using SwipeRow. But after I add the SwipeRow on top of my ListItem tag, the content is not displayed.
I have tried using renderItem but that seems unrelatable and doesn't work.
return(
// <SwipeRow style={{backgroundColor:'red'}}>
//body={
<View style={{backgroundColor: 'red'}}>
<ListItem style={{ width: '100%' }} onPress={() => this.navigationTo(this.props.data.h)}>
<View style={{ marginHorizontal: 15, alignSelf: 'flex-start' }}>
{this.props.data.iconType === 'Material' ? (
<MaterialIcon style={{}} size={24} name={this.props.data.i} color="#87898B" />
) : (
<MaterialCommunityIcons style={{}} size={24} name={this.props.data.i} color="#87898B" />
)}
</View>
<View>
<Text style={styles.heading}>{this.props.data.h}</Text>
<Text style={styles.description}>
{this.props.data.dp}{' '}
<B>
{count} {this.props.data.db}
</B>{' '}
{this.props.data.da}.
</Text>
<Text style={styles.metadata}>{this.props.data.m}</Text>
</View>
</ListItem>
</View>
// }
// </SwipeRow>
);

Probably try giving some styles to SwipeRow assuming you have imported the swipeRow

You can use renderRow in ListView
<ListView
style={{flex: 1, backgroundColor:'red'}}
dataSource={this.props.data}
renderRow={ data => (
<SwipeRow
leftOpenValue={75}
rightOpenValue={-75}
>
<View style={{ marginHorizontal: 15, alignSelf: 'flex-start' }}>
{this.props.data.iconType === 'Material' ? (
<MaterialIcon style={{}} size={24} name={data.i} color="#87898B" />
) : (
<MaterialCommunityIcons style={{}} size={24} name={data.i} color="#87898B" />
)}
</View>
<View>
<Text style={styles.heading}>{data.h}</Text>
<Text style={styles.description}>
{data.dp}{' '}
<B>
{count} {data.db}
</B>{' '}
{data.da}.
</Text>
<Text style={styles.metadata}>{data.m}</Text>
</View>
</SwipeRow>
)}
/>

Related

Define height of AutoComplete list - React Native

The listStyle where I set the height of my list it's not working on Autocomplete.
I'm using react-native-autocomplete-input.
Check the Example:
<HideKeyboard>
<SafeAreaView style={mainStyle.container}>
<StatusBar style="light" backgroundColor="#0a3f88" />
<SimpleLineIcons style={mainStyle.menuIconHome} name="menu" size={28} color="black" onPress={() => {Keyboard.dismiss(), navigation.openDrawer()}}/>
<Image style={mainStyle.logo} source={logo}></Image>
<Autocomplete
style={{
backgroundColor:"transparent",
textAlign:"center",
}}
onChangeText={(text) => searchFilterFunction(text)}
data={filteredDataSource}
placeholder="Nome da empresa..."
autoFocus={true}
listStyle={{
maxHeight:20,
}}
containerStyle={{
paddingHorizontal:40,
position:"absolute",
top:"45%",
alignSelf:"center",
}}
inputContainerStyle={{
height:40,
zIndex:999,
}}
flatListProps={{
keyExtractor: (item, index) => index.toString(),
renderItem: ({ item }) =>
<TouchableOpacity
onPress={()=>{
navigation.navigate("Projeto",{
item:item,
});
}}
>
<View style={{
height:50,
borderBottomWidth:0.4,
}}>
<Text style={{
color:"#0a3f88",
fontWeight:"bold",
marginLeft:10,
}}>{item}</Text>
</View>
</TouchableOpacity>
}}
/>
<Image style={mainStyle.cmlagos} source={camaraLagos}></Image>
</SafeAreaView>
</HideKeyboard>
As you can see in the prinscreen below , the listStyle have no effect.
Already tried to use ScrollView outside of the Autocomplete but it's the same.
Any suggestions ?
Solved!
Instead of use the listStyle, we can use style:{height: 150} inside of flatListProps.

React-native Modal component animation

Is there any way to make Modal appear from left to right?
Right now I have this and its only sliding from bottom to top:
<Modal animationType={'slide'} visible={showModal}>
<View
style={{
backgroundColor: 'blue',
width: Dimensions.get('screen').width,
height: Dimensions.get('screen').height,
}}>
<TouchableOpacity onPress={() => setShowModal(false)}>
<Feather name="menu" size={40} color="red" />
</TouchableOpacity>
</View>
</Modal>
You can use npm i react-native-modal to get your desired result.
<Modal
animationIn="slideInLeft"
animationOut="slideOutRight"
animationInTiming={500}
animationOutTiming={750}
isVisible={showModal}
useNativeDriver={true}
onBackButtonPress={() => {
setShowModal(!showModal);
}}>
<View
style={{
backgroundColor: 'blue',
width: Dimensions.get('screen').width,
height: Dimensions.get('screen').height,
}}>
<TouchableOpacity onPress={() => setShowModal(false)}>
<Feather name="menu" size={40} color="red" />
</TouchableOpacity>
</View>
</Modal>

Placement of text and toggle button

I want to place a text and a toggle button in such a manner that the Text should be there at flex-start and the toggle would be there at the flex end. I have come up with the following code :
<TouchableRipple onPress={() => { }}>
<View style={{flexDirection: 'row'}}>
<Text style={{ fontSize: 18, fontWeight: "bold" }}>
<FontAwesome5 name="bookmark" size={16} /> Booked
</Text>
<View pointerEvents="none" style={{justifyContent: "flex-end"}}>
<Switch value={true} />
</View>
</View>
</TouchableRipple>
But the view is coming as follows:
How can I put the same at the end ?
Any help would be appritiated.
Here try this
<TouchableRipple onPress={() => { }}>
<View style={{flexDirection: 'row'}}>
<View style={{flex:1}}> //wrap Text inside view with flex 1
<Text style={{ fontSize: 18, fontWeight: "bold" }}>
<FontAwesome5 name="bookmark" size={16} /> Booked
</Text>
</View>
<View pointerEvents="none" style={{flex:1,justifyContent: "flex-end"}}> //add flex 1 here
<Switch value={true} />
</View>
</View>
</TouchableRipple>

Scrollview inside another view does not works in react native

render() {
return (
<View style ={styles.container}>
{/*for header*/}
<View style = {{flexDirection:'row',justifyContent:'space-between',alignItems: 'center',width:'100%',height:'09%',backgroundColor: '#009AFF'}}>
<TouchableWithoutFeedback onPress={() =>this.props.navigation.goBack()}>
<Image style={{width: 25, height: 25,margin:10}} source={require('../assets/clinic/left-arrow.png')} />
</TouchableWithoutFeedback>
<View>
<Text style={{fontSize: 21,fontWeight: 'bold', color: "white",paddingRight:25}}>Dummy</Text>
</View>
<View>
</View>
</View>
{/*for main content*/}
<ScrollView style={{width:'100%',height:'90%'}} contentContainerStyle={{ flexGrow: 1 }} nestedScrollEnabled={true}>
<View>
<View style = {{width:'100%',height:'45%',backgroundColor: '#009AFF',justifyContent:'center',alignItems: 'center'}}>
<Text style={{fontSize: 18,fontWeight: 'bold', color: "white",paddingRight:25}}>John Alison</Text>
</View>
<TouchableOpacity
style={styles.submitButton}>
<Text style={styles.submitText}>Update</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.submitButton}>
<Text style={styles.submitText}>Update</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.submitButton}>
<Text style={styles.submitText}>Update</Text>
</TouchableOpacity>
</View>
</ScrollView>
</View>
)
}
Above code i have implemented in react native for learning purposes.But in above code ScrollView does not works,means it does not scrolls,why? i have tried many possible ways like setting flex and flexGrow equal to 1,enabling nested scrolling but it does not works.What is wrong with my code

onPress not working in nested views

I'm using TouchableOpacity for handling clicks.Everything is working fine in upper hierarchy views, but bellow two containers view is not clickable.I've set an alert when it's clicked for testing purposes.View bellow comment is not working and I think it's because of bad nesting.
Here is code :
return (
<View style={styles.container}>
<View style={styles.subContainer}>
<Text style={[styles.storyLikesAndShares, { marginRight: 17 }]}>
{this.state.likes} Likes
</Text>
<Text style={styles.storyLikesAndShares}>
{this.props.story.Shares ? this.props.story.Shares : 0} Shares
</Text>
</View>
<View style={[styles.subContainer, { paddingTop: 16 }]}>
<View style={styles.storyIconsContainer}>
<TouchableOpacity onPress={() => this.changeLikedState(this.props)}>
<Icon
style={[
this.props.story && this.state.isLiked
? styles.storyLikedIcon
: styles.storyNotLikedIcon,
{ marginRight: 24 }
]}
name={"heart"}
size={24}
/>
</TouchableOpacity>
<Icon style={styles.storyNotLikedIcon} name={"share"} size={24} />
//Code bellow is not working
<TouchableOpacity
onPress={() => alert('alertiiiing')}
>
{this.props.storyViewType === "feed" ? (
<Text
onPress={() => console.log('read more clicked')}
style={styles.storyReadMoreText}>Read Full Story...</Text>
) : (
<View />
)}
</TouchableOpacity>
</View>
</View>
</View>
);
}
}