I have to implement fingerprint Authentication in my app , so i have installed react-native-fingerprint-scanner but the code is not working as i am getting this error
Here is my code
import React, { Component, PropTypes } from 'react';
import {
Alert,
Image,
Text,
TouchableOpacity,
View,
ViewPropTypes,
StyleSheet
} from 'react-native';
import FingerprintScanner from 'react-native-fingerprint-scanner';
import ShakingText from './ShakingText';
class FingerprintPopup extends Component {
constructor(props) {
super(props);
this.state = { errorMessage: undefined };
}
componentDidMount() {
FingerprintScanner
.authenticate({ onAttempt: this.handleAuthenticationAttempted })
.then(() => {
this.props.handlePopupDismissed();
Alert.alert('Fingerprint Authentication', 'Authenticated successfully');
})
.catch((error) => {
this.setState({ errorMessage: error.message });
this.description.shake();
});
}
componentWillUnmount() {
FingerprintScanner.release();
}
handleAuthenticationAttempted = (error) => {
this.setState({ errorMessage: error.message });
this.description.shake();
};
render() {
const { errorMessage } = this.state;
const { style, handlePopupDismissed } = this.props;
return (
<View style={styles.container}>
<View style={[styles.contentContainer, style]}>
<Image
style={styles.logo}
source={require('../assets/finger_print.png')}
/>
<Text style={styles.heading}>
Fingerprint{'\n'}Authentication
</Text>
<ShakingText
ref={(instance) => { this.description = instance; }}
style={styles.description(!!errorMessage)}>
{errorMessage || 'Scan your fingerprint on the\ndevice scanner to continue'}
</ShakingText>
<TouchableOpacity
style={styles.buttonContainer}
onPress={handlePopupDismissed}
>
<Text style={styles.buttonText}>
BACK TO MAIN
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
FingerprintPopup.propTypes = {
style: ViewPropTypes.style,
handlePopupDismissed: PropTypes.func.isRequired,
};
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
backgroundColor: 'rgba(0, 164, 222, 0.9)',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
contentContainer: {
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#ffffff',
},
logo: {
marginVertical: 45,
},
heading: {
textAlign: 'center',
color: '#00a4de',
fontSize: 21,
},
description: (error) => ({
textAlign: 'center',
color: error ? '#ea3d13' : '#a5a5a5',
height: 65,
fontSize: 18,
marginVertical: 10,
marginHorizontal: 20,
}),
buttonContainer: {
padding: 20,
},
buttonText: {
color: '#8fbc5a',
fontSize: 15,
fontWeight: 'bold',
},
});
export default FingerprintPopup;
I am getting this error react.PropTypes.oneOfType ,I am not sure where it is going wrong .
Please help me how to solve this.
PropTypes are moved to individual library,
import it like this,
import PropTypes from "prop-types";
you do not need to install it because it comes with react native
Related
I want to store username to local storage using #react-native-async-storage/async-storage in React Native. When I checked through console.log, username was saved successfully but while retrieving the data back to different screen using getData function, It says null. Help me to figure out the issue.
this is my storage.js file where I've kept all the Async Storage functions.
import AsyncStorage from '#react-native-async-storage/async-storage';
const storeData = async (key, value) => {
try {
await AsyncStorage.setItem(key, value)
} catch (e) {
console.log('Error on saving')
}
}
const getData = async (key) => {
try {
const value = await AsyncStorage.getItem(key)
if (value !== null) {
console.log('Promise', value)
return value
}
} catch (e) {
// error reading value
}
}
export { storeData, getData };
this is my Log In Screen file
import React, { Component, useState } from 'react';
import { View, Text, Button, ScrollView, TextInput, TouchableHighlight, StyleSheet } from 'react-native';
import * as yup from 'yup'
import { Formik } from 'formik'
import { storeData } from '../utils/storage';
const Login = (props) => {
const handleLogin = (name) => {
storeData('username',name)
props.navigation.navigate('Home')
}
return (
<Formik
initialValues={{
name: '',
password: ''
}}
onSubmit={values => Alert.alert(JSON.stringify(values))}
validationSchema={yup.object().shape({
name: yup
.string()
.required('Please, provide your name!'),
password: yup
.string()
.min(4)
.max(10, 'Password should not excced 10 chars.')
.required(),
})}
>
{({ values, handleChange, errors, setFieldTouched, touched, isValid, handleSubmit }) => (
<ScrollView style={styles.scrollb}>
<View style={styles.container}>
<Text style={styles.title}>LOGIN PAGE</Text>
<Text style={styles.subtitle}>Welcome Back.</Text>
</View>
<View style={styles.container2}>
<TextInput
style={styles.tinput}
placeholder="Username"
value={values.name}
onChangeText={handleChange('name')}
onBlur={() => setFieldTouched('name')}
/>
{touched.name && errors.name &&
<Text style={{ fontSize: 12, color: '#FF0D10' }}>{errors.name}</Text>
}
</View>
<View style={styles.container2}>
<TextInput
style={styles.tinput}
placeholder="Password"
value={values.password}
onChangeText={handleChange('password')}
placeholder="Password"
onBlur={() => setFieldTouched('password')}
secureTextEntry={true}
/>
{touched.password && errors.password &&
<Text style={{ fontSize: 12, color: '#FF0D10' }}>{errors.password}</Text>
}
</View>
<View style={styles.container3}>
<TouchableHighlight
style={{
borderRadius: 10,
}}>
<Button
title="Login"
borderRadius={25}
containerViewStyle={{ borderRadius: 25 }}
buttonStyle={{ width: 145, height: 45, borderRadius: 25 }}
accessibilityLabel="Learn more about this button"
onPress={() => handleLogin(values.name)}
disabled={!isValid}
/>
</TouchableHighlight>
</View>
</ScrollView>
)}
</Formik>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
backgroundColor: "#61dafb",
},
container2: {
flex: 1,
paddingTop: 14,
paddingHorizontal: 24,
backgroundColor: "#61dafb",
},
container3: {
flex: 1,
paddingTop: 284,
paddingHorizontal: 34,
backgroundColor: "#61dafb",
borderRadius: 40,
},
title: {
marginTop: 16,
borderRadius: 6,
backgroundColor: "#61dafb",
color: "white",
textAlign: "center",
fontSize: 50,
fontWeight: "bold",
},
subtitle: {
borderRadius: 6,
paddingLeft: 33,
backgroundColor: "#61dafb",
color: "white",
textAlign: "left",
fontSize: 30,
fontWeight: '400',
},
tinput: {
height: 50,
textAlign: "center",
paddingVertical: 8,
backgroundColor: "white",
borderRadius: 27,
},
scrollb: {
backgroundColor: "#61dafb",
},
});
export default Login;
This is my Home screen file. Where I want to retrieve that username from Login Page via async storage.
import React, { Component, useEffect, useState } from 'react';
import { View, Text, ScrollView, TouchableHighlight, Image, StyleSheet } from 'react-native';
import { getData } from '../utils/storage';
const Home = (props) => {
const [username, setUsername] = useState('');
useEffect(() => {
getData('username')
console.log('useEffect',getData('username'))
}, [])
const CategoriesAr = [
{
name: "Business",
path: "Business",
imgURL: "https://img.icons8.com/clouds/100/000000/analytics.png",
},
{
name: "Technology",
path: "Technology",
imgURL: "https://img.icons8.com/clouds/100/000000/transaction-list.png",
},
{
name: "Science",
path: "Science",
imgURL: "https://img.icons8.com/clouds/100/000000/innovation.png",
},
{
name: "Health",
path: "Health",
imgURL: "https://img.icons8.com/clouds/100/000000/client-company.png",
}
]
const GridItem = (gridProps) => {
const { data } = gridProps;
return (
<>
<TouchableHighlight onPress={() => props.navigation.navigate(data.path)}>
<View style={styles.card}>
<View style={styles.header}>
<Text style={{ fontWeight: "bold", fontSize: 18 }}>{data.name}</Text>
</View>
<View style={styles.imgbody}>
<Image
style={styles.tinyLogo}
source={{
uri: data.imgURL,
}}
/>
</View>
</View>
</TouchableHighlight>
</>
)
}
return (
<ScrollView style={styles.sclb}>
<Text style={styles.title}>Hi {username}</Text>
<View style={styles.containerX}>
{CategoriesAr.map((item) => <GridItem data={item} />)}
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
title: {
marginTop: 16,
borderRadius: 6,
backgroundColor: "#61dafb",
color: "white",
textAlign: "center",
fontSize: 50,
fontWeight: "bold",
},
containerX: {
flex: 1,
flexWrap: "wrap",
marginTop: 8,
maxHeight: 400,
backgroundColor: "#61dafb",
},
card: {
height: 150,
width: 150,
backgroundColor: "white",
alignItems: "center",
borderRadius: 15,
elevation: 10,
padding: 10,
margin: 22,
},
imgbody: {
paddingTop: 20,
},
tinyLogo: {
height: 90,
width: 90,
},
header: {
flexDirection: "row",
},
sclb: {
backgroundColor: "#61dafb",
}
});
export default Home;
You need to put await before getData like this.
useEffect(() => {
(async()=>{
await getData('username')
console.log('useEffect',await getData('username'))
})();
}, [])
useEffect(() => {
CallMethod()
}, [])
const CallMethod = async() =>{
await getData('username')
}
I'm trying to develop an app with React Native.
When I clicked on any product, I can see the product detail page correctly. But for the second click, the same product always appears as keep in a cache or something.
What am I missing out?
Maybe it is a state problem but I cannot figure it out.
Product Listing Page:
import { NavigationHelpersContext } from "#react-navigation/core";
import React, { Component } from "react";
import {
SafeAreaView,
ScrollView,
StatusBar,
View,
StyleSheet,
FlatList,
Text,
Image,
TouchableOpacity,
Alert,
useColorScheme,
} from "react-native";
import { getData } from "./loadData";
export default class Pekmez extends Component {
constructor(props) {
super(props);
this.state = {
refreshFlag: (Boolean = false),
data: [],
};
}
componentDidMount() {
this._unsubscribe = this.props.navigation.addListener("focus", () => {
const { route, navigation } = this.props;
const { params } = route;
console.log("_KAT fetch params:", params);
let suffix = "Product/" + params.id;
console.log("_KAT product:", suffix);
getData(suffix, "GET").then((val) => {
this.setState({ data: val.data }, () => {
console.log("state=>", this.state);
});
});
});
//id gelecek
//fetch
}
clickEventListener(item) {
this.props.navigation.navigate("UrunDetay", { ...item });
}
render() {
return (
<View style={styles.container}>
<View style={styles.headerbar}>
<Text style={styles.pagetitle}>Ürünler</Text>
</View>
<FlatList
style={styles.list}
contentContainerStyle={styles.listContainer}
data={this.state.data}
horizontal={false}
numColumns={2}
keyExtractor={(item) => {
return item.id;
}}
renderItem={({ item }) => {
return (
<TouchableOpacity
style={styles.card}
onPress={() => {
this.clickEventListener(item);
}}
>
<View style={styles.cardFooter}></View>
<Image
style={styles.cardImage}
source={{
uri:
"https://www.toptankoyurunleri.com/Uploads/Products/" +
item.id +
"/" +
item.filename,
}}
/>
<View style={styles.cardHeader}>
<View
style={{ alignItems: "center", justifyContent: "center" }}
>
<Text style={styles.title}>{item.title}</Text>
</View>
</View>
</TouchableOpacity>
);
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
headerbar: {
height: 55,
backgroundColor: "#f27a1a",
alignItems: "center",
justifyContent: "center",
paddingVertical: 15,
marginBottom: 10,
},
pagetitle: {
fontSize: 18,
flex: 1,
alignSelf: "center",
color: "#fff",
fontWeight: "bold",
},
container: {
flex: 1,
marginTop: 0,
},
list: {
paddingHorizontal: 5,
},
listContainer: {
alignItems: "center",
},
/******** card **************/
card: {
shadowColor: "#00000021",
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.37,
shadowRadius: 7.49,
elevation: 12,
marginVertical: 10,
backgroundColor: "white",
flexBasis: "42%",
marginHorizontal: 10,
},
cardHeader: {
paddingVertical: 10,
paddingHorizontal: 5,
borderTopLeftRadius: 1,
borderTopRightRadius: 1,
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
cardContent: {
paddingVertical: 5,
paddingHorizontal: 6,
},
cardFooter: {
flexDirection: "row",
justifyContent: "space-between",
paddingTop: 5,
paddingBottom: 5,
paddingHorizontal: 10,
borderBottomLeftRadius: 1,
borderBottomRightRadius: 1,
},
cardImage: {
height: 150,
width: 150,
alignSelf: "center",
},
title: {
fontSize: 13,
flex: 1,
alignSelf: "center",
color: "#696969",
fontWeight: "bold",
},
});
Product Detail Page
import React, { Component } from "react";
import {
SafeAreaView,
TouchableOpacity,
ScrollView,
StatusBar,
View,
StyleSheet,
Text,
Image,
useColorScheme,
Button,
BackHandler,
} from "react-native";
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from "react-native/Libraries/NewAppScreen";
import { WebView } from "react-native-webview";
export default class UrunDetay extends Component {
constructor(props) {
super(props);
this.state = {
detailData: {},
};
}
componentDidMount() {
console.log("this props detail:", JSON.stringify(this.props));
const { route, navigation } = this.props;
const { params } = route;
console.log("params:", params);
this.setState({ detailData: params });
}
render() {
const { detailData } = this.state;
console.log("deail:", this.props.navigation);
let vw = <Text>Loading...</Text>;
if (detailData.id && detailData.id > 0) {
vw = (
<View style={styles.container}>
<View style={styles.headerbar}>
<Text style={styles.pagetitle}>{this.state.detailData.title}</Text>
</View>
<WebView
source={{
uri:
"https://app.toptankoyurunleri.com/urun/urunadi/" +
this.state.detailData.id,
forceReload: this.state.forceReload,
}}
style={{ marginTop: 55 }}
/>
</View>
);
}
return vw;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
headerbar: {
height: 55,
backgroundColor: "#fff",
flex: 1,
position: "absolute",
top: 0,
width: "100%",
paddingBottom: 15,
paddingTop: 15,
},
pagetitle: {
fontSize: 18,
flex: 1,
alignSelf: "center",
color: "#000",
fontWeight: "bold",
},
});
Where did you map your item in your list ? It appear to keep the same item or item.id in your state can you make test with breakpoints on your browser tool ?
I have some problems with AsyncStorage and i was hoping that you can help me out. I have to write some notes and save them so when I open the app again, they will be displayed on a ListView.
Here are the classes I used:
Notes.js:
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
} from 'react-native';
export default class Note extends Component {
render() {
return (
<View key={this.props.keyval} style={styles.note}>
<Text style={styles.noteText}>{this.props.val.date}</Text>
<Text style={styles.noteText}>{this.props.val.note}</Text>
<TouchableOpacity onPress={this.props.deleteMethod} style={styles.noteDelete}>
<Text style={styles.noteDeleteText}>Del</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
note: {
position: 'relative',
padding: 20,
paddingRight: 100,
borderBottomWidth:2,
borderBottomColor: '#ededed'
},
noteText: {
paddingLeft: 20,
borderLeftWidth: 10,
borderLeftColor: '#0000FF'
},
noteDelete: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2980b9',
padding: 10,
top: 10,
bottom: 10,
right: 10
},
noteDeleteText: {
color: 'white'
}
});
This is the component that I use every time when I want to create a note.
Main.js:
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TextInput,
ScrollView,
TouchableOpacity,
AsyncStorage,
} from 'react-native';
import Note from './Note';
export default class Main extends Component {
constructor(props){
super(props);
this.state = {
noteArray: [],
noteText: '',
};
this.getSavedNotes(this.state.noteArray);
}
render() {
let notes = this.state.noteArray.map((val, key)=>{
return <Note key={key} keyval={key} val={val}
deleteMethod={()=>this.deleteNote(key)}/>
});
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.headerText}>- NOTER -</Text>
</View>
<ScrollView style={styles.scrollContainer}>
{notes}
</ScrollView>
<View style={styles.footer}>
<TextInput
style={styles.textInput}
placeholder='Write your note here'
onChangeText={(noteText)=> this.setState({noteText})}
value={this.state.noteText}
placeholderTextColor='white'
underlineColorAndroid='transparent'>
</TextInput>
</View>
<TouchableOpacity onPress={ this.addNote.bind(this) } style={styles.addButton}>
<Text style={styles.addButtonText}>+</Text>
</TouchableOpacity>
</View>
);
}
addNote(){
if(this.state.noteText){
var d = new Date();
this.state.noteArray.push({
'date':d.getFullYear()+
"/"+(d.getMonth()+1) +
"/"+ d.getDate(),
'note': this.state.noteText
});
this.setState({ noteArray: this.state.noteArray });
this.setState({noteText:''});
AsyncStorage.setItem('arr', JSON.stringify(this.state.noteArray));
alert(this.state.noteArray);
}
}
deleteNote(key){
this.state.noteArray.splice(key, 1);
this.setState({noteArray: this.state.noteArray});
}
getSavedNotes = async (noteArray) =>{
try{
let data = await AsyncStorage.getItem('arr');
if(JSON.parse(data))
{
this.state.noteArray = JSON.parse(data);v
}
}catch(error){
alert(error);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
header: {
backgroundColor: '#1A237E',
alignItems: 'center',
justifyContent:'center',
borderBottomWidth: 10,
borderBottomColor: '#ddd'
},
headerText: {
color: 'white',
fontSize: 18,
padding: 26
},
scrollContainer: {
flex: 1,
marginBottom: 100
},
footer: {
position: 'absolute',
bottom: 0,
backgroundColor: '#000000',
left: 0,
right: 70,
zIndex: 10
},
textInput: {
alignSelf: 'stretch',
color: '#fff',
padding: 20,
backgroundColor: '#252525',
borderTopWidth:2,
borderTopColor: '#ededed'
},
addButton: {
position: 'absolute',
zIndex: 11,
right: 0,
bottom: 0,
backgroundColor: '#1A237E',
width: 70,
height: 68,
// borderRadius: 35,
alignItems: 'center',
justifyContent: 'center',
elevation: 8
},
addButtonText: {
color: '#fff',
fontSize: 24
}
});
Here is where I try to save the notes. It seems like the notes are saved but they are not displayed as I open the app. They are displayed only after I tape a letter in the text box.
Finally the App.js:
import React, { Component } from 'react';
import Main from './app/components/Main.js';
export default class App extends Component {
render() {
return (
<Main/>
);
}
}
Here I just display the Main.js component.
getSavedNotes = async (noteArray) =>{
try{
let data = await AsyncStorage.getItem('arr');
data = JSON.parse(data);
this.setState({noteArray:data}) //assuming data as array of notes
}catch(error){
alert(error);
}
}
I am using the tab navigator in stack navigator ..when in tab navigator i move to next tab there a little bit pause then move to next tab...the code of index file is
import React, { Component } from 'react';
import { AppRegistry,Alert,ScrollView, Image, Dimensions,
Text,View,TouchableOpacity,StyleSheet} from 'react-native'
import Login from './login'
import SignUp from './signup'
import forget from './forget'
import Tabo from './DefaultTabBar'
import { StackNavigator,TabNavigator } from 'react-navigation';
import HomeButton from './HomeButton'
import ProfileScreen from './ProfileScreen'
import Granjur from './granjur'
const background=require("./flag/1.jpg");
export default class TabViewExample extends Component {
render(){
const { navigation } = this.props;
return(
<App navigation={ navigation }/>
);
}
}
const MyApp = TabNavigator({
Home: {
screen: HomeButton,
},
Notifications: {
screen: ProfileScreen,
},
},
{
swipeEnabled:false,
initialRouteName: 'Home',
tabBarOptions: {
activeTintColor: '#e91e63',
},
});
const Simple = StackNavigator({
Login: {
screen: Login,
},
signup: {
screen: SignUp,
},
forget:{
screen:forget
},
dashbord:{
screen:Granjur
}
});
AppRegistry.registerComponent('TabNavigator', () => Simple);
i also use scrollable tabView in that tab view also that problem occur..In second tab i have a swipable list view may be due to this error come how i resolv this the code for profile screen is that
import React, {
Component,
} from 'react';
import {
AppRegistry,
ListView,
StyleSheet,
Text,
TouchableOpacity,
TouchableHighlight,
View,
Alert,
Dimensions
} from 'react-native';
import { SwipeListView, SwipeRow } from 'react-native-swipe-list-view';
var alertMessage="You want to Delete it";
var alertMessage1='why press it'
var v1=1.0;
const wid=Dimensions.get('window').width;
export default class App extends Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
basic: true,
listViewData: Array(5).fill('').map((_,i)=>`item #${i}`)
};
}
deleteRow(secId, rowId, rowMap) {
rowMap[`${secId}${rowId}`].closeRow();
const newData = [...this.state.listViewData];
newData.splice(rowId, 1);
this.setState({listViewData: newData});
}
// undoRow(rowId) {
// const newData = [...this.state.listViewData];
// this.setState({listViewData: newData});
// this.setState({listViewData: newData});
// }
render() {
return (
<SwipeListView
dataSource={this.ds.cloneWithRows(this.state.listViewData)}
renderRow={ data => (
<TouchableHighlight
onPress={ _ => Alert.alert(
'Alert Title',
alertMessage1,
) }
style={styles.rowFront}
underlayColor={'#AAA'}
>
<Text>I am {data} in a SwipeListView</Text>
</TouchableHighlight>
)}
renderHiddenRow={ (data, secId, rowId, rowMap) => (
<View style={styles.rowBack}>
<TouchableOpacity style={{backgroundColor:'#2c3e50',alignItems: 'center',bottom: 0,justifyContent: 'center',position: 'absolute',top: 0,width: 75}}
onPress={ _ => rowMap[ `${secId}${rowId}` ].closeRow() } >
<Text style={styles.backTextWhite}>Undo</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.backRightBtn, styles.backRightBtnRight]}
onPress={ _ => Alert.alert(
'Are You Sure',alertMessage,
[{text: 'OK', onPress: () =>this.deleteRow(secId, rowId, rowMap)},
{text: 'Cancel',}]
) }>
<Text style=
{styles.backTextWhite}>Delete</Text>
</TouchableOpacity>
</View>
)}
leftOpenValue={wid}
rightOpenValue={-wid}
disableLeftSwipe={true}
/>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1
},
standalone: {
marginTop: 30,
marginBottom: 30,
},
standaloneRowFront: {
alignItems: 'center',
backgroundColor: '#CCC',
justifyContent: 'center',
height: 50,
},
standaloneRowBack: {
alignItems: 'center',
backgroundColor: '#8BC645',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
padding: 15
},
backTextWhite: {
color: '#FFF'
},
rowFront: {
alignItems: 'center',
backgroundColor: '#CCC',
borderBottomColor: 'black',
borderBottomWidth: 1,
justifyContent: 'center',
height: 50,
},
rowBack: {
alignItems: 'center',
backgroundColor: '#DDD',
flex: 1,
flexDirection: 'row',
//justifyContent: 'space-between',
paddingLeft: 15,
},
backRightBtn: {
alignItems: 'center',
bottom: 0,
justifyContent: 'center',
position: 'absolute',
top: 0,
width: 75
},
backRightBtnLeft: {
backgroundColor: 'blue',
//right: 75
},
backRightBtnRight: {
backgroundColor: '#2c3e50',
right: 0
},
controls: {
alignItems: 'center',
marginBottom: 30
},
switchContainer: {
flexDirection: 'row',
justifyContent: 'center',
marginBottom: 5
},
switch: {
alignItems: 'center',
borderWidth: 1,
borderColor: 'black',
paddingVertical: 10,
width: 100,
}
});
App.navigationOptions = {
title: 'Signup Screen',
headerVisible:false
};
AppRegistry.registerComponent('TabNavigator', () => App);
How i remove this pause plz tell me early as soon as possible..Thanks
I see just "t pera" but not gotten name from getStudentName function before "t pera".
import React, { Component } from 'react';
import {
Alert,
AppRegistry,
StyleSheet,
Text,
Navigator,
TextInput,
View,
Platform,
TouchableHighlight,
TouchableNativeFeedback,
} from 'react-native';
export class Student extends Component {
getStudentName() {
return fetch('http://192.168.1.14:3005/api/users/57bf7c101a7c1a892f6a19bc')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.name;
})
.catch((error) => {
console.error(error);
})
}
onButtonPress(){
this.props.navigator.push({
id: 'Student'
})
}
render() {
return(
<View style={styles.container}>
<TextInput style={styles.input}
placeholder = "peki"
/>
<Text>
{this.getStudentName}t pera
</Text>
<TouchableHighlight style={styles.button1} onPress={this.getStudentName}>
<Text style={styles.nastavi}>Nastavi</Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FFFFFF',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
padding: 30
},
input: {
borderBottomColor: 'grey',
borderBottomWidth: 1,
height: 40,
width: 250
},
button1: {
height: 40,
borderRadius: 5,
backgroundColor: '#4a4de7',
width: 250,
marginTop: 20,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
button2: {
height: 40,
borderRadius: 5,
backgroundColor: 'black',
width: 250,
marginTop: 20,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
nastavi: {
color: 'white',
fontSize: 15
}
});
module.exports = Student;
It's because your getStudentName() method isn't returning the string you're expecting, but a promise. You should update the state of your component from the result, rather than returning anything.
Notice below that I've replaced "this.getStudentName" with this.state.studentName, which will return an empty string (as defined in the constructor) until the promise from your method getStudentName() updates the state. Once the promise is finished and the state updates, it'll automatically refresh your views to show the student name.
export class Student extends Component {
constructor(props) {
super(props);
this.state = {
studentName: ''
};
}
componentDidMount() {
this.getStudentName();
}
getStudentName() {
var self = this;
return fetch('http://192.168.1.14:3005/api/users/57bf7c101a7c1a892f6a19bc')
.then((response) => response.json())
.then((responseJson) => {
self.setState({
studentName: responseJson.name
});
})
.catch((error) => {
console.error(error);
});
}
onButtonPress(){
this.props.navigator.push({
id: 'Student'
})
}
render() {
return(
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder = "peki" />
<Text>
{this.state.studentName}t pera
</Text>
<TouchableHighlight style={styles.button1} onPress={this.getStudentName.bind(this)}>
<Text style={styles.nastavi}>Nastavi</Text>
</TouchableHighlight>
</View>
);
}