React Native Horizontal ScrollView does not fully scrolled - react-native

I have the above ScrollViews( highlighted in yellow color ) each one with maximum 6 items. When I try to scroll it to the end, I can't scroll 100%. Part of the last item will not view. See the following screenshot.
The highlighted red area is not able to see or scroll.
Following is the component,
const Item = ({title, data}: any) => (
<View style={styles.itemRoot}>
<View style={styles.item}>
<View style={styles.itemLeft}>
{/* left inner container */}
</View>
<View style={styles.itemRightRoot}>
<View style={styles.itemRightTitle}>
<Text>TITLE</Text>
</View>
<View style={styles.itemRight}>
{/* area which render each ScrollViews */}
{title.items.map((item: any, index: number) => {
return (
<ScrollView horizontal>
{item.map((child, index) => {
return (
<View
key={index}
style={{
width: isTablet()
? (Dimensions.get('screen').width - 80) / 6
: (Dimensions.get('screen').width - 64) / 3,
marginRight: 8,
marginBottom: 8,
}}>
<SectionInnerItem />
</View>
);
})}
</ScrollView>
);
})}
</View>
</View>
</View>
{/* separator */}
<View
style={{
height: 2,
marginTop: 24,
marginBottom: 24,
backgroundColor: '#36363D',
width: Dimensions.get('screen').width - 64,
}}
/>
</View>
);
And this is the stylesheet,
const styles = StyleSheet.create({
itemRoot: {
marginLeft: 24,
marginRight: 16,
},
item: {
display: 'flex',
flexDirection: 'row',
},
itemRightRoot: {
display: 'flex',
flexDirection: 'column',
},
itemRightTitle: {
marginLeft: 24,
marginRight: 16,
},
itemRight: {
marginLeft: 24,
marginRight: 16,
paddingTop: 16,
paddingBottom: 16,
},
itemLeft: {},
});
What am I doing wrong here? Also, is there a way I can just use one single ScrollView but with a maximum of 6 items on each row and the rest of the items in the next row?

Please Give flex: 1 for the itemRightRoot. The problem is that, itemRightRoot doesn't know the width of the rest of the screen with the square on the left side of the screen.
itemRightRoot: {
flex: 1,
display: 'flex',
flexDirection: 'column',
},

Related

react-native custom header navigator has unwanted margins

I have drawer and stack navigator. I disabled header of drawer and stack navigators. And create my own header component but I cannot rid of the edge margins of my custom header component.
[Screenshot]
https://i.stack.imgur.com/5jWv3.png
const styles = StyleSheet.create({
header: {
backgroundColor: 'purple',
width: '100%',
height: '100%',
flexDirection: 'row',
alignItems: 'center',
},
headerText: {
fontWeight: 'bold',
fontSize: 21,
letterSpacing: 1,
paddingLeft: 45,
paddingBottom: 2,
},
icon: {
fontSize: 30,
color:"white",
position: 'absolute',
zIndex: 3,
}});
 
return (
<View style={styles.header}>
<View style={styles.header}>
<MaterialIcons style={styles.icon} name="menu" onPress={openMenu}/>
<Text style={styles.headerText}>{titleName}</Text>
</View>
</View>
)
This is your header Component. Have you checked if the Main Container does not have a paddingHorizontal in the Screen?
Solution #1
Change:
return (
<View style={styles.header}>
<View style={styles.header}>
<MaterialIcons style={styles.icon} name="menu" onPress={openMenu}/>
<Text style={styles.headerText}>{titleName}</Text>
</View>
</View>
)
to:
return (
<View style={styles.header}>
<MaterialIcons style={styles.icon} name="menu" onPress={openMenu}/>
<Text style={styles.headerText}>{titleName}</Text>
</View>
)
Solution #2
import {Dimensions} from 'react-native'
let width=Dimensions.get('screen').width
let height=Dimensions.get('screen').height
then:
const styles = StyleSheet.create({
header: {
backgroundColor: 'purple',
width: width,
height: height,
flexDirection: 'row',
alignItems: 'center',
},
})
I fixed the issue with opening the app on web to see styles of parent the element. In this case my parent element is the <Stack.screen> home tab.
I just checked the styles on web which is
marginLeft: 16,
marginRight: 16,
maxWidth: 470,
and override these styles with
marginLeft: 0,
marginRight: 0,
maxWidth: '100%',
screenshot of the solution result
<Stack.screen
options={{headerBackgroundContainerStyle: {
marginLeft: 0,
marginRight: 0,
maxWidth: '100%'
}
}}
/>

