How to align texts to each Textinput - React Native - react-native

I want those texts in the left to be aligned to my Textinputs on the right.
I am fetching textinputs and texts from api so they are dynamic. I need to display each text on the left side of the texinput.
Here is my code:
textfieldsObject = () => {
const obje = this.props.navigation.state.params.item;
var keyvalue_to_json = JSON.parse(obje.keyValues);
var textinputName = [];
var foundTextFields = [];
for (let i = 0; i < keyvalue_to_json.inputFields.length; i++) {
if (keyvalue_to_json.inputFields[i].type === 'textfield') {
foundTextFields.push(<TextInput placeholder={keyvalue_to_json.inputFields[i].placeholderText} style={styles.inputFields}
onEndEditing={(e) => {
keyvalue_to_json.inputFields[i].inputValues = e.nativeEvent.text;
this.myInputFields.myTextFields[i] = keyvalue_to_json.inputFields[i];
}}
></TextInput>) &&
textinputName.push(<Text style={{ textAlign: 'left', flex: 2 }}>{keyvalue_to_json.inputFields[i].title}</Text>)
}
}
return (
<View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between' }}>
<View style={{ flex: 1 }}>
{textinputName}
</View>
<View style={{ flex: 1 }}>
{foundTextFields}
</View>
</View>
)
}

I have write small piece of code . You can try this code. It may solve your problem. Please also check this code into snack and directly run to scan QR using Expo app. Please c
import * as React from 'react';
import { TextInput, Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View
style={{
justifyContent: 'center',
alignSelf: 'center',
alignItems: 'center',
alignContent: 'center',
flexDirection: 'row',
}}>
<Text style={{ textAlign: 'center', flex: 1, padding: 15 }}>
{'Full name'}
</Text>
<TextInput
placeholder='Enter Your Full Name'
placeholderTextColor='#303030'
style={{
borderWidth: 1,
borderColor: '#000',
flex: 1,
padding: 15,
}}/>
</View>
<View
style={{
justifyContent: 'center',
alignSelf: 'center',
alignItems: 'center',
alignContent: 'center',
flexDirection: 'row',
}}>
<Text style={{ textAlign: 'center', flex: 1, padding: 15 }}>
{'CRP Number'}
</Text>
<TextInput
placeholder='Enter Your CRP Number'
placeholderTextColor='#303030'
style={{
borderWidth: 1,
borderColor: '#000',
flex: 1,
padding: 15,
}}/>
</View>
<View
style={{
justifyContent: 'center',
alignSelf: 'center',
alignItems: 'center',
alignContent: 'center',
flexDirection: 'row',
}}>
<Text style={{ textAlign: 'center', flex: 1, padding: 15 }}>
{'Company Name'}
</Text>
<TextInput
placeholder='Enter Your Company Name'
placeholderTextColor='#303030'
style={{
borderWidth: 1,
borderColor: '#000',
flex: 1,
padding: 15,
}}/>
</View>
<View
style={{
justifyContent: 'center',
alignSelf: 'center',
alignItems: 'center',
alignContent: 'center',
flexDirection: 'row',
}}>
<Text style={{ textAlign: 'center', flex: 1, padding: 15 }}>
{'Company CVR '}
</Text>
<TextInput
placeholder='Enter Your company CVR'
placeholderTextColor='#303030'
style={{
borderWidth: 1,
borderColor: '#000',
flex: 1,
padding: 15,
}}>
{'Enter Your company CVR'}
</TextInput>
</View>
<Text style={{ color:'#fff',borderRadius:50, width:300, height:50, textAlign:'center', padding:15, marginTop:70,backgroundColor:'#00b5ec'}}>{"Click to sign in"}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
marginTop: 10,
marginRight:1
},
});
Updated Answer Please Check
import * as React from 'react';
import { FlatList, TextInput, Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
jsonData: [
{ id: 1, textName: 'Hello', textInputName: 'Full Name' },
{
id: 2,
textName: 'Hello',
textInputName: 'Last Name',
},
{
id: 3,
textName: 'Hello',
textInputName: 'Date of Birth',
},
{
id: 4,
textName: 'Hello',
textInputName: 'Address',
},
{ id: 1, textName: 'Hello', textInputName: 'Full Name' },
{
id: 2,
textName: 'Hello',
textInputName: 'Last Name',
},
{
id: 3,
textName: 'Hello',
textInputName: 'Date of Birth',
},
{
id: 4,
textName: 'Hello',
textInputName: 'Address',
},
{ id: 1, textName: 'Hello', textInputName: 'Full Name' },
{
id: 2,
textName: 'Hello',
textInputName: 'Last Name',
},
{
id: 3,
textName: 'Hello',
textInputName: 'Date of Birth',
},
{
id: 4,
textName: 'Hello',
textInputName: 'Address',
},
],
};
}
render() {
return (
<View style={styles.container}>
<FlatList
style={{ width: '100%', flex: 1 }}
data={this.state.jsonData}
showsVerticalScrollIndicator={false}
renderItem={({ item }) => (
<View
style={{
justifyContent: 'center',
alignSelf: 'center',
alignItems: 'center',
alignContent: 'center',
flexDirection: 'row',
}}>
<Text style={{ textAlign: 'center', flex: 1, padding: 15 }}>
{item.textName}
</Text>
<TextInput
placeholder={item.textInputName}
placeholderTextColor="#303030"
style={{
borderWidth: 1,
borderColor: '#000',
flex: 1,
padding: 15,
}}
/>
</View>
)}
/>
<Text
style={{
color: '#fff',
borderRadius: 50,
width: 300,
height: 50,
textAlign: 'center',
padding: 15,
marginTop: 10,
backgroundColor: '#00b5ec',
marginBottom: 20,
}}>
{'Click to sign in'}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
marginTop: 10,
marginRight: 1,
},
});
I have also added updated snack expo please check
https://snack.expo.io/#vishal7008/anxious-candy

