react-native add '...' on the right of card to show more information - react-native

I'm trying to add the 3 littles dots on the right of a card to show more information on click but cannot find how this is called.
On android it is called ""overflow menu" but the only component using overflow I found is "toolbarAndroid". I cannot use it because i work on Android & IOS.
Did you know how to do this ?
Actually i'm using "react-native-elements" for the card but they don't provide this option.
Maybe i have to create a component for that
My actual code, not using "title" props of card because i don't want to display the divider line.
renderProject(project) {
const { id, name, description, species, images } = project;
return (
<Card containerStyle={thisstyles.cardContainerStyle} key={id}>
<View>
<Text style={thisstyles.projectName}>{name}</Text>
</View>
<View style={{marginLeft:15}}>
<Text style={{color:'mediumvioletred'}}>{description}</Text>
<Text>
{species} Espèces {images} Images
</Text>
</View>
</Card>
);
}

As you have used custom component just add Image to show triple dots.
<View>
<Text style={thisstyles.projectName}>{name}</Text>
<Image style={position: 'absolute', right: 0}
source={require('../../path/to/image')} />
</View>
In your given module react-native-elements,
<Card
title='HELLO WORLD'
image={require('../images/pic2.jpg')}> // you can play around with this

You can Crate Your component Like this without any image
import React, {Component} from 'react';
import {View,TouchableOpacity} from 'react-native';
import {Text,Header,CardItem} from 'native-base';
class CardExample extends Component{
_renderSearchResult(){
return(
<View>
<CardItem style={styles.cardView}>
<View style={{flex:1}}>
<View style={styles.locationRowContainer}>
<View style={styles.addressContainer}>
<Text style={styles.locationText}>
My current location
</Text>
</View>
<TouchableOpacity onPress={()=>{alert('You cliked me')}}>
<View>
<View style={styles.circleDot}>
</View>
<View style={styles.circleDot}>
</View>
<View style={styles.circleDot}>
</View>
</View>
</TouchableOpacity>
</View>
</View>
</CardItem>
<CardItem style={styles.cardView}>
<View style={{flex:1}}>
<View style={styles.locationRowContainer}>
<View style={styles.addressContainer}>
<Text style={styles.locationText}>
My current location
</Text>
</View>
<TouchableOpacity onPress={()=>{alert('You cliked me')}}>
<View>
<View style={styles.circleDot}>
</View>
<View style={styles.circleDot}>
</View>
<View style={styles.circleDot}>
</View>
</View>
</TouchableOpacity>
</View>
</View>
</CardItem>
</View>
)
}
render(){
return(
<View style={styles.container}>
{this._renderSearchResult()}
</View>
)
}
}
const styles={
container:{
flex:1,
},
cardView:{
elevation:5,
marginTop:8,
},
locationRowContainer:{
flexDirection:'row',
marginTop:21,
},
addressContainer:{
flex:3,
justifyContent:'center',
alignItems:'flex-start'
},
locationText:{
fontSize:16,
color:'black'
},
circleDot:{
backgroundColor:'black',
height:6,
width:6,
borderRadius:6/2,
marginBottom:2,
},
mapLocationContainer:{
flex:1,
justifyContent:'center',
alignItems:'flex-end'
}
}
export default CardExample;

Related

React Native RenderItem not working with custom renderItem

