i have used react-native-drawer . i have kept the side menu file seperate and import it in main file . i want to write click function in side menu file . when i click the first item it gives me this error.
how can i solve this problem i think its mocking child component error .
here is my side menu file code
import React, { Component } from 'react';
import {
View,
StyleSheet,TouchableHighlight
} from 'react-native';
import { Content,Text,List, ListItem .
,Header,Icon,Left,Right,Body,Button,Title} from 'native-base';
import StatusComponent from './StatusComponent';
import Hr from 'react-native-hr';
export default class SideBar extends Component{
constructor(props){
super(props);
console.log(props)
asad=this.asad.bind(this);
}
asad(){
alert('gata rhe ');
}
render(){
return(
<View style={{backgroundColor:'#262626',flex:1,
position:'relative' ,top:62}} >
<List>
<ListItem >
<Right>
<TouchableHighlight onPress={()=>this.asad(this.props)}>
<Text style={{color:'white'}} > main page</Text>
</TouchableHighlight>
</Right>
</ListItem>
<ListItem >
<Right>
<TouchableHighlight >
<Text style={{color:'white'}} > secnd page</Text>
</TouchableHighlight>
</Right>
</ListItem>
</List>
</View>
)
};
}
NativeBase provides help to include Drawer in our apps
Check NativeBase Drawer
i got the solution i m using NativeBase for ui things so touchable is not work in native listItems so i used button of native BAse like this
<ListItem Button onPress={() => this.asad(this.props) } >
<Right>
<Text style={{color:'white'}} > page</Text>
</Right>
</ListItem>
Related
import {SafeAreaView, StyleSheet,ScrollView, Text,Button, View, TouchableOpacity,TextInput} from 'react-native';
import React, {Component, useState} from 'react';
import Header from './AllHeaders/Header';
import UnitClerkHeader from './AllHeaders/UnitClerkHeader';
import AppointmentHeading from './AllHeaders/AppointmentHeading';
import PatientDoc from './PatientDoc';
import styles from './Styles/CompleteStyling';
export default class HomeScreen extends Component {
render(){
return (
<ScrollView>
<SafeAreaView style={{flex: 1}}>
<View>
<Header name="HOME SCREEN" class= ""/>
<UnitClerkHeader/>
<View style={styles.containerForButton}>
<TouchableOpacity style={styles.button_Side_by_Side}
onPress={() =>this.props.navigation.navigate("SignInScreen")}
>
<Text style={styles.Button_text_styling}>
REGISTRATION </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button_Side_by_Side}
onPress={() =>this.props.navigation.navigate("SignInScreen")}
>
<Text style={styles.Button_text_styling}>
SEARCH </Text>
</TouchableOpacity>
</View>
<AppointmentHeading name="UPCOMING APPOINTMENTS" class= "" />
<PatientDoc/>
<PatientDoc/>
<PatientDoc/>
<PatientDoc/>
<PatientDoc/>
<TouchableOpacity style={styles.buttonGeneral}
onPress={() =>this.props.navigation.navigate("SignInScreen")}
>
<Text style={styles.Button_text_styling} >
NEXT </Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</ScrollView>
);
}
}
ERROR Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of HomeScreen.
Check if you imported components properly if you
export default
then you don't use {} when you import and if you just exported your component then you need {}... I suggest you check this first
I have a text input in an overlay in my react native application. I used keyboardavoidingview to make sure the keyboard doesn't cover my submit button but the entire overlay is not moving with the keyboard only the inside content is moving. Heres an image of what is happening. Is there any way to move the overlay with the content too?
This is my code
<Overlay overlayStyle={{borderRadius:15,backgroundColor:'#f8f8f8',paddingTop:20,paddingLeft:20,height:300}} isVisible={showrevoverlay} onBackdropPress={()=>{resetoverlay()}}>
<KeyboardAvoidingView keyboardVerticalOffset={300} style={{flex:1,alignItems:'center',justifyContent:'center'}} behavior="padding">
<View style={{flexDirection:'column',justifyContent:'space-evenly',alignItems:'center'}}>
<Text style={{fontWeight:'bold',textAlign:'left',width:'100%'}}>Review:</Text>
<TextInput
placeholder="Write review"
style={{alignItems:'center',justifyContent:'center'}}
style={{ height: 200,width:300, borderColor: 'gray',backgroundColor:'#eef4f6',marginTop:10}}
onChangeText={text => setreview(text)}
value={review}
/>
<TO onPress={()=>{saveReview()}} style={{marginTop:10,width:100,height:50,backgroundColor:'#4B53F2',justifyContent:'center',alignItems:'center'}}><Text style={{fontFamily:'Montserrat-Bold',color:'white',fontSize:15}}>Submit</Text></TO>
</View>
</KeyboardAvoidingView>
</Overlay>
Here is the solution to solve this problem. you can add your code.
import React , {Component} from 'react';
import {View , Dimensions,ScrollView} from 'react-native';
const windowHeight = Dimensions.get('window').height;
export default class Overlay extends Component {
render(){
return(
<View style={{flex:1}}>
<ScrollView style={{flex:1}}>
<View style={{width:'100%', height:windowHeight }}>
/*Every thing inside this will shift up with out changing style */
</View>
</ScrollView>
</View>
)
}
}
Working with react-native is mega frustrating. Its more frustrating because I am new to it. I have written component that takes redux action as an input.
import React from "react";
import {Text} from "react-native";
import styles from "./searchBoxStyles";
import {View,InputGroup,Input} from "native-base";
import Icon from "react-native-vector-icons/FontAwesome";
export const SearchBox = (getInputData,selectedSearchTab) => {
function handleInput(key,val){
getInputData({
key,
value:val});
}
return(
<View style={styles.searchBox}>
<View style={styles.inputWrapper}>
<Text style={styles.label}>PickUp</Text>
<InputGroup>
<Icon name="search" size={15} color="#FF5E3A"/>
<Input onFocus={()=>selectedSearchTab("pickUp")} style={styles.inputSearch} placeholder="choose pickup location" onChanangeText={handleInput.bind(this,"pickUp")}/>
</InputGroup>
</View>
<View style={styles.secondInputWrapper}>
<Text style={styles.label}>DropOff</Text>
<InputGroup>
<Icon name="search" size={15} color="#FF5E3A"/>
<Input onFocus={()=>selectedSearchTab("dropOff")} style={styles.inputSearch} placeholder="choose drop off location" onChanangeText={handleInput.bind(this,"dropOff")}/>
</InputGroup>
</View>
</View>
);
};
export default SearchBox;
getInputData & selectedSearchTab are both redux actions, passed down from container component.
Clicking on the textBox I get selectedSearchTab is not a function error.
My home page contains a View. This view contains a flat list with items. The flat list is being rendered through a different component
I should be able to use something like this.props.navigation.navigate('DetailPage') from the component not from my homePage.
I think i should pass the navigation as a prop to the but not sure how i could do that.
Navigation File
export const HomePageStack = StackNavigator({
Homepage:{
screen:homePage,
},
DetailPage:{
screen: DetailPage,
}
})
Home Page Screen
render(){
return(
<View>
<DetailedArea />
</View>
)}
Detailed Area
render(){
return(
<TouchableHighlight onPress={this.props.navigation.navigate('DetailPage')}>
<Text>CLICK HERE TO GO TO DETAIL PAGE</TEXT>
</TouchableHighlight>
)}
the HomeScreen has this.props.navigation, but it isn't passed down to DetailedArea.
I recommend the following:
HomeScreen
render(){
return(
<View>
<DetailedArea onNavigate={() => this.props.navigation.navigate('DetalPage')} />
</View>
)}
DetailedArea
render(){
return(
<TouchableHighlight onPress={this.props.onNavigate}>
<Text>CLICK HERE TO GO TO DETAIL PAGE</TEXT>
</TouchableHighlight>
)}
I am getting warnings while using this component. Trying to use this component as a button. I tried require('TouchableNativeFeedback') but no use. I also tried to npm install TouchableNativeFeedback, but failed. How should it be incorporated in my react native android code?
{
var TouchableNativeFeedback= require('TouchableNativeFeedback');
var Button= require('react-native-button');
var {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableNativeFeedback,
} = React;
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
My first App
</Text>
<Text style={styles.instructions}>
we should get started
</Text>
<Text style={styles.instructions}>
Nice!!
</Text>
<Image source={require('./abc.png')} style={styles.img} >
<Text style={styles.welcome}> Inside an image! </Text>
</Image>
<TouchableNativeFeedback
style={styles.img} >
<View>
<Text style= {styles.instructions}>
Button!
</Text>
</View>
</ TouchableNativeFeedback>
<Button style={styles.img} onClick="this.butclick">
<View>
<Text style={styles.instructions}>
This is a Button
</Text>
</View>
</Button>
</View>
);
}
});
}
It can be implement like this, see the react-native documentation for more functionality.
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple('red')}>
<View style={styles.view}>
<Text style={style.text}>Text Here</Text>
</View>
</TouchableNativeFeedback>
best practice to use TouchableNativeFeedback.Ripple is to check the api version of devices first, because this background type is available on Android API level 21+.
import { Platform } from 'react-native';
<TouchableNativeFeedback
onPress={this.follow}
background={
Platform.Version >= 21 ?
TouchableNativeFeedback.Ripple('rgba(0,0,0,.2)', true) :
TouchableNativeFeedback.SelectableBackground()
}
>
require isn't necessary.
TouchableNativeFeedback is like Text, Image or View.
var Button= require('react-native-button');
var {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableNativeFeedback,
} = React;
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<TouchableNativeFeedback
style={styles.img} >
<View>
<Text style= {styles.instructions}>
Button!
</Text>
</View>
</ TouchableNativeFeedback>
</View>
);
}
});
Firstly, you need to import the respective dependency(TouchableNativeFeedback):
import { TouchableNativeFeedback, View, Text } from 'react-native';
After this, you can use it as:
<TouchableNativeFeedback onPress={() => this._onPressButton()} key={index}>
<View>
<Text>Click Me</Text>
</View>
</TouchableNativeFeedback>
Note: Make sure to add the respective click function(this._onPressButton()) in your code, otherwise you will get an error.