React Native Grid View : Image messes up the view - ios

I'm building an app that requires a Grid View. So far my grid works fine as you can see on the image below, the red squares are well positioned. Though, when I add an image in each box, it messes up the grid (second picture). Any ideas why ?
This is the screenshots (first image works fine with margins and is centered)
Second image has no more margins in the middle and on the right side
And this is the code that generates the view :
renderData = (data) => {
return (
<View style={styles.box}>
<Text style={styles.boxText}>{data.name}</Text>
// This is what I add to display the image
<Image
source={data.image}
style={styles.boxImage} />
</View>
);
}
renderPage() {
return (
<View style={styles.container}>
<TouchableHighlight style={styles.filterButton}>
<Text style={styles.filterButtonMessage}>
Occasions
</Text>
</TouchableHighlight>
<ListView contentContainerStyle={styles.list}
dataSource={this.state.data2}
renderRow={this.renderData} />
</View>
);
}
var styles = StyleSheet.create({
container: {
flex: 1,
},
list: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center'
},
box: {
width: 150,
backgroundColor: 'red',
height: 150,
alignItems: 'stretch',
margin: 3
},
boxImage: {
flex: 1
},
boxText: {
flex: 1,
fontWeight: '900',
fontSize: 15,
color: 'white',
position: 'absolute',
bottom: 5,
right: 5,
backgroundColor: 'rgba(0,0,0,0)'
}
});

have you tried...
boxImage: {
flex: 1,
width: 150,
height: 150,
},

Related

React Native Expo App Crashing due to Handmade component inside ScrollView

I am building a react native expo application. The backend is seperated and not used in the process. Below you ll see the home screen component returns
return (
<ImageBackground source={require("../assets/background.jpeg")} style={styles.background}>
<MainPageTopBar />
<View style={styles.container}>
<ScrollView>
<View style={styles.textArea}>
<Text style={styles.text} >Merhaba</Text>
</View>
<View style={styles.welcome}>
<MainCard text={"Tüm Sanatçıları Keşfet"}/>
</View>
<View>
<Text>Öne Çıkan Sahneler</Text>
<View>
<ScrollView horizontal={true}>
{
venueList.map((val, index) => {
return (
<StageCard stageName={val.name} stageLocation={val.location}/>
)
})
}
</ScrollView>
</View>
</View>
</ScrollView>
</View>
<AppBar />
</ImageBackground>
);
Likewise below u can see the code for the class StageCard
import { View, TouchableWithoutFeedback, StyleSheet, Text, ImageBackground } from "react-native";
import { Ionicons } from '#expo/vector-icons';
import React from "react";
function StageCard(props) {
const func = () => {
props.navigation.navigate(props.nav);
}
return (
<TouchableWithoutFeedback onPress={() => console.log("ola")}>
<View style={styles.container}>
<ImageBackground style={styles.stageCard} imageStyle={styles.imageStyle} source={require("../assets/venue.jpg")}>
<View style={styles.nameView}>
<Text style={styles.text}>
{props.stageName}
</Text>
</View>
<View style={styles.cityView}>
<Text style={styles.textCity}>
{props.stageLocation}
</Text>
</View>
</ImageBackground>
</View>
</TouchableWithoutFeedback>
);
}
const styles = StyleSheet.create({
container: {
width: "40%",
height: "30%",
marginLeft: "5%",
marginTop: "10%",
},
imageStyle: {
borderRadius: 20,
},
stageCard: {
width: '100%',
height: '100%',
flex: 1,
},
nameView: {
width: "50%",
height: "20%",
alignContent: "center",
backgroundColor: "transparent",
position: "absolute",
top: "5%",
left: "5%",
},
cityView: {
width: "50%",
height: "20%",
alignContent: "center",
backgroundColor: "transparent",
justifyContent: "flex-end",
position: "absolute",
bottom: "5%",
right: "5%",
},
text: {
textAlign: "left",
textAlignVertical: "center",
fontSize: 20,
color: "#f4eeeb",
borderColor: "#f4eeeb",
},
textCity: {
textAlign: "right",
textAlignVertical: "center",
fontSize: 20,
color: "#f4eeeb",
borderColor: "#f4eeeb",
},
})
export default StageCard;
The app crashes when the app is built. I have narrowed down the possibilities as when I changes the stagecard to a view, the app builds and runs too. Hence the issue must be in the StageCard component.
After coming to the prior conclusion, I tried seperatly isolating the component. Couldn't figure out what caused the issue on the ios.
Update: The problem is caused by the scrollview as the mapping separately works. I got rid of the scrollview horizontal and the cards showed up. Any ideas?

change an array of pictures depending on iPhone screen size