I recomend you to create Views with the same size. Once this is done, put inside the Text compnent with tha margin you want or the view style properties to align the text.
Either with View Style properties or Text, if the View containing the 2 texts are the same size the texts components wioll be aligned to each other.

As you can see in the code below, what I do is wrapping your text components with a
view, and both views wrapping the text has the exact same size.
Once this is done, the Text components inside these views has width and height 100%, so it will be the same size as the view. This way you will have 2 components aligned in your main View with flex-direction = row, and the text will be aligned.
Copy the code below and set up the size of the views inside the style props of both views where I commented the code
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between'
}}
>
<View
style={{
flex: 1,
//Here You set up with and height
}}
>
<Text
style={{
height: '100%',
width: '100%',
textAlign: 'center'
}}
>
{textinputName}
</Text>
</View>
<View
style={{
flex: 1,
//And here you set up the same with and height than the first view
}}
>
<Text
style={{
height: '100%',
width: '100%',
textAlign: 'center'
}}
>
{foundTextFields}
</Text>
</View>
</View>

Related

Flex 1 not working properly in react-native

For parent View I have set flex 1 and for child view, I have given Flex 1 and Flex 4 respectively. But the first child view is taking all the spaces.
Plz refer the below screenshot
export default function App() {
return (
<View style={styles.appContainer}>
<View style={styles.inputContainer}>
<TextInput style={styles.textInput} placeholder='Add your goal' />
<Button title='Add me' />
</View >
<View styles={styles.goalContainer}>
<Text>List of goals...</Text>
</View>
</View>
);
}
// Styles
const styles = StyleSheet.create({
appContainer: {
flex: 1,
paddingTop: 50,
paddingHorizontal: 16
}
,
inputContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingBottom: 24,
borderBottomWidth: 1,
borderBottomColor: '#cccccc'
},
textInput: {
borderWidth: 1,
borderColor: '#cccccc',
width: '70%',
marginRight: 8,
padding: 8
},
goalContainer: {
flex: 4
}}) //Forgot to add curly bracket and closing bracket
correct style spelling in View.
<View style={styles.goalContainer}>
<Text>List of goals...</Text>
</View>
Please try with below code
import React from 'react'
import {View,StyleSheet,Text,TextInput,Button} from 'react-native'
export default function App() {
return (
<View style={styles.appContainer}>
<View style={styles.inputContainer}>
<TextInput style={styles.textInput} placeholder='Add your goal' />
<Button title='Add me' />
</View>
<View style={styles.goalContainer}>
<Text>List of goals...</Text>
</View>
</View>
);
}
// Styles
const styles = StyleSheet.create({
appContainer: {
flex: 1,
paddingTop: 50,
paddingHorizontal: 16,
backgroundColor: null,
}
,
inputContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingBottom: 24,
borderBottomWidth: 1,
borderBottomColor: '#cccccc',
backgroundColor:null
},
textInput: {
borderWidth: 1,
borderColor: '#cccccc',
width: '70%',
marginRight: 8,
padding: 8,
backgroundColor:null
},
goalContainer: {
flex: 4,
backgroundColor: null
}
})

