Achieving Stack/Overlap Icons using React native.
I am trying to achieve something like this in react native:
https://fontawesome.com/how-to-use/on-the-web/styling/stacking-icons
how to achieve this?
You can achieve this by doing it like this. Using width and height helps you keep the view in place and aligning everything to the center so it looks nice like stacked icons.
<View style={{
position:"relative",
justifyContent:'center',
alignItems:"center",
width:40,
height:40
}}>
<Icon name="circle" size={34} color={"black"} />
<Icon name="flag" size={20} color={"white"} style={{position: 'absolute', zIndex: 99}} />
</View>
https://snack.expo.io/HkxWerHBr
Output:
In this Example I stacked the FontAwesome Icon "square" and "home". To stack them, you need a parent view with position: 'relative'. Then you can apply position: 'absolute'and a zIndex to the icon which should be on top of the other one. Afterwards you can position the icon for example with the top/left style property.
Code:
<View style={{position: 'relative'}}>
<Icon name="square" size={24} color={"black"} />
<Icon
name="home"
size={24}
color={"white"}
style={{position: 'absolute', zIndex: 99, left: 0, top: 0}} />
</View>
Demo:
https://snack.expo.io/rkHnZJrrH
Was able to achieve like this with react native elements [ not sure if they use zIndex internally]
render() {
return (
<View style={styles.container}>
<View
style={{
position: 'relative',
height: 64,
width: 64,
justifyContent: 'center',
alignItems: 'center',
}}>
<Icon type="font-awesome" name="square" size={64} />
<Icon
type="font-awesome"
name="twitter"
color="white"
size={32}
containerStyle={{ position: 'absolute' }}
/>
</View>
</View>
);
}
And the container style would be
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
}
snack repo:
https://snack.expo.io/#roach_iam/vigorous-blueberries
Related
Touchable opacity onPress working when we click at edges, when we click on center its not working
I have tried
importing from react-native-gestures
giving z-index
wrapping with view
import {TouchableOpacity} from 'react-native';
<View style={{bottom:0,width:'100%',height:44,flex:1,position:"absolute"}}>
<TouchableOpacity
onPress={()=>handleLogin()}
style={{
width: '100%',
flex:1,
height: 44,
alignItems: 'center',
justifyContent: 'center',
width:"100%",
}}
>
<LinearGradient
start={{x: 0.5, y: 0}}
end={{x: 0.861, y: 1}}
locations={[0,0.867,1]}
style={{
width:"100%",
height:"100%",
justifyContent:"center",
flexDirection:"row",
alignItems:"center",
// zIndex:99
}}
colors={['#DD9D18', '#FFEF6C', '#EEC733' ]}>
<Text style={GenericStyles.h5StyleTwo} >Sign In</Text>
<SignInIcon fill="#000" style={{marginLeft:8}}/>
</LinearGradient>
</TouchableOpacity>
</View>
Maybe your LinearGradient or SignInIcon component having some gesture detector, please checkout that.
Simply I am trying to make 3 Texts with icons align in a column
I want to give the expo icons a little margin-top so they are next to each text element
Then how can I make the next line in text aligned with the text itself
For Example The (S) in School to be vertically aligned with the (5) in 5th
I searched a lot on how to do that in react-native but with no luck
and I tried some normal CSS stuff but didn't work is it achievable?
Code :
<View style={styles.cardView}>
<Text style={styles.CardTextLayout} > <MaterialIcons name="store" size={21} color="lightgrey" /> {item.key} </Text>
<Text style={styles.locationText} > <Entypo name="location-pin" size={21} color="lightgrey" />5th Settelment, Near Akhnaton School, Cairo</Text>
<Text style={styles.locationText} > <MaterialIcons name="description" size={21} color="lightgrey" />Breif Description about the place and what is offers</Text>
</View>
Styles
CardTextLayout: {
// marginLeft: 8,
fontSize: cardResponsiveFontSize,
fontWeight: 'bold',
textAlign: 'left',
color: '#231F20',
elevation: 8,
},
locationText: {
fontSize: cardResponsiveFontSize,
textAlign: 'left',
color: '#231F20',
elevation: 8,
},
I don't know how you would do that with your current code, but you can try to set it up like this.
<View style={styles.cardView}>
<View style={styles.cardRow}>
<View style={styles.cardIcon}>{put your icon here}</View>
<View style={styles.cardText}>{put your text here}</View>
</View>
...add the other 2 rows here
</View>
And styles
cardRow: {
flexDirection: "row",
flex: 1
},
cardIcon: {
flex: 1
},
cardText: {
flex: 9
}
And add your styles for icons and text.
You can change up the cardIcon and cardText flex ratio so that you get different width for your icon.
You can make a wrapper view with alignItems: 'center' to make both text and icon vertical center
<View style={styles.cardView}>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<MaterialIcons name="store" size={21} color="lightgrey" />
<Text style={styles.CardTextLayout}>{item.key}</Text>
</View>
.....
</View>
I got the following problem: I want to implement a location search bar with the google maps places api to generate results. Everything is working, but the listview(which's position prop is set to absolute) seems to be transparent.
i already tried to set the containers opacity to 1 but that didnt helped. can someone tell me what i need to change to make to underlaying test-text not visible in the container?
my code:
locationPicker:
<View style={styles.modalContainer}>
<SafeAreaView style={styles.safeArea}>
<View style={styles.searchContainer}>
<LocationSearchBar/>
</View>
</SafeAreaView>
<View style={styles.modalContent}>
<Text>test</Text>
</View>
</View>
searchContainer: {
alignItems: "center",
justifyContent: "center",
minHeight: 60,
paddingHorizontal: 16,
paddingVertical: 10,
backgroundColor: theme.colors.screen.alter
}
locationSearchBar:
<React.Fragment>
<TextInput
autoCorrect={false}
onChangeText={handleTextChange}
value={inputValue}
label={<Icon name={"search"} />}
placeholder={"Search location..."}
/>
<ScrollView style={styles.autoCompleteResultList}>
{locationResults.map((el, i) => (
<AutoCompleteItem
{...el}
fetchDetails={fetchDetails}
key={String(i)}
/>
))}
</ScrollView>
</React.Fragment>
AutoCompleteItem:
<View style={styles.autoCompleteItemContainer}>
<RkText rkType={"primary2"}>{this.props.structured_formatting.main_text}</RkText>
<RkText rkType={"primary1"}>{this.props.structured_formatting.secondary_text}</RkText>
</View>
autoCompleteItemContainer: {
backgroundColor: "red",
paddingHorizontal: 5,
paddingVertical: 5
},
autoCompleteResultList: {
maxHeight: 200,
position: "absolute",
backgroundColor: theme.colors.screen.alter,
width: "100%",
top: 55
}
cheers!
I think it's not a background-color or opacity problem.
It seems overlay problem of your position:absolute and default views
test is normal or default one so it has highest priority to come over any position:absolute views.
hence, test is above the results.
You'll need to change this position and make result above the test.
so do this by zIndex.
autoCompleteResultList: {
maxHeight: 200,
position: "absolute",
backgroundColor: theme.colors.screen.alter,
width: "100%",
top: 55,
zIndex:1 // highest number of zIndex in your current screen if you have other zIndex
}
I want to create a row column type structure where i can create multiple section which can be dragged as well as resized as per needed, I have used this library(https://www.npmjs.com/package/react-native-draggable) for making dragable section but how i can configure it to be resizable, also it needs to be limited to the container
<View
style={{
flexDirection: 'row',
flex: 1,
padding: 20,
}}>
<View style={{ flex: 0.3, backgroundColor:'blue' }}>
<Draggable renderSize={56} renderColor='black' offsetX={-100} offsetY={-200} renderText='A' pressDrag={() => alert('touched!!')} />
</View>
<View style={{ flex: 0.3, backgroundColor: 'green' }}>
<Draggable renderColor='red' renderShape='square' renderText='UC' />
</View>
<View style={{ flex: 0.4, backgroundColor: 'yellow' }}>
<Draggable renderColor='red' renderShape='square' renderText='B' />
<Draggable />
</View>
</View>
Using this Resizable and draggable library you can easily achieve this with just 3 lines of code,
<Gestures rotatable={false}>
<Text style={{ padding: 40 }}>AHGHAGS</Text>
</Gestures>
see working example on snack here
I am new in react native and I have to design a screen and when list going longer I realised my scroll view is not working here is below my code please share suggestion...Thanks!
<View style={{flex:1}}>
<ActionBar
containerStyle={{height:60,alignItems: 'center'}}
backgroundColor={'#fff'}
title={'Select Categories'}
titleStyle={styles.pageTitle}
onLeftPress={() => goBack()}
leftIconContainerStyle={{marginTop:22}}
leftIconName={'back'}
leftIconImageStyle={{backgroundColor:'#333',height:18,width:18}}
/>
<Image source={require('../images/bg-login.jpg')}
style={{position:'absolute',left:0,right:0,top:0,bottom:0}} />
<ScrollView style={{backgroundColor:'#00000000',position:'absolute',left:0,right:0,top:0,bottom:0}} >
{views}
</ScrollView>
<View style={styles.footerSec}>
<TouchableOpacity style={styles.nextBtn}
onPress={()=> {this.props.navigation.navigate('Tutorials',{tutId:this.state.selectedCats})}}>
<Text style={[styles.btnText, styles.priceText]}>Next</Text>
</TouchableOpacity>
</View>
</View>
Here is my list code:
<TouchableOpacity key={itemData[j]._id}
onPress = {() => {
activeItem ? this.removeCat(itemData[j]._id) : this.insertCat(itemData[j]._id)
}}>
<View style={{position:'relative'}}>
<LinearGradient colors={activeItem ? ['#cb5fb1', '#f874d8', '#f98bde'] :['#ffb6cf','#ffb6cf','#ffb6cf'] } style={{
position: 'absolute',
alignItems: 'center',
justifyContent:'center',
backgroundColor: '#f673d7',
width: armSize,
height: armSize,
borderRadius: (armSize) / 2,
top: topp,
left: leftp,
}}>
<Text style={{
color: '#fff',
alignSelf:'center',
fontSize: RandomNumber,
fontWeight: '600',
}}>
{itemData[j].name}
</Text>
</LinearGradient>
</View>
</TouchableOpacity>
I designed below screen but the scroll view bounce and come up on same position...I think this is because of child position style but it's required for the circle in row. I can't scroll for below circles that's the issue.
You could use normal Image to put a background image using position='absolute' and setting background color opacity of ScrollView to #00000000 which means that will be transparent
Example
<Image
source={require('../images/bg-login.jpg')}
style={{position:'absolute',
left:0,
right:0,
top:0,
bottom:0}} />
<ScrollView
style={{backgroundColor:'#00000000',
position:'absolute',
left:0,
right:0,
top:0,
bottom:0}} >
<View>
<Text>Some content</Text>
</View>
</ScrollView>
For the scroll view issues I used below code and it's working fine everywhere
<ScrollView contentContainerStyle={{ paddingBottom: 120 }}>
---code---
</ScrollView>