I have another problem with a button. I have to position it inside a ListView under the last item.
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}
<TouchableOpacity onPress={ this.addNote.bind(this) } style={styles.addButton}>
<Text style={styles.addButtonText}>+</Text>
</TouchableOpacity>
</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>
</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 save the notes and display them inside the ListView. After the insertion, the button should appear under the new added note.
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.
I made it! Here are the changes I made in Main.js file:
<ScrollView style={styles.scrollViewContainer}>
<ScrollView style={styles.scrollContainer}>
{notes}
</ScrollView>
<TouchableOpacity onPress={ this.addNote.bind(this) } style={styles.addButton}>
<Text style={styles.addButtonText}>+</Text>
</TouchableOpacity>
</ScrollView>
And here is the designSheet:
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,
},
footer: {
position: 'absolute',
bottom: 0,
height: 70,
backgroundColor: '#000000',
left: 0,
right:0,
zIndex: 10,
},
textInput: {
alignSelf: 'stretch',
color: '#fff',
padding: 20,
backgroundColor: '#252525',
borderTopWidth:2,
borderTopColor: '#ededed',
marginRight: 70,
},
addButton: {
position: 'relative',
zIndex: 11,
left: 0,
top: 0,
backgroundColor: '#1A237E',
width: 70,
height: 70,
alignItems: 'center',
justifyContent: 'center',
elevation: 8
},
addButtonText: {
color: '#fff',
fontSize: 60
},
scrollViewContainer: {
flex: 1,
marginBottom: 70,
}
});
I hope this help others aswell
Related
I am designing an app in React Native and the problem I am facing right now is when I try to type in the TextBox, the keypad comes up and it pushes up or out the view changing height dynamically of other views too. Please check the Before and After image below:
The Code:
import React, { Component } from 'react';
import t from 'tcomb-form-native'; // 0.6.9
const Form = t.form.Form;
import {
StyleSheet,
View,
KeyboardAvoidingView,
TouchableOpacity,
ToastAndroid
} from 'react-native';
import { RFPercentage, RFValue } from "react-native-responsive-fontsize";
const styles = StyleSheet.create({
parentSectionContainer: {
flex: 1,
justifyContent: 'space-evenly',
backgroundColor: '#F1F0F2'
},
SignupFormParent: {
marginTop: 100,
alignSelf: 'center',
backgroundColor: '#FFFFFF',
height: '45%',
width: '85%',
borderRadius: 100,
shadowColor: '#2AC062',
shadowOpacity: 0.4,
shadowOffset: { height: 10, width: 0 },
shadowRadius: 20,
},
textMelow: {
width: RFPercentage(10),
fontSize: RFPercentage(2),
fontWeight: "normal",
color: '#FFFFFF',
textTransform: 'uppercase',
fontStyle: 'normal'
},
textBold: {
width: RFPercentage(10),
fontSize: RFPercentage(2),
fontWeight: "bold",
color: '#FFFFFF',
textTransform: 'uppercase',
fontStyle: 'normal'
},
btnContainer: {
paddingTop: 8,
width: '100%',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignContent: 'center'
},
signupBodyStyle: {
position: "absolute",
bottom: 0,
width: '90%',
marginBottom: 20,
},
signinSignupButtonsBtnsContainer: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'center',
width: '100%'
},
signupButtonBodyStyle: {
flex: 1,
backgroundColor: '#8A56AC',
borderRadius: 100,
alignItems: 'center',
padding: 25
},
signinSignupTextStyle: {
color: '#FFFFFF',
fontSize: 18,
}
});
const User = t.struct({
name: t.String,
email: t.String,
password: t.String,
"Confirm Password": t.String,
location: t.String
});
const SignupForm = (props) => {
const options = {
auto: 'placeholders',
};
return (
<View style={styles.SignupFormParent}>
<View style={{ paddingLeft: 20, paddingRight: 20, marginTop: 80 }}>
{/* <Text style={styles.text}>FORM</Text> */}
<Form type={User} options={options}/>
</View>
</View>
);
};
const ContinueButton = (props) => {
const { onPress, style } = props;
return (
<TouchableOpacity onPress={onPress} style={style.bodyStyle}>
<View
style={style.buttonStyle}>
<Text style={style.textStyle}>{props.title}</Text>
</View>
</TouchableOpacity>
);
}
export default class SignUpView extends Component {
// constructor(props) {
// }
fetch('${Config.IP}:${Config.PORT}/login', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'jayndoe#foobar.com',
password: "jynd1234",
}),
})
.then(response => response.json())
.then(responseJson => {
ToastAndroid.showWithGravity(
JSON.stringify(responseJson),
ToastAndroid.SHORT,
ToastAndroid.CENTER,
);
})
.catch(error => {
ToastAndroid.showWithGravity(
JSON.stringify(error),
ToastAndroid.SHORT,
ToastAndroid.CENTER,
);
})
}
render() {
return(
<View style={styles.parentSectionContainer}>
<KeyboardAvoidingView style={{ position: 'absolute', top: 0, width: '100%', backgroundColor: '#8A56AC', height: '30%', borderBottomLeftRadius: 120 }}/>
<View style={{ position: 'absolute', top: 50, width: '100%', flexDirection: 'row', justifyContent: 'space-evenly', margin: 'auto' }}>
<Text style={styles.textBold}>LOG IN</Text>
<Text style={styles.textMelow}>SIGN UP</Text>
</View>
<SignupForm
title="SIGN UP USING INSTAGRAM"
onPress={() => {this.instagramSSO()}}
style={{formStyles: styles.formStyles}}
/>
<View style={{ flex: 1, flexDirection: 'column', alignItems: 'center' }}>
<ContinueButton
title="CONTINUE"
style={{ bodyStyle: styles.signinBodyStyle, buttonStyle: styles.signinButtonBodyStyle, textStyle: styles.signinSignupTextStyle }}
onPress={() => Alert.alert('Please sign-in!!')}
/>
</View>
</View>
);
}
}
Appreciate any help in resolving this issue :)
This is because of the absolute positionning of your views,
I think you used it because you needed to put the white input wrapper on top of the purple one view. Maybe you could remove the absolute positionning and use negative paddingTop on the white wrapper instead ? I am not sure how to achieve this using good practices, but that could prevent the keyboardavoidingview to push your other components.
I have a react native component that handles comunication between two peers using WebRTC.
Everything works perfectly on ios but on android the buttons are unclickable and i am pretty sure its because of the position:absolute, the buttons rendering somewhere behind a element and because of that they are untappable.
My question is ... what am i doing wrong? Why are they rendering but they are untappable on android?
The buttons are: End call positioned center bottom and switch camera positioned right bottom.
PS: I removed most of the component logic as it was irelevant to the question.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { RTCView } from 'react-native-webrtc';
import WebSocketWrapper from '../components/generic/WebSocketWrapper/WebSocketWrapper';
import { Image, StyleSheet, View, Text, Platform, ActivityIndicator, Dimensions } from 'react-native';
import RNSecureStorage, { ACCESSIBLE } from 'rn-secure-storage';
import WebRtcPeer from 'react-native-kurento-utils';
import { COLORS } from '../styles/colors';
import { SafeAreaView } from 'react-navigation';
import axios from 'axios';
import Toast from 'react-native-root-toast';
import Icon from 'react-native-vector-icons/MaterialIcons';
import IconIonicons from 'react-native-vector-icons/Ionicons';
import { TouchableOpacity } from 'react-native-gesture-handler';
import logger from '#/logging.service';
import utils from '#/utils.service';
const BTN_CIRCLE_SIZE = 60;
const ICON_CIRCLE_SIZE = BTN_CIRCLE_SIZE / 2;
const styles = StyleSheet.create({
rtcViewsContainer: {},
remoteView: {
alignSelf: 'center',
top: 0,
right: 0,
bottom: 0,
left: 0,
backgroundColor: '#000000'
},
selfView: {
position: 'absolute',
alignSelf: 'flex-start',
width: 150,
height: 150,
left: 16,
bottom: 32,
borderWidth: 0.5
},
textContainer: {
flex: 1,
padding: 32,
width: '100%',
alignItems: 'center',
justifyContent: 'center'
},
introductionText: {
justifyContent: 'center',
alignItems: 'center',
fontSize: 13,
lineHeight: 22,
textAlign: 'center'
},
logo: {
alignSelf: 'center',
height: 70,
width: 150
},
logoContainer: {
height: 70,
position: 'absolute',
top: 0,
left: 0,
right: 0,
justifyContent: 'center',
alignItems: 'center'
},
endCallIconContainer: {
position: 'absolute',
zIndex: 100,
bottom: 32,
width: BTN_CIRCLE_SIZE,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row'
},
endCallIconTouchable: {
width: BTN_CIRCLE_SIZE,
height: BTN_CIRCLE_SIZE,
borderRadius: BTN_CIRCLE_SIZE / 2,
alignSelf: 'center',
zIndex: 110,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'red'
},
switchCameraIconTouchable: {
width: BTN_CIRCLE_SIZE,
height: BTN_CIRCLE_SIZE,
borderRadius: BTN_CIRCLE_SIZE / 2,
alignSelf: 'flex-end',
zIndex: 110,
justifyContent: 'center',
alignItems: 'center'
},
switchCameraIcon: {
width: BTN_CIRCLE_SIZE,
height: BTN_CIRCLE_SIZE
},
endCallIcon: {
alignSelf: 'center'
}
});
export default class VideoCallIdentification extends Component {
static navigationOptions = {
header: null
};
displayRTCViews() {
return !!(this.state.remoteURL && this.state.videoURL);
}
getText() {
if (this.state.CALL_STATE === this.CALL_STATES.FINISHED_CALL) {
return 'Please wait ...';
} else if (this.state.REGISTERED_STATE === this.CALL_STATES.REGISTERED) {
return 'An agent will be with you soon. You will be prompted to give access to your microphone and camera in order for the video call to proceed!';
}
}
componentWillUnmount() {
this.stopCommunication();
}
getRemoveViewDimensions() {
return {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height
};
}
onSocketError(e) {
logger.log('!!!!!!!!!!!!!!! Socket Erorr!', e);
utils.toast('An unexpected error has ocurred!');
this.stopWebRtc();
this.props.navigation.navigate('CompleteAccountPage');
}
getEndCallBarSize() {
return {
left: Dimensions.get('window').width / 2 - BTN_CIRCLE_SIZE / 2,
height: BTN_CIRCLE_SIZE
};
}
getSwitchCameraBarSize() {
return {
right: 32,
height: BTN_CIRCLE_SIZE
};
}
changeCamera() {
this.webRtcConnection.toggleCamera();
}
render() {
return (
<View
style={{ marginTop: 0, paddingLeft: 0, paddingRight: 0, marginBottom: 0, flex: 1, width: '100%', ...this.getRemoveViewDimensions() }}
containerStyle={{ flex: 1, width: '100%', ...this.getRemoveViewDimensions() }}
>
<SafeAreaView style={{ ...this.getRemoveViewDimensions(), position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
{this.displayRTCViews() ? (
<View>
<View style={{ ...styles.rtcViewsContainer, ...this.getRemoveViewDimensions() }}>
<RTCView streamURL={this.state.remoteURL} style={{ ...styles.remoteView, ...this.getRemoveViewDimensions() }} />
<RTCView streamURL={this.state.videoURL} style={styles.selfView} />
</View>
<View style={{ ...styles.endCallIconContainer, ...this.getEndCallBarSize() }}>
<TouchableOpacity style={styles.endCallIconTouchable} onPress={() => this.stopCommunication(true).bind(this)}>
<Icon style={styles.endCallIcon} size={ICON_CIRCLE_SIZE} name="call-end" color="#ffffff" />
</TouchableOpacity>
</View>
<View style={{ ...styles.endCallIconContainer, ...this.getSwitchCameraBarSize() }}>
<TouchableOpacity style={styles.switchCameraIconTouchable} onPress={() => this.changeCamera(true)}>
<IconIonicons style={styles.endCallIcon} size={BTN_CIRCLE_SIZE} name="ios-reverse-camera" color="#ffffff" />
</TouchableOpacity>
</View>
</View>
) : (
<View style={styles.textContainer}>
<View style={styles.logoContainer}>
<Image source={require('../assets/images/logoAndNameColored.png')} style={styles.logo} resizeMode="contain" />
</View>
<Text style={styles.introductionText}>{this.getText()}</Text>
<ActivityIndicator style={{ marginTop: 22 }} size="large" color={COLORS.APP_PURPLE} />
</View>
)}
<WebSocketWrapper
ref={ref => {
if (!this.state.socket) {
this.setState({ socket: ref });
}
}}
onError={this.onSocketError.bind(this)}
onOpen={this.onSocketOpen.bind(this)}
url={this.state.socketUrl}
onMessage={this.onmessage.bind(this)}
/>
</SafeAreaView>
</View>
);
}
}
VideoCallIdentification.propTypes = {
navigation: PropTypes.object
};
Is there a way to call an event when I press on an item inside this ScrollView?
let notes = this.state.noteArray.map((val, key)=>{
return <Note key={key} keyval={key} val={val}
deleteMethod={()=>this.deleteNote(key)}
editMethod={()=> this.editMethod(key, val)} />
});
<ScrollView style={styles.scrollContainer}> {notes} </ScrollView>
Note:
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
} from 'react-native';
export default class Note extends Component {
render() {
return (
{this.props.val.date}
{this.props.val.note}
<TouchableOpacity onPress={this.props.deleteMethod} style={styles.noteDelete}>
<Text style={styles.noteDeleteText}>Del</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.props.editMethod} style={styles.editNote}>
<Text style={styles.noteDeleteText}>Edit</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
},
editNote: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2980b9',
padding: 10,
top: 10,
bottom: 10,
right: 70
},
noteDeleteText: {
color: 'white'
},
});
You need to add your all items under TouchableOpacity in which you like to get an event:
<TouchableOpacity
onPress={() => {
alert('Pressed')
}}>
// Keep your element which you like to tap
</TouchableOpacity>
You can refer the react-native doc for more reference.
You can use like this
let notes = this.state.noteArray.map((val, key)=>{
return <Note key={key} keyval={key} val={val}
deleteMethod={()=>this.deleteNote.bind(key)}
editMethod={()=> this.editMethod.bind(key, val)} />
});
I have a view with 3 textinput and I am trying to center them when the keyboard is opened. I already tried with KeyboardAvoidingView and the result is that all, except the save button disappear. What am I doing wrong?
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TextInput,
ScrollView,
ListView,
KeyboardAvoidingView,
TouchableOpacity,
AsyncStorage,
} from 'react-native';
import Note from './Note.js';
export default class NoteBody extends Component {
static navigationOptions = {
header: null,
};
constructor(props){
super(props);
this.state = {
noteText: '',
noteTitle: '',
callType: '',
};
}
render() {
return (
<View style={styles.container}>
<View style={styles.header1}>
<Text style={styles.title}>New Note</Text>
</View>
<View style={styles.headerDesign}>
</View>
<View style={styles.header2}>
</View>
<View style= {styles.mainPage}>
<View style={styles.noteBody}>
<TextInput
style = {styles.subject}
placeholder='Raport Number/Note Indentifier'
onChangeText={(noteTitle)=> this.setState({noteTitle})}
value={this.state.noteTitle}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
<TextInput
style = {styles.calltype}
multiline = {true}
numberOfLines = {5}
placeholder='Call Type/Other Information'
onChangeText={(callType)=> this.setState({callType})}
value={this.state.callType}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
<TextInput
multiline = {true}
numberOfLines = {8}
style={styles.textInput}
placeholder='Notes'
onChangeText={(noteText)=> this.setState({noteText})}
value={this.state.noteText}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
</View>
<View style= {styles.footer}>
<TouchableOpacity onPress={ this.addNote.bind(this) } style={styles.addButton}>
<Text style={styles.addButtonText}>SAVE</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
addNote(){
const { navigate } = this.props.navigation;
if(this.state.noteText && this.state.noteTitle && this.state.callType){
var d = new Date();
this.props.navigation.state.params.noteArray.push({
'noteName':this.state.noteTitle,
'date':(d.getMonth()+1)+
"/"+d.getDate() +
"/"+ d.getFullYear(),
'callType': this.state.callType,
'note': this.state.noteText
});
this.setState({ noteArray: this.props.navigation.state.params.noteArray });
this.setState({noteText:''});
this.setState({noteTitle:''});
this.setState({callType:''});
AsyncStorage.setItem('arr', JSON.stringify(this.props.navigation.state.params.noteArray));
this.props.navigation.state.params.onNavigateBack();
this.props.navigation.goBack();
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
mainPage:{
flex: 2,
alignItems: 'center',
justifyContent:'center',
},
header1:{
backgroundColor: '#000',
alignItems: 'center',
height: 40,
justifyContent: 'center',
},
title:{
color: '#fff',
fontSize: 20,
},
header2:{
marginBottom: 10,
backgroundColor: '#000',
alignItems: 'center',
height: 40,
justifyContent: 'center',
},
headerDesign:{
backgroundColor: '#0000FF',
alignItems: 'center',
height: 20,
justifyContent: 'center',
},
noteBody:{
flex: 2,
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
zIndex: 10,
alignItems: 'center',
marginBottom: 100,
},
textInput: {
alignSelf: 'stretch',
textAlignVertical: 'top',
backgroundColor: '#fff',
color: '#000',
padding: 20,
borderTopWidth:1,
borderTopColor: '#D3D3D3',
borderBottomWidth:1,
borderBottomColor: '#000',
},
addButton: {
position: 'absolute',
zIndex: 11,
bottom: 20,
alignItems: 'center',
justifyContent: 'center',
width: 200,
backgroundColor: '#0000FF',
height: 40,
elevation: 8
},
addButtonText: {
color: '#fff',
fontSize: 20,
},
subject:{
alignSelf: 'stretch',
textAlignVertical: 'top',
backgroundColor: '#fff',
padding: 20,
borderTopWidth:1,
borderTopColor: '#000',
borderBottomWidth:1,
borderBottomColor: '#D3D3D3',
},
calltype:{
alignSelf: 'stretch',
textAlignVertical: 'top',
backgroundColor: '#fff',
padding: 20,
},
footer:{
flex: 3,
alignItems: 'center',
justifyContent:'center',
}
});
Please, copy the code in your text editor and give it a try. Just replace the wrapping view with KeyboardAvoidingView like so: https://facebook.github.io/react-native/docs/keyboardavoidingview.html#keyboardverticaloffset and tell me what else can I do?
You must insert the KeyboardAvoidingView in a ScrollView.
Like so:
<ScrollView>
<KeyboardAvoidingView styles={styles.container} behavior = 'padding' enabled>
</KeyboardAvoidingView>
</ScrollView>
I am new to React Native development. I want to create an enter passcode authentication page. I have no idea, how to create this page.
Please give me some sample
thankyou in advance.
I want one like this: Passcode authentication
here is my way for passCode:
just use you images and paths according to your project
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
Image
} from 'react-native';
import H1 from '../../Common/Inheritance/h1';
import { config } from '../../../theme/config';
import { Actions } from 'react-native-router-flux';
class EnterPassCode extends Component {
constructor(props) {
super(props);
this.state = {
passCode: ''
};
this.onBack = this.onBack.bind(this);
}
onBack() {
Actions.EnterTouchId();
}
onChangePassCode() {}
render() {
return (
<View style={styles.pad}>
<TouchableOpacity style={styles.backButton} onPress={this.onBack}>
<Image source={require('../../../assets/img/back_arrow_black.png')} />
</TouchableOpacity>
<View style={styles.title}>
<H1>Create a passcode</H1>
</View>
<View style={styles.codeWrapper}>
<View style={styles.passcodeEnter}>
<TextInput
secureTextEntry={true}
style={styles.textBox}
keyboardType='numeric'
maxLength={4}
autoFocus={true}
onChange={this.onChangePassCode.bind(this)}
onChangeText={passCode => this.setState({ passCode })}
/>
</View>
<View style={styles.circleBlock}>
<View
style={[
styles.circle,
this.state.passCode.length >= 1 && styles.circleFill
]}
></View>
<View
style={[
styles.circle,
this.state.passCode.length >= 2 && styles.circleFill
]}
></View>
<View
style={[
styles.circle,
this.state.passCode.length >= 3 && styles.circleFill
]}
></View>
<View
style={[
styles.circle,
this.state.passCode.length >= 4 && styles.circleFill
]}
></View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
pad: {
paddingTop: 75,
margin: 5
},
backButton: {
display: 'flex',
left: 10,
top: 30,
position: 'absolute',
zIndex: 9999,
width: 50,
height: 50,
alignItems: 'center',
justifyContent: 'center'
},
title: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingBottom: 90,
paddingTop: 40
},
codeWrapper: {
position: 'relative'
},
passcodeEnter: {
height: '100%',
opacity: 0,
position: 'absolute',
width: '100%',
zIndex: 9
},
textBox: {
fontSize: 30,
letterSpacing: 15,
textAlign: 'center'
},
circleBlock: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'center'
},
circle: {
borderRadius: 30,
borderWidth: 3,
borderColor: config.primaryColor,
height: 25,
marginLeft: 23,
marginRight: 23,
width: 25
},
circleFill: {
backgroundColor: config.primaryColor,
borderRadius: 30,
borderWidth: 3,
borderColor: config.primaryColor,
height: 25,
marginLeft: 23,
marginRight: 23,
width: 25
}
});
export default EnterPassCode;