Slider height is not changing with height property in react-native-swiper

so I'm fairly new to react-native. I'm trying to implement a carousel with react-native-swiper.
Issue -
I want to set the carousel height to 150px, for this I set the property height to 150px, with this the carousel height got changed to 150px but when I try to render a text component below carousel, it is not rendering just below the carousel.
import React from 'react';
import { View, Text, StyleSheet } from "react-native";
import Swiper from 'react-native-swiper';
const styles = StyleSheet.create({
wrapper: { backgroundColor: "black", height: 150 },
slide1: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB'
},
slide2: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5'
},
slide3: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9'
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold'
}
})
const HomeScreen_ = () => {
return (
<>
<Swiper
style={styles.wrapper}
height={150}
showsButtons
autoplay
paginationStyle={{ height: 8, position: 'absolute', top: 130 }}
activeDot={
<View
style={{
backgroundColor: '#c3383833', width: 8,
height: 8, borderRadius: 4, marginLeft: 3,
marginRight: 3, marginTop: 3, marginBottom: 3
}} />
}>
<View style={styles.slide1}>
<Text style={styles.text}>Hello Swiper</Text>
</View>
<View style={styles.slide2}>
<Text style={styles.text}>Beautiful</Text>
</View>
<View style={styles.slide3}>
<Text style={styles.text}>And simple</Text>
</View>
</Swiper >
<Text style={{ height: 100, color: "black", }}>Just a Random Text</Text>
</>
)
};
export default HomeScreen_;
you can check this sample, in React Native, we have covered any component using View
import React from 'react';
import {View, Text, StyleSheet, SafeAreaView} from 'react-native';
import Swiper from 'react-native-swiper';
const SwiperExample = () => {
return (
<>
<View style={{flex: 0.3}}> // here
<Swiper
style={styles.wrapper}
showsButtons
autoplay
paginationStyle={{height: 8, position: 'absolute', top: 130}}
activeDot={
<View
style={{
backgroundColor: '#c3383833',
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 3,
marginRight: 3,
marginTop: 3,
marginBottom: 3,
}}
/>
}>
<View style={styles.slide1}>
<Text style={styles.text}>Hello Swiper</Text>
</View>
<View style={styles.slide2}>
<Text style={styles.text}>Beautiful</Text>
</View>
<View style={styles.slide3}>
<Text style={styles.text}>And simple</Text>
</View>
</Swiper>
</View>
<Text style={{height: 100, color: 'black'}}>Just a Random Text</Text>
</>
);
};
const styles = StyleSheet.create({
wrapper: {backgroundColor: 'black', flex: 1},
slide1: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB',
},
slide2: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5',
},
slide3: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9',
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold',
},
});
export default SwiperExample;
I solved this issue by removing the height property in the wrapper object of StyleSheet and passing containerStyle={{ height: 150, flex: 0 }} as a prop in Swiper

Issues with Flexbox in React Native not displaying the Full Text