React Native scrollview stops scrolling after screen change

I have a ScrollView in react native where the functionality stops working only after I change the screen. For example: when I reload and land on the home screen (with the ScrollView) it all works fine. but when I use the bottom tab navigator to change the screen and return back to the home screen, it doesn't work anymore.
Thanks in advance for the help!
const Home = () => {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: COLORS.background }}>
<Header screenName="home" />
<View style={{ color: COLORS.secondary, flex: 14, paddingHorizontal: SIZES.width / 20}}>
<ScrollView
showsVerticalScrollIndicator={false}
>
<Text style={styles.popularHeader}>Title</Text>
<ScrollView
horizontal={true}
showsHorizontalScrollIndicator={false}
style={styles.popular}
>
<View style={styles.popularItem}>
<Text>Name</Text>
</View>
<View style={styles.popularItem}>
<Text>Name</Text>
</View>
<View style={styles.popularItem}>
<Text>Name</Text>
</View>
<View style={styles.popularItem}>
<Text>Name</Text>
</View>
</ScrollView>
<View style={styles.event}>
<Text style={styles.eventTitle}>event title</Text>
<Text style={styles.eventDate}>date</Text>
</View>
</ScrollView>
</View>
</SafeAreaView>
)
}
const styles = StyleSheet.create({
popularHeader: {
color: COLORS.text,
fontSize: SIZES.h4,
alignSelf: 'center',
marginBottom: 10
},
popular: {
borderBottomWidth: 1,
paddingBottom: SIZES.height / 30,
marginBottom: SIZES.height / 30,
borderBottomColor: COLORS.secondary
},
popularItem: {
width: 100,
height: 100,
borderRadius: 5,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: COLORS.text,
marginRight: 10,
},
event:{
height: SIZES.height / 3,
backgroundColor: COLORS.text,
borderRadius: 5,
marginBottom: SIZES.height / 30,
padding: 10
},
eventTitle: {
fontSize: SIZES.h3,
alignSelf: 'center'
},
eventDate: {
fontSize: SIZES.h6,
alignSelf: 'center'
}
})
In case someone wonders, after a three-day-long search I found out the problem was with the bottomTabNavigator not unmounting the screens after a change of screen. so the solution that fixed my problem is:
in screenOptions:
unmountOnBlur: true

React Native; How to place spaces in FlatList

I am trying to build a flat list in react native but am having trouble keeping the specific list items from not touching. I tried to use the itemSeparatorComponent but the problem still persisted.
This is my FlatList component
<View style={{ position: "absolute", bottom: -35, marginLeft: 40 }}>
<FlatList
horizontal
data={this.state.hitRecords}
renderItem={({ item }) => (
<ArticleBox
title={item.title}
year={item.year}
time={item.time}
author={item.author}
/>
)}
itemSeparatorComponent = {()=> </View>}
/>
</View>
This is my ArticleBox component
const styles = StyleSheet.create({
box: {
backgroundColor: "rgba(0.0,0.0,0.0,0.9)",
height: 150,
width: 300,
alignSelf: "center",
flex: 2,
flexDirection: "column",
borderRadius: 25,
elevation: 2
},
layout: {
textAlign: "center",
color: "#FFF"
},
input: {
color: "#ff8c00"
}
});
class ArticleBox extends Component<Props> {
render() {
return (
<View style={styles.box}>
<Text style={styles.layout}>
Time: <Text styles={styles.input}>{this.props.time}</Text>
</Text>
<Text />
<Text style={styles.layout}>Publication Year: {this.props.year}</Text>
<Text />
<Text style={styles.layout} numberOfLines = {3} >Publication Title: {this.props.title}</Text>
<Text />
<Text style={styles.layout}>Author: {this.props.author}</Text>
</View>
);
}
}
I am trying to get the list to behave like this
item item item item
but the list behaves like this
itemitemitemitem
Add marginLeft: 12 in your 'ArticleBox' Component. like this.
box: {
backgroundColor: "rgba(0.0,0.0,0.0,0.9)",
height: 150,
width: 300,
alignSelf: "center",
flex: 2,
flexDirection: "column",
borderRadius: 25,
elevation: 2,
marginLeft: 12
}

Adding margin to component changes screen layout react-native

