React Native: Requiring Unknow Module - react-native

I just started with react-native and was building this sample application:
xcode version: 6.2
OS : OS X 10.9.5
node version: 0.10.28
index.ios.js
var React = require('react-native');
var Main = require('./App/Components/Main');
var {
AppRegistry,
StyleSheet,
Text,
NavigatorIOS,
View,
} = React;
var styles = StyleSheet.create({
container:{
flex: 1,
backgroundColor: '#111111'
},
});
class githubNotetaker extends React.Component{
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
title: 'Github NoteTaker',
component: Main
}} />
);
}
};
AppRegistry.registerComponent('githubNotetaker', () => githubNotetaker);
Main.js
var React = require('react-native');
var {
View,
Text,
StyleSheet
} = React;
var styles = StyleSheet.create({
mainContainer: {
flex: 1,
padding: 30,
marginTop: 65,
flexDirection: 'column',
justifyContent: 'center',
backgroundColor: '#48BBEC'
},
title: {
marginBottom: 20,
fontSize: 25,
textAlign: 'center',
color: '#fff'
},
searchInput: {
height: 50,
padding: 4,
marginRight: 5,
fontSize: 23,
borderWidth: 1,
borderColor: 'white',
borderRadius: 8,
color: 'white'
},
buttonText: {
fontSize: 18,
color: '#111',
alignSelf: 'center'
},
button: {
height: 45,
flexDirection: 'row',
backgroundColor: 'white',
borderColor: 'white',
borderWidth: 1,
borderRadius: 8,
marginBottom: 10,
marginTop: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
});
class Main extends React.Component{
render() {
return(
<View style={styles.mainContainer}>
<Text> Testing the Router </Text>
</View>
)
}
};
module.exports = Main;
Error
I getting clueless why it is not able to location Main.js module.

Well,
The issue was little different.
In my file index.io.js I named my class as githubNotetaker while the project directory name was githubNoteTaker. I changed my class name to githubNoteTaker.
One more thing to add, also my tutorial didn't mention, I had to start npm serve using command npm start. I did that and application worked like a charm

Related

How to set one icon in left and text in center in header in react native

Am trying to set my icon in left and text in center (like Image which I have give) in header by using flex but they both are going in center how to solve it.
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Text,
View,
} from 'react-native'
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.cross}>X</Text>
<Text style={styles.headerText}>Invester Profile</Text>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
header: {
backgroundColor:'#212121',
height: 159.9,
flexDirection: 'row',
},
headerText: {
color: 'white',
marginTop: 20,
textAlign: 'center',
},
cross: {
color: 'white',
marginTop: 20,
}
})
Just add flex: 1 to headerText. Like this:
headerText: {
color: 'white',
marginTop: 20,
textAlign: 'center',
flex: 1
}

BoxShadow in react-native

I am trying to create a box-shadow around a view in react-native version 0.59.9
I have tried 'shadowOffSet' and all shadow properties but no use
import React, { Component } from 'react';
import { Text, View, StyleSheet, PixelRatio } from 'react-native';
const styles = {
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
},
}
export default class Card extends Component {
render() {
return (
<View style={styles.container}>
<View style={{
borderWidth: 1,
borderRadius: 20,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 20,
borderWidth: (1 / PixelRatio.getPixelSizeForLayoutSize(1)),
elevation: 1,
justifyContent: 'center',
alignItems: 'center',
overflow: this.props.overflow ? this.props.overflow : 'hidden',
width: 120,
height: 150}}>
<Text>Mine</Text>
</View>
</View>
);
}
}
The result is attached as screenshot
https://user-images.githubusercontent.com/14028306/60788321-0a283500-a17a-11e9-841d-5604982783ac.jpg
You can use the react native box shadow generator for the best practice.
https://ethercreative.github.io/react-native-shadow-generator/
please use this example for boxShow in react-native
import React, { Component } from 'react';
import { TouchableOpacity, StyleSheet, Text, View } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.buttonStyles}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
buttonStyles: {
backgroundColor: '#f2f2f2',
paddingVertical: 10,
width: '60%',
borderRadius: 10,
shadowColor: 'black',
shadowOpacity: 0.9,
elevation: 10,
},
welcome: {
fontSize: 20,
alignSelf: 'center',
}
});
Your code is valid on ios plateform for the bowShadow but for android you have to pass by the property elevation
Increasing the elevation parameter in your View style will increase the radius of the box-shadow on android devices:
https://snack.expo.io/S1NK7dxbr
As an aside, you have borderWidth listed twice as a style in your nested View component.

When we try to separate style files app doesn't render it shows spinner with background all time