I'm having some troubles displaying information which I believe they have to do with the Flexbox Properties, but no matter how I play around with the Styles I don't get to fit everything in some components.
First I have this Component which is a Simple Card Component where I pass my data from API:
<PartidoItem
localImage={logoLocal}
marcadorLocal={marcadorLocal}
time={date}
partidoId={partidoId}
estatus={estatus}
minute={elapsed}
estadio={estadio}
marcadorVisita={marcadorVisita}
visitImage={logoVisita}
onSelect={estatus !== 'NS' && estatus !== 'TBD' ? () => {
selectPartidoHandler(partidoId, tituloPartido)
}
: () => { }
}
/>
This comes from this Component:
import React from 'react';
import { View, Text, Image, StyleSheet, TouchableNativeFeedback, TouchableOpacity, Platform } from 'react-native';
import Card from '../UI/Card';
import Colors from '../../constants/Colors';
const PartidoItem = props => {
let TouchableCmp = TouchableOpacity;
if (Platform.OS === 'android' && Platform.Version >= 21) {
TouchableCmp = TouchableNativeFeedback;
}
return (
<Card style={styles.product}>
<View style={styles.touchable}>
<TouchableCmp onPress={props.onSelect} useForeground>
<View style={styles.container}>
<View style={styles.column}>
<View style={styles.imageContainer}>
<Image
resizeMode="cover"
style={styles.image}
source={{ uri: props.localImage }}
/>
</View>
</View>
<View style={styles.column}>
<Text style={styles.number}>{props.marcadorLocal}</Text>
</View>
{props.estatus === 'NS' || props.estatus === 'TBD'
? <View style={styles.column}>
<Text style={styles.date}>{props.time}</Text>
<Text style={styles.title}>{props.estadio}</Text>
</View>
: props.estatus === 'FT' ?
<View style={styles.column}>
<Text style={styles.title2}>Final</Text>
<Text style={styles.title}>{props.estadio}</Text>
</View>
:
<View style={styles.column}>
<Text style={styles.title}>Tiempo:</Text>
<Text style={styles.title}>{props.minute} '</Text>
</View>
}
<View style={styles.column}>
<Text style={styles.number}>{props.marcadorVisita}</Text>
</View>
<View style={styles.column}>
<View style={styles.imageContainer}>
<Image
resizeMode="cover"
style={styles.image}
source={{ uri: props.visitImage }}
/>
</View>
</View>
</View>
</TouchableCmp>
</View>
</Card>
);
};
const styles = StyleSheet.create({
product: {
height: 100,
margin: 20,
justifyContent: 'center',
alignItems: 'center',
},
touchable: {
borderRadius: 10,
},
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
column: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
width: '20%',
},
space_between_columns: {
width: 100
},
box: {
height: 50,
width: 50
},
imageContainer: {
width: '100%',
height: '70%',
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
overflow: 'hidden',
marginHorizontal: 10,
overflow: 'hidden',
},
image: {
width: '100%',
height: '100%',
flex: 1,
},
hora: {
fontSize: 14,
color: '#888',
fontWeight: 'bold',
textAlign: 'center',
},
number: {
fontSize: 50,
marginVertical: 4,
fontWeight: 'bold',
justifyContent: 'center',
color: Colors.secondary,
},
title: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
//flexWrap: 'wrap',
flex: 2,
flexGrow: 1,
},
title2: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
color: 'red',
},
date: {
fontSize: 14,
marginVertical: 4,
textAlign: 'center',
flex: 1,
flexGrow: 1,
marginHorizontal: 2,
},
});
export default PartidoItem;
Which Holds this Component as well:
import React from 'react';
import { View, StyleSheet } from 'react-native';
//Importacion de los colores
import Colors from "../../constants/Colors";
const Card = props => {
return (
<View style={{...styles.card, ...props.style}}>
{props.children}
</View>
);
};
const styles = StyleSheet.create({
card: {
shadowColor: 'black',
shadowOpacity: 0.26,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 8,
elevation: 5,
borderRadius: 10,
backgroundColor: Colors.background,
}
});
export default Card;
Now the problem is that when I see it in the Android Emulator and it has large Strings I see this:
As you can see the Component is the one in the Primary Box and the Property "Estadio" is too big that doesn't show completely
The same happens when I check this on my iOS device (through Expo):
Is there a way to get this info to fit into that space so it shows the Full Name?
Kind Regards
PD: After Change Advise on first Answer this is the result with the Logos not showing correctly:
Try this for your styles :
const styles = StyleSheet.create({
product: {
height: 120,
margin: 20,
justifyContent: 'center',
alignItems: 'center',
},
touchable: {
borderRadius: 10,
},
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
column: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
},
space_between_columns: {
width: 100
},
box: {
height: 50,
width: 50
},
imageContainer: {
width: 100,
height: 100,
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
overflow: 'hidden',
marginHorizontal: 10,
overflow: 'hidden',
},
image: {
width: '100%',
height: '100%',
flex: 1,
},
hora: {
fontSize: 14,
color: '#888',
fontWeight: 'bold',
textAlign: 'center',
},
number: {
fontSize: 50,
marginVertical: 4,
fontWeight: 'bold',
justifyContent: 'center',
color: Colors.secondary,
},
title: {
fontSize: 14,
margin: 5,
fontWeight: 'bold',
textAlign: 'center',
//flexWrap: 'wrap',
flex: 2,
flexGrow: 1,
},
title2: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
color: 'red',
},
date: {
fontSize: 14,
marginVertical: 4,
textAlign: 'center',
flex: 1,
flexGrow: 1,
marginHorizontal: 2,
},
});