I'm building a react-native app and I'm having a problem styling the components.
For some reason when I add a margin to one of the components the main component doesn't occupy the full height of the screen even though is "flex:1".
In this example the problem happens with the back button, if I use padding it works fine but I need to use margin so the user doesn't press the wrong component by mistake.
And the same problem happens in the rest of the app with different components that have a margin property.
Main component
body: {
flex: 1,
backgroundColor: 'green'
},
subHeader: {
backgroundColor: '#f4f4f4',
height: 95,
flexDirection: 'row'
},
vericalBar: {
width: 9
},
subHeaderDescription: {
flex: 1,
justifyContent: 'center',
marginLeft: 16
},
subHeaderLocation: {
color: '#2d2d2d',
fontSize: 14,
marginBottom: 10
},
subHeaderText: {
color: '#2d2d2d',
fontSize: 20
},
subHeaderStatus: {
alignItems: 'center',
justifyContent: 'center',
marginRight: 18
},
listDescription: {
backgroundColor: 'red',
flexGrow: 1,
paddingTop: 16,
paddingLeft: 20
},
taskDescription: {
color: '#2d2d2d',
fontSize: 16
}
<View style={localStyles.body}>
<Header navigation={this.props.navigation} />
<View style={localStyles.subHeader}>
<View style={[localStyles.vericalBar, { backgroundColor: task.color }]} />
<View style={localStyles.subHeaderDescription}>
<Text style={localStyles.subHeaderLocation}>{location.name}</Text>
<Text style={localStyles.subHeaderText}>{task.name}</Text>
</View>
{iconSelector(task)}
</View>
<BackButton navigation={this.props.navigation} />
<View style={localStyles.listDescription}>
<Text style={localStyles.taskDescription}>{task.description}</Text>
</View>
{returnStatus(task)}
<ReportIssueButton navigation={this.props.navigation} />
<Footer navigation={this.props.navigation} />
</View>
Back Button
<TouchableWithoutFeedback onPress={() => navigation.goBack()}>
<View style={localSytles.container}>
<Image style={{ width: 14, height: 14 }} source={require('../../Images/Back.png')} />
<Text style={localSytles.buttonText}>Back</Text>
</View>
</TouchableWithoutFeedback>
container: {
flexDirection: 'row',
height: 40,
paddingLeft: 20,
alignItems: 'center',
backgroundColor: 'blue'
},
buttonText: {
color: '#2d2d2d',
fontSize: 14,
marginLeft: 10
}
I've found the problem, the container "listDescription" had a "paddingTop: 16"
by removing that property it allowed the container to push the rest of the containers down.

Custom Component not appearing

I made a custom bottom Navbar for my React-Native App which I want to stick at the bottom of the screen.
This is what it looks like
<View style={styles.NavBarBottom}>
<TouchableOpacity
onPress={() => this.activeTab("home")}>
<Text> <Icon name="bitcoin" size={30} color={ this.state.activeTab == "home" ? "#fbc02d" : "white"} /></Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.activeTab("News")}>
<Text> <Icons name="news" size={30} color={this.state.activeTab == "News" ? "#fbc02d" : "white"} /> </Text>
</TouchableOpacity>
</View>
where Styles are this
const styles = StyleSheet.create({
NavBarBottom : {
paddingTop: 8,
borderTopWidth: 2,
backgroundColor: "#005cb2",
display: "flex",
flexDirection: "row",
justifyContent: "space-around",
padding: 5,
}
})
Now this successfully works and show in case of Home Screen but on another screen when I import it, It appears only when the content is loading and afterwards it doesn't appear (attaching the GIF for the same in end). Also on the page where I am just passing the props, it doesn't appear
The code for other page would be
<View>
<Header
navigation = {this.props.navigation}
enable = "true" />
<ScrollView>
<View style={listOfCurrencies}>
{ CurrencyDisplay.map(data =>
<TouchableOpacity>
<View style={IndvidualCurrencyMain}>
<Text style={dataLong}> {data["long"]}</Text>
<Text style={dataShort}>{data["short"]}</Text>
</View>
</TouchableOpacity>)}
</View>
</ScrollView>
<BottomNavigation />
</View>
With Styles like this
const styles = StyleSheet.create({
listOfCurrencies: {
display: "flex",
flexDirection: "column",
marginBottom: 60
},
IndvidualCurrencyMain: {
backgroundColor: "white",
display: "flex",
flexDirection: "row",
height: 80,
alignItems: "center",
height: 50,
borderRadius: 10,
marginLeft: 3,
marginRight: 3,
marginTop: 5,
marginBottom: 5
},
dataLong:{
marginLeft: 3,
width: 150
},
dataShort: {
marginLeft: "48%",
marginRight: 5
},
index: {
marginLeft: 2,
width: 20
}
})
Any idea why it won't be appearing?
You can try this just by adding the main view flex:1 style