I created a custom renderItem using the React Native documentation as an example and it is not working, however, when using a simple component (commented in the script), it is working perfectly. I have tried to change some things around, but I can't make it work.
For the flatlist, I based my code on the react native example at https://reactnative.dev/docs/flatlist, using the flat-list-simple example, calling the function in the render item as renderItem={Function} but react-native does not recognize it, I appreciate any guidance on what I could change or if I am doing the whole thing wrong, thank you!
import { StyleSheet, Text, View, TouchableOpacity, FlatList } from 'react-native'
import React from 'react'
import Ionicons from 'react-native-vector-icons/Ionicons';
import VisitasHeader from './VisitasHeader';
const VisitasCard = ({visitas,titulo}) => {
// renderItem for FlatList
const CardFunction = (item) => {
<View style={{marginBottom:10}}>
<View style={styles.card_top}>
<View style={styles.holder}>
<View style={styles.icon}>
<Ionicons
name='ios-people-circle-sharp'
color='white'
size={48}
/>
</View>
<View style={styles.visitante}>
<Text style={styles.text_nombre}>{item.nombre} </Text>
<Text style={styles.text_cedula}>e-0000001</Text>
<View>
<Text style={styles.text_fecha}>2 de enero de 2022</Text>
</View>
</View>
</View>
</View>
<View style={styles.card_bottom}>
<TouchableOpacity style={styles.button_accept}>
<Text style={styles.button_text}>Aceptar</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button_reject}>
<Text style={styles.button_text}>Rechazar</Text>
</TouchableOpacity>
</View>
</View>
}
return (
<FlatList
ListHeaderComponent={<VisitasHeader title={titulo} />}
data={visitas}
keyExtractor={item => item.id}
renderItem={CardFunction}
// renderItem={({item}) => <View><Text>{item.nombre}</Text></View>} WORKS PERFECT WHEN USING THIS
ListEmptyComponent={<Text style={{textAlign:'center',paddingTop:10}}>No tiene visitas por aprobar.</Text>}
/>
)
}
export default VisitasCard
const styles = StyleSheet.create({
button_accept:{
backgroundColor:'green',
// margin:12,
padding:10,
borderRadius:12,
},
button_text:{
color:'white',
fontWeight:'bold',
},
button_reject:{
backgroundColor:'red',
// margin:12,
padding:10,
borderRadius:12,
},
card_bottom:{
height:50,
flexDirection:'row',
alignItems:'center',
justifyContent:'center',
borderWidth:1,
borderColor:'#3959ea',
borderBottomLeftRadius:8,
borderBottomRightRadius:8,
justifyContent:'space-evenly'
},
card_top:{
height:100,
backgroundColor:'#3959ea',
borderTopLeftRadius:8,
borderTopRightRadius:8,
alignItems:'center',
justifyContent:'center',
},
holder:{
flexDirection:'row',
},
icon:{
padding:10,
alignItems:'center',
margin:12,
},
text_cedula:{
color:'white',
fontSize:18,
textTransform:'uppercase',
fontWeight:'600',
},
text_nombre:{
color:'white',
fontSize:24,
textTransform:'capitalize',
fontWeight:'800',
// ellipsizeMode:'head',
// numberOfLines:1,
},
text_fecha:{
color:'white'
},
visitante:{
flex:2,
justifyContent:'center',
alignItems:'flex-start',
}
})
try add { item } and add return
const CardFunction = ({ item }) => {
return (
<View style={{ marginBottom: 10 }}>
<View style={styles.card_top}>
<View style={styles.holder}>
<View style={styles.icon}>
<Ionicons
name="ios-people-circle-sharp"
color="white"
size={48}
/>
</View>
<View style={styles.visitante}>
<Text style={styles.text_nombre}>{item.nombre} </Text>
<Text style={styles.text_cedula}>e-0000001</Text>
<View>
<Text style={styles.text_fecha}>2 de enero de 2022</Text>
</View>
</View>
</View>
</View>
<View style={styles.card_bottom}>
<TouchableOpacity style={styles.button_accept}>
<Text style={styles.button_text}>Aceptar</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button_reject}>
<Text style={styles.button_text}>Rechazar</Text>
</TouchableOpacity>
</View>
</View>
);
};

ScrollView isn't appering