I have a screen that is an HRV reading, the styles work well on all new devices, even on SE and Mini versions, my problem is with iPhone 8, the screen gets all messed up. this is the iPhone 13 screen and this is the iPhone 8 screen, I don't know how to change my code to identify it here is how my code is:
Obs. each index has a different style for the image.
const hrvScreensData = [
{
//0
imagePath: require('../../assets/images/hrvanimation1.png'),
styleText: {
fontSize: 28,
fontFamily:'inter-regular',
lineHeight:34,
padding: 20,
color: '#FFF',
textAlign: 'center',
},
title: 'Measure with back camera',
bkgColor: 'rgba(83,58,237,0.7)',
styleLarge: {height: screenWidth/2, width: screenWidth, flex: 1, resizeMode: 'contain'},
styleSmall: {height: 40, width: 40, resizeMode: 'contain'}
},
.
.
.
<View
style={{
marginTop: -150,
flexDirection: 'row',
justifyContent: 'flex-end',
paddingLeft: index == 0 ? 20 : 0,
backgroundColor: 'transparent',
}}
>
{
item.imagePath !== null ?
<Image
source={item.imagePath}
style={item.styleLarge}
/>
:
null
}
</View>
<View
style={{
alignItems: 'center',
justifyContent: 'flex-start',
width: screenWidth,
flex: 0.8,
}}>
<Text
style={item.styleText}
>
{item.title}
</Text>
</View>
any way I can make the app check which device or screen size is and change the style on the Index?
You can access the screen dimensions of the current device using Dimensions from react-native. Then conditionally set the styles of your component.
Here is an example.
import { Dimensions } from "react-native"
const height = Dimensions.get("screen").height
const width = Dimensions.get("screen").width
const SomeComponent = () => {
return (
<View
style={{
paddingLeft: width < 321 ? 10 : 20
}}
></View>
)
}

React-native-maps lite mode don't work at Ios emulator

Good afternoon everyone, I am developing an app in React native, I put the library react-native-maps to show some fixed maps in a scrollview, in android I show the coordinates with the marker but in the map moves when I try do the scroll
I'm trying with staticmap, but where I would have to leave the map in ios I'm left blank.
import React, {Component} from 'react'
import {View, Text, TouchableOpacity, Platform, Image} from 'react-native'
import MapApp from './MapApp'
const staticMapURL = 'https://maps.googleapis.com/maps/api/staticmap'
class PropertyListCard extends Component {
renderMap(){
if(Platform.OS == 'ios'){
console.log(Platform.OS)
return(
<View
style={{
width: 500,
height:500,
backgroundColor: 'red'
}}
>
<Image
source={{uri: "https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=MyGoogleKey"}}
style={{
width: 200,
height: 200
}}
/>
</View>
)
}else{
return(
<MapApp />
)
}
}
render(){
return(
<View style={styles.container}>
<View style={styles.titleContainer}>
<Text style={styles.titleText}>
{this.props.data.direction}
</Text>
</View>
<View style={styles.mapContainer}>
{this.renderMap()}
</View>
<TouchableOpacity
style={styles.btn}
onPress={()=>{}}
>
<Text
style={styles.btnText}
>
Ver Vecinos
</Text>
</TouchableOpacity>
</View>
)
}
}
const styles = {
container: {
flex:1,
backgroundColor: '#fff',
margin: 10,
borderRadius: 10
},
titleContainer:{
height: 40,
justifyContent: 'center',
borderBottomWidth: 1,
borderColor: 'grey'
},
titleText: {
paddingLeft: 20,
fontSize: 17,
fontWeight: 'bold'
},
mapContainer:{
width: '100%',
height: 200
},
btn:{
height: 50,
width: '100%',
backgroundColor: '#008591',
borderBottomLeftRadius: 10,
borderBottomRightRadius: 10,
alignItems: 'center',
justifyContent: 'center',
},
btnText: {
color: '#fff',
fontSize: 17,
fontWeight: 'bold',
}
}
export default PropertyListCard
there is no support for litemode on ios
https://github.com/react-community/react-native-maps/issues/1411#issuecomment-310380854

Background color turns black after OnPress, when displayed on top of FlatList

Very strange behavior, I am using a FlatList, and on top of it there are 2 floating buttons (TouchableOpacity) (absolute position) and when they are pressed, their background color turns black.
This happens only on IOS.
Code:
Render
let content = (
<CollapsableNavList
onListScroll={this.showOrHideFilterButtons}
showFilterButtonsOnScroll={this.showOrHideFilterButtons}
style={styles.list}
isHorizontal={false}
dataModel={this.props.isFetching ? this.props.whileFetchingDisplayedResults : this.props.dataModel}
isFetching={false}
onRowSelect={this._onRowSelect}
didScrollWithOffset={this.didScrollWithOffset}
renderRowContent={this.renderRowContent}
keyExtractor={(item) => {
if (this.props.isFetching) {
return item
}
const property = item
return property.propertyId
}}
>
{header}
</CollapsableNavList>
)
return (
<View style={[styles.container, styles.relative]}>
<View style={styles.filterBtnBlock}>
<AdditionalSearchParamsButton
title='Map'
iconName='map'
onPress={this.onMapPress}
/>
</View>
{content}
</View>
)
export default class AdditionalSearchParamsButton extends Component {
// Prop type warnings
static propTypes = {
iconName: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired
}
render () {
const { iconName, title, onPress } = this.props
return (
<View>
<TouchableHighlight onPress={onPress} underlayColor={Colors.clear}>
<View style={styles.innerContainer}>
<McIcon
name={iconName}
style={styles.additionalPropsIcon}
/>
<Text style={styles.additionalPropsText}>{title}</Text>
</View>
</TouchableHighlight>
</View>
)
}
}
export default StyleSheet.create({
container: {
height: 50,
width: 150,
alignItems: 'center',
justifyContent: 'center'
},
innerContainer: {
height: 36,
width: 126,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: Colors.snow,
borderRadius: 18,
elevation: 2,
shadowOffset: {width: 0, height: 2},
shadowColor: 'black',
shadowOpacity: 0.3,
marginBottom: 5,
},
additionalPropsBtn: {
height: 36,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: Colors.snow
},
additionalPropsText: {
...Fonts.style.bigTitle,
color: Colors.blue,
paddingLeft: 10
},
additionalPropsIcon: {
fontSize: 22,
color: Colors.blue
}
})
What I've tried:
-Setting underlays color to clear, with no success.
-Adding different layers under, no success.
-This only happens when displayed on a list, happens with ListView too.
Please use TouchableOpacity instead of TouchableHighlight
TouchableHighlight Highlight the background when you click
Try add this <TouchableHighlight underlayColor='none' />
try this in your TouchableOpacity props
underlayColor="#ffffff00"
I have solved it using activeOpacity with background color
<TouchableOpacity activeOpacity={1} backgroundColor="#FFF"></TouchableOpacity>
You can use own backgroundColor
Wrap View with <TouchableHighlight underlayColor="#fff">

React Native showing blank screen

I'm using react-native latest release 0.4.4 and installed react-native-side-menu and react-native-carousel components.
For some reason when I run the app, it's not showing anything.
The code instantiate a view with sidemenu and contentview inside.
contentview is for displaying the main page which contains three buttons and when someone clicks on explore it takes them to search page using navigatorios component.
Is there is some problem with StyleSheet ?
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
Component,
NavigatorIOS,
View,
TouchableHighlight,
TextInput,
} = React;
var SideMenu = require('react-native-side-menu');
var Menu = React.createClass({
about: function() {
this.props.menuActions.close();
},
render: function() {
return (
<View>
<Text>Menu</Text>
<Text onPress={this.about}>About</Text>
</View>
);
}
});
var styles = StyleSheet.create({
searchView: {
flexDirection: 'row',
padding: 25,
marginTop: 100,
},
text: {
color: 'black',
backgroundColor: 'white',
fontSize: 30,
margin: 80
},
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#F5FCFF',
},
flowRight: {
flexDirection: 'column',
padding: 25,
alignItems: 'center',
alignSelf: 'stretch',
marginTop: 100,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
button: {
height: 36,
flex: 1,
flexDirection: 'row',
backgroundColor: '#009D6E',
borderColor: '#008C5D',
borderWidth: 1,
borderRadius: 8,
marginBottom: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
});
class Search extends Component {
render() {
return (
<View style={styles.searchView}>
<TextInput
style={{ flex: 2, height: 40, borderColor: 'gray', borderWidth: 1, padding: 5, borderRadius: 5}}
onChangeText={(text) => this.setState({input: text})}
placeholder="Search Appointment" />
<TextInput
style={{ flex: 1, height: 40, borderColor: 'gray', borderWidth: 1, padding: 5, borderRadius: 5}}
onChangeText={(text) => this.setState({input: text})}
placeholder="Location" />
</View>
);
}
}
class Welcome extends React.Component {
onExplorePressed() {
this.props.navigator.push({
title: 'Explore',
component: Search,
});
}
render() {
return (
<View style={styles.flowRight}>
<Text style={styles.welcome}>
Welcome to Docit!
</Text>
<TouchableHighlight style={styles.button} underlayColor='#009D3E'>
<Text style={styles.buttonText}>Sign In with Facebook</Text>
</TouchableHighlight>
<TouchableHighlight style={styles.button} underlayColor='#009D3E'>
<Text style={styles.buttonText}>Sign In with Email</Text>
</TouchableHighlight>
<Text style={styles.welcome}>OR</Text>
<TouchableHighlight
onPress={this.onExplorePressed.bind(this)}
style={styles.button}
underlayColor='#009D3E'>
<Text style={styles.buttonText}>Explore Something</Text>
</TouchableHighlight>
</View>
);
}
}
class ContentView extends Component {
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
component: Welcome,
title: 'Welcome',
}}/>
)
}
}
var Docit = React.createClass({
render: function() {
var menu = <Menu navigator={navigator}/>;
return (
<SideMenu menu={menu}>
<ContentView/>
</SideMenu>
);
}
});
AppRegistry.registerComponent('Something', () => Something);
Am I doing something wrong here ??
I figured out that react-native-carousel component was conflicting with sidebar menu component and showing a blank screen. I posted the issue on their repository.
The simple solution is remove react-native-carousel component from everywhere, even from node_modules/, the folder inside.
Your react versions could be out of sync. I've had this happen to me when the react version bundled with the iOS app is different than the version that the packager is running.
If you're using cocoapods, make sure that the react version in your podfile is the same as your package.json.

Resources