How can I change styles of an array element in react native

I leave a small code of sample of as I have my code, in fact my code I show it inside a FlatList... but here I leave him something similar in .map that is practically the same thing, they are dynamic Views, I wish that on having clicked in the button, that View change Styles (Position Abosulte, Width, Backgorund color and more)
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
import Constants from 'expo-constants';
import AssetExample from './components/AssetExample';
let shopping = ['bread', 'milk', 'cheese', 'hummus', 'noodles'];
export default function App() {
return (
<View style={styles.container}>
{shopping.map((data, idx) => {
return (
<View
style={{
width: '100%',
height: 70,
backgroundColor: '#f7f7f7',
marginTop: 5,
marginBottom: 5,
borderColor: '#dfdfdf',
borderWidth: 1,
alignItems: 'center',
}}>
<Text>Tex: {data}</Text>
//I press this buttom, i want change this View Styles!!!, only this view
<TouchableOpacity onPress={() => {}}>
<View
style={{
width: '100%',
height: 30,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f7f7f7',
marginTop: 5,
marginBottom: 5,
borderColor: '#dfdfdf',
borderWidth: 1,
borderRadius: 15,
}}>
<Text style={{ width: '100%' }}>Change</Text>
</View>
</TouchableOpacity>
</View>
);
})}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});
You can have a state variable and then set it to change the style.
<TouchableOpacity onPress={() => this.setState({changeStyleIndex:index})}>
<View
style={this.state.changeStyleIndex != index{
width: '100%',
height: 30,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f7f7f7',
marginTop: 5,
marginBottom: 5,
borderColor: '#dfdfdf',
borderWidth: 1,
borderRadius: 15,
}:{change style goes here}}>
<Text style={{ width: '100%' }}>Change</Text>
</View>
</TouchableOpacity>
import React from 'react'
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
import Constants from 'expo-constants';
let shopping = ['bread', 'milk', 'cheese', 'hummus', 'noodles'];
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
BackColor = '#f7f7f7',
StateWidth: '100%'
}
}
HandleChange = () => {
this.setState({
BackColor: 'red',
StateWidth: '50%'
})
}
render() {
const { BackColor, StateWidth } = this.state
return (
<View style={styles.container}>
{shopping.map((data, idx) => {
return (
<View
style={{
width: { StateWidth },
height: 70,
backgroundColor: { BackColor },
marginTop: 5,
marginBottom: 5,
borderColor: '#dfdfdf',
borderWidth: 1,
alignItems: 'center',
}}>
<Text>Tex: {data}</Text>
//I press this buttom, i want change this View Styles!!!, only this view
<TouchableOpacity onPress={() => { this.HandleChange }}>
<View
style={{
width: '100%',
height: 30,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f7f7f7',
marginTop: 5,
marginBottom: 5,
borderColor: '#dfdfdf',
borderWidth: 1,
borderRadius: 15,
}}>
<Text style={{ width: '100%' }}>Change</Text>
</View>
</TouchableOpacity>
</View>
);
})}
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
I used the component by class, but change it to function and it will give crt, the logic is basically this.

How to center a TextInput when the keyboard opens in React Native

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>