I was messing with my code and suddenly the ScrollView decided to disappear.
For some reason, the ScrollView works "properly" inside the Character bar View
but when it is inside of the base View it just isn't there.
export default class CharacterSheet extends Component {
render() {
return (
<View style={{flex:1}}>
<View style={styles.TopBar}>
<View>
</View>
</View>
<View style={{flex:1}}>
<View style={styles.CharacterBar}>
</View><View style={styles.Base}>
<ScrollView style={styles.scroll}>
<View style={{paddingTop:72}}>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
<View style={styles.spellsBox}>
<Text>e</Text>
</View>
<View style={styles.spellsBox}>
<Text>a</Text>
</View>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
</View>
</ScrollView>
</View>
<Animated.View style={styles.CharacterStatsBar}>
</Animated.View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
CharacterBar:{
height:72,
backgroundColor:'#242527'
},
CharacterStatsBar:{
position:'absolute',
top: 72,
left: 0,
right: 0,
height:72,
backgroundColor:'#404040',
borderBottomWidth:2,
borderBottomColor:'#c53131',
borderTopWidth:1,
borderTopColor:'#838383',
},
Base:{
flex:1,
backgroundColor:'#fff',
},
scroll:{
width:'95%',
alignSelf:'center'
},
spellsBox:{
height:80,
marginTop:10,
paddingVertical:10,
borderColor:'#777',
borderWidth:3,
justifyContent:'center'
}
});
I'm trying to run this in an android device
this problem is pretty annoying and is stressing me a little bit.
Try Like this , don't wrap ScrollView inside multiple Views.
<View style={{flex:1}}>
<View style={styles.TopBar}>
<View>
</View>
</View>
<ScrollView style={styles.scroll}>
<View style={{paddingTop:72}}>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
<View style={styles.spellsBox}>
<Text>e</Text>
</View>
<View style={styles.spellsBox}>
<Text>a</Text>
</View>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
<View style={styles.spellsBox}>
<Text>Hi</Text>
</View>
<View style={styles.spellsBox}>
<Text>byee</Text>
</View>
</View>
</ScrollView>
</View>

How to navigate from a component class in React Native

I want to simply navigate from Home Screen to Creator Screen. I can easily navigate between them if i place the link directly in my Home Class, but I have created a Cards component class for all my creators, now I can't navigate from my Cards Class. Any idea how? The code in below is not working. I got error said that Can't find variable: navigation.
my Home scree screenshot
Any one would help? Big thanks.
I tired to make my Cards Class like this, but then my imageUri became a new problem. So i removed it, the current Cards Class is in below.
const Cards = ({navigation}) => (
<View style={{padding: 30, flexDirection: 'row', borderBottomColor: '#6a6a6a', borderBottomWidth: 0.4}}>
<View>
<Image source={this.props.imageUri} style={styles.profileIcon} />
<Image source={images.broShakeLogo} style={styles.broShakeLogo} />
</View>
<View style={{paddingLeft: 40, flexDirection: 'column'}}>
.....
<TouchableOpacity
onPress={() => navigation.navigate('creator')} >
.....
);
Here's my stack navigator
const HomeStack = createStackNavigator ({
home: {
screen: HomeScreen,
},
creator: {
screen: CreatorScreen
},
},
{
headerMode: 'none'
});
And here's my Home Class
class Home extends Component {
return (
<View style={styles.container}>
<ScrollView>
<View style={styles.welcomContainer}>
{/* so this one in here actually works fine but i want them wrap inside my Cards Class */}
<TouchableOpacity onPress={() => this.props.navigation.navigate('creator')}>
<CT.ReadmoreText/>
</TouchableOpacity>
</View>
<Cards imageUri={require('../assets/images/cprofile_2.jpg')} distance="30" navigation={this.props.navigation}/>
<Cards imageUri={require('../assets/images/cprofile_1.jpg')} distance="34" />
<Cards imageUri={require('../assets/images/cprofile_1.jpg')} distance="20" />
<Cards imageUri={require('../assets/images/cprofile_3.jpg')} distance="10" />
</ScrollView>
</View>
);
}
}
export default Home;
Here's my Cards class
class Cards extends Component {
render() {
<View style={styles.container}>
<View style={{padding: 30, flexDirection: 'row', borderBottomColor: '#6a6a6a', borderBottomWidth: 0.4}}>
<View>
<Image source={this.props.imageUri} style={styles.profileIcon} />
<Image source={images.broShakeLogo} style={styles.broShakeLogo} />
</View>
<View style={{paddingLeft: 40, flexDirection: 'column'}}>
<Icon name="location-arrow" type="FontAwesome"
style={{ color: "#00d278" ,fontSize: 18 }} >
<Text style={styles.distanceText}> {this.props.distance} m</Text>
</Icon>
<Text style={styles.locationText}>Atomica</Text>
<Text style={styles.cityText}>MELBOURNE</Text>
<View style={{paddingTop: 18}}>
<TouchableOpacity
onPress={() => navigation.navigate('creator')}
>
<CT.ReadmoreText/>
</TouchableOpacity>
</View>
</View>
</View>
</View>
);
}
}
Your can try this
import {withNavigation} from 'react-navigation'
class Home extends React.Component{
return (
<View style={styles.container}>
<ScrollView>
<View style={styles.welcomContainer}>
{/* so this one in here actually works fine but i want them wrap inside my
Cards Class */}
<TouchableOpacity onPress={() =>
this.props.navigation.navigate('creator')}>
<CT.ReadmoreText/>
</TouchableOpacity>
</View>
<Cards imageUri={require('../assets/images/cprofile_2.jpg')} distance="30"
/>
<Cards imageUri={require('../assets/images/cprofile_1.jpg')} distance="34"
/>
<Cards imageUri={require('../assets/images/cprofile_1.jpg')} distance="20"
/>
<Cards imageUri={require('../assets/images/cprofile_3.jpg')} distance="10"
/>
</ScrollView>
</View>
);
}
}
export default withNavigation(Home);
const Cards = () => (
<View style={{padding: 30, flexDirection: 'row', borderBottomColor: '#6a6a6a',
borderBottomWidth: 0.4}}>
<View>
<Image source={this.props.imageUri} style={styles.profileIcon} />
<Image source={images.broShakeLogo} style={styles.broShakeLogo} />
</View>
<View style={{paddingLeft: 40, flexDirection: 'column'}}>
.....
<TouchableOpacity
onPress={() => this.props.navigation.navigate('creator')} >
.....
);
You have passed navigation as props,
<Cards imageUri={require('../assets/images/cprofile_2.jpg')} distance="30" navigation={this.props.navigation}/>
So, you need to use it as this.props.navigation.navigate('....');
but you have used it as navigation.navigate('....');
change it and it will work.