image of CMD
Before doing it styles were on the same files. We cut all styles and pasted it on the separate file. Here is how it looks like.
import React, {Component} from "react";
import {Dimensions} from "react-native";
const win = Dimensions.get('window');
const styles={
content: {
justifyContent:'center'
},
img: {
flex: 1,
alignSelf: "stretch",
width: win.width,
height: win.height,
},
item:{
borderBottomColor: "#0dc49c"
},
icon:{
color: "#a4916c",
marginLeft: 10,
marginRight: 5
},
input:{
color: "#a4916c"
},
list:{
borderBottomWidth: 0,
borderTopWidth: 0,
borderBottomColor: "#a4916c",
},
contacticon: {
justifyContent: "center",
alignSelf: "center",
fontSize: 60,
fontWeight: "bold",
color: "#0dc49c",
marginBottom: 2,
},
contacttext: {
justifyContent: "center",
alignSelf: "center",
fontSize: 25,
color: "#0dc49c",
marginBottom: 180,
},
}
module.exports = styles;
When it was on the same files as components it was worked perfectly while because of duplicate styles we decided to separate them. What is wrong? How can it be fixed?
try using styles like this
import { StyleSheet } from "react-native";
const styles = StyleSheet.create({
content: {
justifyContent:'center'
},
});
module.exports = styles;
and import styles like this
import styles from "../styles/file

React-Native - Can't find variable: title

New React-Native installation. I am trying to set it up. In index.ios.js, I have:
class thingy extends Component {
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={(
title: 'Thingy',
component: Main
)} />
);
}
}
When I run this, the app gives me the error:
Can't find variable: title
I'm not sure why it's giving me this error. Any ideas?
Main Component:
var React = require('react-native');
var {
View,
Text,
StyleSheet
} = React;
var styles = StyleSheet.create({
mainContainer: {
flex: 1,
padding: 30,
marginTop: 65,
flexDirection: 'column',
justifyContent: 'center',
backgroundColor: '#48BBEC'
},
title: {
marginBottom: 20,
fontSize: 25,
textAlign: 'center',
color: '#fff'
},
searchInput: {
height: 50,
padding: 4,
marginRight: 5,
fontSize: 23,
bordderWidth: 1,
borderColor: 'white',
borderRadius: 8,
color: 'white'
},
buttonText: {
fontSize: 18,
color: '#111',
alignSelf: 'center'
},
button: {
height: 45,
flexDirection: 'row',
backgroundColor: 'white',
borderColor: 'white',
borderWidth: 1,
bordeRadius: 8,
marginBottom: 10,
marginTop: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
});
class Main extends React.Component{
render(){
return (
<View style={styles.mainContainer}>
<Text> Testing the Router </Text>
</View>
)
}
};
module.exports = Main;
Ah, it looks like initialRoute should be an object, but you have it wrapped in parenthesis:
How it is now:
initialRoute={(
title: 'Thingy',
component: Main
)}
Should actually be:
initialRoute={{
title: 'Thingy',
component: Main
}}

Not printed state in React Native

I'm now using React Native. Now I'm trying to print out one of states that are initialized ( for instance, showText herein ). When I recall this value in render, it doesn't show up ( blank ). The way that I recall is "{this.state.showText}". It doesn't produce any error messages.
Maybe because of the same reason, the initial value of TouchableHighlight seems to be blank. I'm completely lost here since a sample app in Facebook Github works fine within the website. Please give me any idea on this matter.
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ScrollView,
ListView,
TouchableHighlight,
TextInput
} from 'react-native';
class Greeting extends Component {
render() {
return (
<Text>Hello {this.props.name}! {this.props.date}~ Class can be added..{'\n'}</Text>
);
}
}
class Test1 extends Component {
constructor(props) {
super(props);
this.state = {
showText: 'true',
showTextBool: true,
wow: 'ddsdfasdf'
};
}
onSignupPress(){
return "hello";
}
render() {
let display = this.state.showTextBool ? 'true' : 'false';
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native! {this.state.showText} {this.state.showTextBool}
{this.state.wow}
</Text>
<TextInput style={styles.searchInput} value={this.state.wow} placeholder='Search via name or postcode'/>
<TouchableHighlight style={styles.button} underlayColor='#99d9f4'>
<Text style={styles.buttonText}>Go</Text>
</TouchableHighlight>
<Text style={styles.welcome}>
{display} + {this.onSignupPress()} + {this.state.showText}
</Text>
</View>
);
}
}
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,
},
buttonText: {
color: 'white',
alignSelf: 'center'
},
button: {
height: 36,
flex: 1,
flexDirection: 'row',
backgroundColor: '#48BBEC',
borderColor: '#48BBEC',
borderWidth: 1,
borderRadius: 8,
marginBottom: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
searchInput: {
height: 36,
padding: 4, marginRight: 5,
flex: 4,
fontSize: 18, borderWidth: 1, borderColor: '#48BBEC', borderRadius: 8, color: '#48BBEC'
}
});
AppRegistry.registerComponent('Test1', () => Test1);
I tried your code in react native express page. It renders one "true", but you are expected two (the text and the boolean). In the following part:
Welcome to React Native! {this.state.showText} {this.state.showTextBool}
The text is being rendered properly (it says indeed 'true'), but the boolean is not there, mainly because you cannot render a boolean like that. Try with the following:
{String(this.state.showTextBool)}
This will render the boolean value properly.