I have a file weatherProject.js :
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
You input {this.state.zip}.
</Text>
<Forecast
main={this.state.forecast.main}
description={this.state.forecast.description}
temp={this.state.forecast.temp}/>
<TextInput
style={styles.input}
returnKeyType='go'
onSubmitEditing={this._handleTextChange} />
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
input: {
fontSize: 20,
borderWidth: 2,
height: 40
}
});
weatherProject require the forecast module var Forecast = require('./Forecast');:
var Forecast = React.createClass({
render: function() {
return (
/*<View>
<Text style={styles.bigText}>
{this.props.main}
</Text>
<Text style={styles.mainText}>
Current conditions: {this.props.description}
</Text>
<Text style={styles.bigText}>
{this.props.temp}°F
</Text>
</View>*/
<View>
<Text style={styles.bigText}>
{this.props.main}
</Text>
<Text>
Current conditions: {this.props.description}
</Text>
<Text>
{this.props.temp}°F
</Text>
</View>
);
}
});
var styles = StyleSheet.create({
bigText: {
flex: 2,
fontSize: 20,
textAlign: 'center',
margin: 10,
color: '#FFFFFF'
},
mainText: {
flex: 1,
fontSize: 16,
textAlign: 'center',
color: '#FFFFFF'
}
})
module.exports = Forecast;
However, after integrating the forecast module, i don' t see the texts and inputs anymore on the android virtual mobile. my guess is that it' s coming from the styling and flexbox as the codes compile fine, if i remove the flex: 1 syntaxes its shows the texts, why according to you the present codes does not show anything on the screen ? ( my avd machine is a Nexus 4 model )
Thanks for your helps
Related
My modal -- noDevicesModalContainer -- is taking up an enormous amount of the screen and I can't work out why.
I am very new to React Native and web development generally, so please do not be afraid to overexplain!
Thank you in advance for your suggestions.
class DevicesEmptyScreen extends Component {
render() {
return (
<View style={styles.screen}>
<View style={styles.noDevicesImage}>
<Image
source={require('./../../../android/app/src/main/res/drawable/no_devices.png')}
/>
</View>
<View style={styles.noDevicesTextContainer}>
<Text style={styles.noDevicesText}>You do not have any devices yet</Text>
</View>
<View style={styles.noDevicesModalContainer}>
<Text style={[styles.noDevicesText, styles.noDevicesModalText]}>
In case no devices have been assigned, please contact your administrator
</Text>
</View>
</View>
)
}
}
export default DevicesEmptyScreen
const styles = StyleSheet.create({
screen: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
noDevicesImage: {
flex: 1,
marginTop: 40
},
noDevicesTextContainer: {
flex: 1,
justifyContent: 'center'
},
noDevicesText: {
color: '#89C7C8',
padding: 10
},
noDevicesModalContainer: {
flex: 1,
backgroundColor: '#EBF5F6',
borderRadius: 10,
marginHorizontal: 30,
marginVertical: 30
},
noDevicesModalText: {
marginLeft: 20
}
})
As per Modal documentation. Try this
<Modal transparent={true}
visible={this.state.isVisible}
onRequestClose={this.closeModal}>
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'}}>
<View style={{
width: 300,
height: 300}}>
...
</View>
</View>
</Modal>
I tried different solutions who had similar problem but none worked for me. My flatlist is not scrolling to the bottom and scroll bar goes out of the screen as i scroll down. In the flat list the item(LoneAlert)components that belong to the same day have a Date separator(Separator)component on top.
As the number of items increase in the list the number of items being pushed down aloso increase.ex: if the list contains 10 items, 1 items is pushed down , if the list has 25 items then 3 items are pushed down.
if I remove the Header Component then it works fine. But i don't know how to fix this. How do i do it?
I tried wrapping the flatList component with a view and giving a flex:1 to the view but it doesn't work.
in App.js, (there is no styling).
return (
<View>
<AlertList allAlert={this.state.alerts}/>
</View>
);
In AlertList.js
_renderItem = ({item, index}) => {
console.log(index);
console.log(item);
// if the alert day is equal to current day or
// alert day is equal to previous day or
// first alert day in the array is equal to current day
// separator bar display none for that alert by passing props showSeparator
if(current_day == item.alert_time.toDate().getDay()
|| index > 0 &&item.alert_time.toDate().getDay() == all_alerts[index -1].alert_time.toDate().getDay()
|| index==0 && item.alert_time.toDate().getDay() == current_day ){
return (
<LoneAlert
alertObject = {item} showSeparator ={false}/>
)
}else{
return(
<LoneAlert
alertObject = {item} showSeparator ={true}/>
)
}
};
checkConnection = () =>{
if (netInfo.isConnected == false || netInfo.isReachable == false ){
return <ConnectionMsg/>
}else{
return(
<View>
<HeaderBar/>
<View style = {{ flex:1 }}>
<FlatList data={props.allAlert}
renderItem = {this._renderItem}
/>
</View>
</View>
);
}
};
return(
<View>
{this.checkConnection()}
</View>
);
};
export default AlertList;
In LoneAlert.js (the items in side flatlist)
return(
<View>
<View>
{this.renderTimeSeparator(props.alertObject.alert_time.toDate(), props.showSeparator)}
</View>
<View style = {styles.wrapper}>
<View style = {styles.alertImageWrapper}>
{this.renderAlertImage(props.alertObject.alert_reason,70,70,'alertImage')}
</View>
<View style = {styles.textWrapper}>
<Text style = {styles.bedNumber}>{props.alertObject.bedNo}</Text>
{this.capitalizeAlertMessage(props.alertObject.alert_reason, styles.alertMessage)}
<Text style = {styles.dateTime}>{this.timeFormatConverter(props.alertObject.alert_time.toDate())}</Text>
</View>
<View style = {styles.dismissalWrapper}>
{this.renderDismissalImage(props.alertObject.dismissal_reason,30,30,styles.dismissalImage)}
{this.renderDismissalText(props.alertObject.dismissal_reason, styles.dismissalText)}
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
wrapper:{
flexDirection: 'row',
padding: 10,
paddingRight:0,
borderBottomWidth: 1,
borderBottomColor: "#D0D0D0",
backgroundColor: '#E7EAED',
},
alertImageWrapper:{
// backgroundColor: "red",
height:"100%",
width:60,
marginRight: 13,
flexDirection: 'row',
alignItems: 'center'
},
alertImage:{
},
textWrapper:{
// backgroundColor:"green"
paddingLeft: 15
},
bedNumber:{
color:"#434343",
fontFamily:"Arial",
fontWeight:'bold',
fontSize: 24,
},
alertMessage:{
color:"#434343",
fontFamily:"Arial",
fontWeight:'bold',
fontSize: 14,
},
dateTime:{
color:"#434343",
fontFamily:"Arial",
fontSize: 14,
},
dismissalWrapper:{
marginLeft: 'auto',
// backgroundColor:"green",
width:70,
},
dismissalImage:{
marginLeft: 'auto',
marginRight:'auto',
// backgroundColor:"red"
},
dismissalText:{
// backgroundColor:"blue",
textAlign: 'center'
}
});
export default LoneAlert;
In Separator.js
render(){
return(
<View style={styles.Bar}>
<Text style ={styles.dateStyle}>{this.props.date[0]},
{this.props.date[1]} {this.props.date[2]}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
Bar:{
// height: 34,
paddingTop: 5,
paddingLeft: 10,
// backgroundColor: "#7C7C7C",
backgroundColor: '#E7EAED',
fontFamily:"Arial",
fontWeight:'bold',
fontSize: 14,
color:"#FFFFFF",
textAlign: "center",
flexDirection: 'row',
alignItems: 'center'
},
dateStyle:{
// backgroundColor: 'blue',
color:"#9B9B9B",
fontWeight:'bold',
}
});
export default Separator;
In HeaderBar.js
const HeaderBar = (props) => {
return(
<View>
<View style={styles.HeaderBar}>
<Image style = {styles.spIcon} source={require('../../assets/images/smartPeep-icon.png')}/>
<Text style = {styles.alertTitle}>
Alert history
</Text>
</View>
<View style = {styles.FirstSeparator}>
<Text style = {styles.AlertDetailLabel}>Alert Type</Text>
<Text style = {styles.DismissalLabel}>Resolved by</Text>
</View>
</View>
)
};
const styles = StyleSheet.create({
HeaderBar:{
width: "100%",
padding: 7,
backgroundColor:"#E7EAED",
height:58,
flexDirection: 'row',
alignItems: "center"
},
spIcon:{
width: 40,
marginRight: 22,
height: "100%",
// backgroundColor: "green"
},
alertTitle:{
maxWidth:180,
fontFamily:"Arial",
fontWeight:'bold',
fontSize: 18,
// backgroundColor: "blue"
},
FirstSeparator:{
height: 35,
backgroundColor:"#434343",
flexDirection: 'row',
},
AlertDetailLabel:{
// backgroundColor:"red",
fontFamily:"Arial",
fontSize: 14,
color: "white",
textAlignVertical:'center',
paddingLeft: 10
},
DismissalLabel:{
marginLeft: 'auto',
fontFamily:"Arial",
fontSize: 14,
color: "white",
textAlignVertical:'center',
paddingRight: 10
}
});
export default HeaderBar;
OK i was able to fix this by addding flex:1 on View in App.js and then setting the height to 100% of parent View in AlertList.js
App.js
<View style = {{ flex: 1}}>
<AlertList allAlert={this.state.alerts}/>
</View>
AlerList.js
<View style = {{ height:"100%"}}>
<HeaderBar/>
<FlatList data={props.allAlert}
renderItem = {this._renderItem}
/>
</View>
I need to align two Text component with different fontSize in a row and vertically centered. I have following now https://snack.expo.io/#troublediehard/dmVuZ2
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.row}>
<Text style={styles.text1}>Font size 20</Text>
<Text style={styles.text2}>Font size 14</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
row: {
flexDirection: 'row',
backgroundColor: 'red',
},
text1: {
fontSize: 20,
backgroundColor: 'blue',
},
text2: {
fontSize: 14,
backgroundColor: 'green',
},
});
For anyone that didn't found a solution yet, you have to wrap the text within another Text tag:
<View style={styles.container}>
<View style={styles.row}>
<Text>
<Text style={styles.text1}>Font size 20</Text>
<Text style={styles.text2}>Font size 14</Text>
</Text>
</View>
</View>
You need to add alignItems: 'center' to styles.row
row: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'red',
},
I copied straight from the documentation here:
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<View style={styles.main}>
<ViewPagerAndroid style={styles.viewPager} initialPage={0}>
<View style={styles.pageStyle}>
<Text>First page</Text>
</View>
<View style={styles.pageStyle}>
<Text>Second page</Text>
</View>
</ViewPagerAndroid>
</View>
</View>
And my stylesheet:
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
main: {
backgroundColor: 'pink',
height: 300
},
viewPager: {
height: 100,
backgroundColor: 'skyblue'
},
pageStyle: {
padding: 20,
width: 100,
height: 100,
backgroundColor: 'green',
flex: 1
}
});
All is the pink and skyblue rectangles. I have no idea why the child is not rendering. Does anyone have any ideas?
I've been struggling with Navigator in React Native Web for a good 2 days now and can't figure out what the problem is. It is worth noting that before attempting to use the Navigator, everything was working fine, and this code is running on a browser. I have the following code below and keep getting the error message:
"bundle.js:784 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of Home."
Followed by:
"bundle.js:640 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of Home."
Basically, I have a component called "Home" and I am trying to renderScene using the Navigator fairly deeply nested in this component but it isn't working. I have used this same Navigator code on another app and it worked, minus a few changes in the props passed. Any help would be greatly appreciated!
const React = require('react-native-web')
const {
Text,
View,
StyleSheet,
Image,
Navigator,
TouchableHighlight,
Component
} = React;
var Home = React.createClass({
renderScene(route, navigator) {
if(route.name == 'Baseball') {
return <Baseball navigator={navigator} {...route.passProps} />
}
if(route.name == 'Football') {
return <Football navigator={navigator} {...route.passProps} />
}
},
render() {
return (
<View>
<View>
<Image
style={styles.homeImage}
source={require('./img/baseball.png')}>
<View style={styles.tagLineWrapper}>
<Text style={styles.tagLine}>
Real Sports.
</Text>
<Text style={styles.tagLine}>
Real Skill.
</Text>
<Text style={styles.tagLine}>
Real Prizes.
</Text>
</View>
</Image>
</View>
<View style = {styles.appStoreBar}>
<Text style={styles.darkText}>
Available Now!
</Text>
<View style={styles.appStoreButton}>
<Image
style={styles.button}
source={require('./img/app-store-button-yellow.png')}
/>
</View>
</View>
<Text style = {styles.instructionsHeader}>
How Pick a Play Works
</Text>
<View style = {styles.doubleIphoneWrapper}>
<View style = {styles.singleIphoneWrapper}>
<Text style = {styles.instructionsSubHeaderText}>
1. Pick a Contest
</Text>
<View style={styles.instructionsWrapper}>
<Text style={styles.instructions}>
Pick 5, 6, or 7 correctly and win the amount shown on the right.
</Text>
</View>
<View style={styles.iphoneAndChevronWrapper}>
<Image
style={styles.chevronIcons}
source={require('./img/chevron-left.png')}
/>
<View style={styles.iphoneAndScreenWrapper}>
<Image
style={styles.iphone}
source={require('./img/iphone5-vertical.png')} >
<Navigator
initialRoute={{name: 'Baseball'}}
renderScene={this.renderScene} />
</Image>
</View>
<Image
style={styles.chevronIcons}
source={require('./img/chevron-right.png')}
/>
</View>
</View>
<View style = {styles.singleIphoneWrapper}>
<Text style = {styles.instructionsSubHeaderText}>
1. Pick a Game
</Text>
<View style={styles.instructionsWrapper}>
<Text style={styles.instructions}>
Make sure it’s a game you are available to watch in real time.
</Text>
</View>
<View style={styles.iphoneAndChevronWrapper}>
<Image
style={styles.chevronIcons}
source={require('./img/chevron-left.png')}
/>
<Image
style={styles.iphone}
source={require('./img/iphone5-vertical.png')}>
</Image>
<Image
style={styles.chevronIcons}
source={require('./img/chevron-right.png')}
/>
</View>
</View>
</View>
</View>
)
}
})
var Baseball = React.createClass({
_navigate(name) {
this.props.navigator.push({
name: 'Football',
passProps: {
name: name
}
})
},
render() {
return (
<View style={[styles.screenView, {backgroundColor: 'blue'}]}>
</View>
)
}
})
var Football = React.createClass({
_navigate(name) {
this.props.navigator.push({
name: 'Baseball',
passProps: {
name: name
}
})
},
render() {
return (
<View style={[styles.screenView, {backgroundColor: 'green'}]}>
</View>
)
}
})
const styles = StyleSheet.create({
homeText: {
color: '#1C1C1C',
fontFamily: '"Helvetica Neue", Helvetica, Arial, sans-serif'
},
homeImage: {
maxHeight: 350,
flex: 0
},
tagLineWrapper: {
alignSelf: 'flex-end',
marginRight: 200,
marginTop: 220
},
tagLine: {
fontSize: 20,
fontStyle: 'italic',
color: 'white',
alignSelf: 'flex-start',
marginTop: 10,
fontFamily: '"Helvetica Neue", Helvetica, Arial, sans-serif'
},
instructionsHeader: {
fontSize: 27,
fontWeight: 'bold',
marginTop: 40,
color: '#1C1C1C',
alignSelf: 'center'
},
doubleIphoneWrapper: {
flexDirection: 'row',
justifyContent: 'center'
},
singleIphoneWrapper: {
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
margin: 40
},
instructionsSubHeaderText: {
fontSize: 18,
color: '#1C1C1C',
marginTop: 60,
alignSelf: 'center'
},
instructionsWrapper: {
width: 194,
height: 64,
alignSelf: 'center'
},
instructions: {
fontSize: 13,
padding: 20,
textAlign: "center"
},
appStoreBar: {
alignSelf: 'stretch',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
padding: 30,
backgroundColor: '#ededed'
},
darkText: {
fontSize: 24,
color: '#1C1C1C',
marginRight: 10
},
appStoreButton: {
width: 200,
marginLeft: 10
},
iphone: {
width: 300,
margin: 30
},
chevronIcons: {
height: 30,
alignSelf: 'center',
margin: 0
},
iphoneAndChevronWrapper: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
screenView: {
height: 338,
width: 192,
alignSelf: 'center',
marginTop: 100,
},
iphoneAndScreenWrapper: {
justifyContent: 'center',
alignItems: 'center',
}
})
module.exports = Home;
This might be late, but you should know that React Native Navigator does not work with React Native Web. But I guess there are some alternative solutions though. I don't remember at the top of my head at the moment.