react-native-swipeout onPress method disables containing component's onPress method

I have the following flatlist render method that upon tapping on a list item, it will call the this._onPress method:
render() {
return (
<TouchableOpacity onPress={this._onPress} >
<View style={styles.bookItem} >
<Image style={styles.cover} source={{uri:this.props.coverURL}}/>
<View style={styles.info} >
<Text style={styles.title}>{this.props.title} </Text>
<Text style={styles.author}>{this.props.author}</Text>
<Text style={{height: 8}}/>
</View>
<View style={styles.rightIcon}>
<Icon name="chevron-right" size={28} color={'#AAAAAA'} />
</View>
</View>
</TouchableOpacity>
);
}
After I added the swipeout tag in the following code, the swipeout works but tapping on an item no longer calls the this._onPress method:
render() {
// Buttons
var swipeoutBtns = [
{
text: 'Delete',
onPress: this._buttonPress
}
]
return (
<TouchableOpacity onPress={this._onPress} >
<Swipeout right={swipeoutBtns} >
<View style={styles.bookItem} >
<Image style={styles.cover} source={{uri:this.props.coverURL}}/>
<View style={styles.info} >
<Text style={styles.title}>{this.props.title} </Text>
<Text style={styles.author}>{this.props.author}</Text>
<Text style={{height: 8}}/>
</View>
<View style={styles.rightIcon}>
<Icon name="chevron-right" size={28} color={'#AAAAAA'} />
</View>
</View>
</Swipeout>
</TouchableOpacity>
);
}
Is this a restriction of react-native-swipeout?
If you were to have Swipeout as the first tag and touchable as the next nested tag I think it would work. However, its seems to make the Swipeout functionality less responsive

