React Native Expo App Crashing due to Handmade component inside ScrollView - ios

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?

Related

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

React Native KeyboardAvoidingView not working properly

I am trying to use the KeyboardAvoidingView with behavior="padding".
When I am trying to enter any text in TextInput, the TextInput field is not moving up. I have added a small view in the end which is moving up but the the view above it.
I have also with KeyboardAvoidingView height property with offset. It was working few components like 2 TextInputs. But when I add all the components the UI goes insane and behave jumbled up.
Any any idea whats happening over here?
Here the link of tutorial which I have followed.
render() {
return (
<View style={styles.backgroundContainer}>
<Loader
loading={this.state.isLoading} />
<KeyboardAvoidingView
keyboardVerticalOffset={10}
style={styles.mainContainer}
behavior='padding' >
<View style={styles.formContainer}>
<View style={[styles.centerContainer, { marginTop: 40 }]}>
<Image source={require('./../../Resources/logo.png')} />
<Text style={{ fontWeight: 'bold', color: 'gray', fontSize: 25 }}>AppName</Text>
<Text style={styles.loginMsg}> Login to your Account </Text>
</View>
<View style={styles.inputFieldsContainer}>
<Image style={{ width: 30, height: 30, margin: 5 }} source={require('./../../Resources/logo.png')} />
<TextInput
placeholder='Email'
returnKeyType='next'
keyboardType='email-address'
onChangeText={(value) => this.setState({ userEmail: value })}
onSubmitEditing={() => this.passwordInput.focus()}
style={styles.inputFields} />
</View>
<View style={styles.inputFieldsContainer}>
<Image style={{ width: 30, height: 30, margin: 5, }} source={require('./../../Resources/logo.png')} />
<TextInput
returnKeyType='go'
secureTextEntry
placeholder='Password'
ref={(input) => this.passwordInput = input}
onChangeText={(value) => this.setState({ password: value })}
style={styles.inputFields} />
</View>
<View style={styles.buttonContainer}>
<Button
fontSize='8'
color='gray'
title='Remember Me'
onPress={() => {
console.log('Remember Me Clicked');
}} />
<Button
color='gray'
title='Forgot Password?'
onPress={() => {
console.log('Forgot Password Clicked');
}} />
</View>
<TouchableOpacity
style={styles.buttonLogin}
onPress={() => {
console.log('Login Clicked');
}}
>
<Text style={{ fontSize: 20, fontWeight: 'bold', color: 'white' }}>Login</Text>
</TouchableOpacity>
<View style={{ height: 1, backgroundColor: 'gray', marginTop: 20, marginBottom: 1 }}>
</View>
<View style={[styles.centerContainer, { marginBottom: 10 }]}>
<Text style={styles.loginMsg}>Don't have a Account</Text>
<TouchableOpacity
style={styles.buttonRegister}
onPress={() => navigate('Register')} >
<Text style={styles.buttonRegisterText}>REGISTER NOW</Text>
</TouchableOpacity>
</View>
</View>
<View style={{ height: 10, backgroundColor: '#628499', }}>
</View>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
backgroundContainer: {
flex: 1, backgroundColor: 'green'
},
mainContainer: {
flex: 1, margin: 25,
borderWidth: 1, borderRadius: 5, borderColor: 'gray',
backgroundColor: 'white',
justifyContent: 'space-between'
},
formContainer: {
flex: 1, paddingLeft: 25, paddingRight: 25
},
centerContainer: {
alignItems: 'center', marginBottom: 10,
},
loginMsg: {
margin: 10,
fontSize: 20, color: 'gray'
},
inputFieldsContainer: {
flexDirection: 'row', margin: 10,
borderWidth: 1, borderRadius: 5, borderColor: 'gray',
},
inputFields: {
flexGrow: 1,
marginTop: 5, marginBottom: 5,
height: 30,
backgroundColor: 'rgba(255,255,255,0.4)',
paddingHorizontal: 10,
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between'
},
buttonLogin: {
alignItems: 'center', height: 40, marginTop: 10, marginLeft: 50, marginRight: 50, padding: 5,
backgroundColor: '#2980b9',
borderWidth: 1, borderRadius: 5, borderColor: 'gray'
},
buttonRegister: {
alignItems: 'center', height: 40,
marginLeft: 50, marginRight: 50
},
buttonRegisterText: {
fontSize: 20, fontWeight: 'bold', color: 'gray'
},
loading: {
position: 'absolute',
left: 0, right: 0, top: 0, bottom: 0,
alignItems: 'center', justifyContent: 'center'
}, });
I used KeyboardAvoidingView, it also doesn't work.
I found this solution, You can take the base code.
Installation
npm i react-native-keyboard-aware-scroll-view --save
Usage
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
<KeyboardAwareScrollView>
<View>
<TextInput />
</View>
</KeyboardAwareScrollView>
You can find it here
The way it worked for me was to use position as behavior and -70 as vertical offset. Any non negative integer was creating a huge unused space when the keyboard pops up.
<KeyboardAvoidingView
style={styles.container}
behavior={Platform.OS === 'ios' ? 'position' : 'height'}
keyboardVerticalOffset={Platform.OS === 'ios' ? -70 : 70}
enabled>
<ScrollView>
...
</ScrollView>
</KeyboardAvoidingView>
<KeyboardAvoidingView
style={styles.mainContainer}
behavior="padding"
enabled
>
<View>.......................</View>
</KeyboardAvoidingView>
'Enabled or disabled KeyboardAvoidingView' should be add.
Keep in mind is always your top Parent with flex:1 then the child is then you text input container
<KeyboardAvoidingView style={{ flex: 1 }}
behavior={Platform.OS === "ios" ? "position" : null} enabled>
<ScrollView>
<View>
<View >
<Text maxFontSizeMultiplier={1.5} >
Sign in to your account{" "}
</Text>
<View
behavior="padding"
enabled
>
<TextInput
placeholder="Email address"
placeholderTextColor={Colors.grey}
style={styles.textInput}
onChangeText={(e) => setEmail(e.trim())}
autoCapitalize="none"
returnKeyType={"done"}
/>
</View>
</View>
</ScrollView>
</KeyboardAvoidingView>
// 2nd Solutions use this package
npm i react-native-keyboard-aware-scroll-view --save
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
<KeyboardAwareScrollView>
<View>
<TextInput />
</View>
</KeyboardAwareScrollView>

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 Grid View : Image messes up the view

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,
},

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