Getting design issues when the device is in PORTRAIT UPSIDEDOWN in React native

I'm working on React native project, My issue is when I try to change the orientation from LANDSCAPE to PORTRAIT getting some design issues especially when the device is turned to PORTRAIT UPSIDEDOWN from LANDSCAPE.
Here Is My Code:
class Exm extends Component {
constructor() {
super();
const init = Orientation.getInitialOrientation();
this.state = {
init,
or: init,
sor: init,
emailId: '',
password:'',
Token:'',
orientation:'',
Spinner:false,
userId:null,
isDisabled:false
};
this._updateOrientation = this._updateOrientation.bind(this);
Orientation.addOrientationListener(this._updateOrientation);
this._updateSpecificOrientation = this._updateSpecificOrientation.bind(this);
Orientation.addSpecificOrientationListener(this._updateSpecificOrientation);
}
_updateOrientation(or) {
// alert("HI")
this.setState({ or });
}
_updateSpecificOrientation(sor) {
//alert("HELLO")
this.setState({ sor });
}
render() {
console.log("Type Of Orientation:"+this.state.init+','+this.state.or+','+this.state.sor);
const { init, or, sor} = this.state;
return (
<View style={styles.container}>
{this.state.sor=="PORTRAIT" ?(
<View style={{flex:1}}>
<Image style={{width:windowSize.width,height:windowSize.height,resizeMode:'cover'}} source={require('./../images/home.png')}>
<View style={{flex:1}}>
<View style={{flex:0.5,justifyContent:"flex-end"}}>
<Text style={{backgroundColor:"transparent",fontSize:17,color:"white",fontWeight:'500',textAlign:'center',marginBottom:45}}>Finest Wines Direct from Sonoma</Text>
<TouchableOpacity onPress={this.onClick.bind(this)}>
<View style={styles.button1}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>BROWSE WEBSITE</Text>
</View>
</TouchableOpacity>
</View>
<View style={{flex:0.5}}>
<TouchableOpacity onPress={this.onClick1.bind(this)}>
<View style={styles.button}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>DAILY DEALS</Text>
</View>
</TouchableOpacity>
</View>
</View>
</Image>
</View>
):
this.state.sor=="UNKNOWN" ? (
<View style={{flex:1}}>
<Image style={{width:windowSize.width,height:windowSize.height,resizeMode:'cover'}} source={require('./../images/home.png')}>
<View style={{flex:1}}>
<View style={{flex:0.5,justifyContent:"flex-end"}}>
<Text style={{backgroundColor:"transparent",fontSize:17,color:"white",fontWeight:'500',textAlign:'center',marginBottom:45}}>Finest Wines Direct from Sonoma</Text>
<TouchableOpacity onPress={this.onClick.bind(this)}>
<View style={styles.button1}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>BROWSE WEBSITE</Text>
</View>
</TouchableOpacity>
</View>
<View style={{flex:0.5}}>
<TouchableOpacity onPress={this.onClick1.bind(this)}>
<View style={styles.button}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>DAILY DEALS</Text>
</View>
</TouchableOpacity>
</View>
</View>
</Image>
</View>
):this.state.sor=="LANDSCAPEUPSIDEDOWN" ? (
<View style={{flex:1}}>
<Image style={{width:windowSize.height,height:windowSize.width}} source={require('./../images/home_landscape.png')}>
<View style={{flex:1}}>
<View style={{flex:0.5,justifyContent:"flex-end"}}>
<Text style={{backgroundColor:"transparent",fontSize:17,color:"white",fontWeight:'500',textAlign:'center',marginBottom:45}}>Finest Wines Direct from Sonoma</Text>
<TouchableOpacity onPress={this.onClick.bind(this)}>
<View style={styles.button1}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>BROWSE WEBSITE</Text>
</View>
</TouchableOpacity>
</View>
<View style={{flex:0.5}}>
<TouchableOpacity onPress={this.onClick1.bind(this)}>
<View style={styles.button}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>DAILY DEALS</Text>
</View>
</TouchableOpacity>
</View>
</View>
</Image>
</View>
):
<View style={{flex:1}}>
<Image style={{width:windowSize.height,height:windowSize.width}} source={require('./../images/home_landscape.png')}>
<View style={{flex:1}}>
<View style={{flex:0.5,justifyContent:"flex-end"}}>
<Text style={{backgroundColor:"transparent",fontSize:17,color:"white",fontWeight:'500',textAlign:'center',marginBottom:45}}>Finest Wines Direct from Sonoma</Text>
<TouchableOpacity onPress={this.onClick.bind(this)}>
<View style={styles.button1}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>BROWSE WEBSITE</Text>
</View>
</TouchableOpacity>
</View>
<View style={{flex:0.5}}>
<TouchableOpacity onPress={this.onClick1.bind(this)}>
<View style={styles.button}>
<Text style={{fontSize:18,color:"white",fontWeight:"bold",textAlign:'center'}}>DAILY DEALS</Text>
</View>
</TouchableOpacity>
</View>
</View>
</Image>
</View>
}
</View>
);
}
}
const styles = StyleSheet.create({
container:{
flex:1,
backgroundColor:'#f5f5f5'
},
button:{
height: 55,
backgroundColor: 'transparent',
borderColor: 'white',
borderWidth: 2,
marginRight:50,
marginLeft:50,
marginTop: 20,
marginBottom:5,
justifyContent:'center',
alignSelf:'stretch',
},
button1:{
height: 55,
backgroundColor: 'transparent',
borderColor: 'white',
borderWidth: 2,
marginRight:50,
marginLeft:50,
marginBottom:5,
justifyContent:'center',
alignSelf:'stretch',
},
buttonText:{
fontSize: 18,
marginTop:5,
marginBottom:5,
textAlign:'center',
color:'white',
textAlignVertical:'center',
},
});
module.exports = Exm;
ScreenShots Here.
Please give me suggestions to solve this issue, Any help much appreciated
Ef.png
Seems like the Module is not updated with ES6 Syntax. Here is a Sample Code you can make use of. Demo
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import OrientationModule from 'react-native-orientation'
class Example extends Component {
constructor() {
super();
this.state = {
orientationStatus: 'PORTRAIT'
};
}
componentWillMount(){
var Orientation = OrientationModule.getInitialOrientation()
this.setState({
Orientation: Orientation
})
}
_orientationDidChange = (orientationStatus) => {
this.setState({orientationStatus})
}
componentDidMount(){
// Add a Listener, every time Orientation changes this method triggers
OrientationModule.addOrientationListener(this._orientationDidChange);
}
componentWillUnmount(){
// Remove the Listener, to avoid setting a State while component was unmounted
OrientationModule.removeOrientationListener(this._orientationDidChange);
}
render() {
// You can Have your Design Logic here
return (
<View style={{flex:1,alignItems:'center',justifyContent:'center'}}>
<Text>{this.state.orientationStatus}</Text>
</View>
)
}
}
module.exports = Example
Why are you doing this in first place, just write component w/o any orientation code and it should rotate automatically. Then if you need some layout adjustments do those like width/height or just check flexbox model more maybe it's already have what you need, while react native mimics flexbox. Can't tell from your description what issue you face.
Also if you want to disable some orientations, it can be done in project config
Android
Android - disable landscape mode?
iOS https://stackoverflow.com/a/24205653/1737158