How to implement time picker functionality in react native - react-native

I want to implement a functionality that should allow me to pick time within a range.
it should be like this
I have used react-native-slider and my code is here
import React, { Component } from 'react';
import { View, Text, Image, TextInput, StyleSheet } from 'react-native';
import Slider from 'react-native-slider';
import colors from '../styles/colors';
import Strings from '../localization/strings';
class FindDoctor extends Component {
constructor(props) {
super(props);
this.state = {
value: 6,
};
}
getInitialState() {
return {
value: 2,
};
}
render() {
return (
<View style={styles.container}>
<View style={{ flexDirection: 'column', margin: 20 }}>
<Text style={styles.textStyle}>Looking for</Text>
<View style={styles.input}>
<TextInput
placeholder={Strings.InternalMedicine}
autoCorrect={this.props.autoCorrect}
autoCapitalize={this.props.autoCapitalize}
returnKeyType={this.props.returnKeyType}
placeholderTextColor={colors.dimgray}
underlineColorAndroid="transparent"
onChangeText={TextInputName => this.setState({ TextInputName })}
/>
</View>
</View>
<View style={{ flexDirection: 'column', margin: 20 }}>
<Text style={styles.textStyle}>Near</Text>
<View style={styles.input}>
<TextInput
placeholder={Strings.Place}
autoCorrect={this.props.autoCorrect}
autoCapitalize={this.props.autoCapitalize}
returnKeyType={this.props.returnKeyType}
placeholderTextColor={colors.dimgray}
underlineColorAndroid="transparent"
onChangeText={TextInputName => this.setState({ TextInputName })}
/>
</View>
</View>
<View style={{ flexDirection: 'column', margin: 20 }}>
<Text style={styles.textStyle}>Within</Text>
<View style={styles.sliderStyles}>
<Slider
value={this.state.value}
onValueChange={(value) => this.setState({ value })}
minimumValue={4}
maximumValue={10}
step={10}
/>
<Text>value: {this.state.value}</Text>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
textStyle: {
fontSize: 20,
color: colors.brandBlue,
},
input: {
backgroundColor: colors.white,
height: 40,
width: '80%',
marginTop: 5,
borderRadius: 4,
alignItems: 'flex-start',
justifyContent: 'flex-start',
borderWidth: 1,
borderColor: colors.light_gray,
fontSize: 20
},
sliderStyles: {
//margin: 10,
alignItems: 'stretch',
justifyContent: 'center',
},
});
export default FindDoctor;
and now the output look like this
But i want to add multiples values in slider like the image shown above
can anyone help me to add multiple values in slider

Related

FlatList - react native not scrolling

I am unable to get my Flatlist to scroll in my expo react native app. At the moment it is just static, displaying a grid of images int he Flatlist with no scrolling functionality. Please can someone advise?
I am unable to get my Flatlist to scroll in my expo react native app. At the moment it is just static, displaying a grid of images int he Flatlist with no scrolling functionality. Please can someone advise?
import { StyleSheet, Text, View, Button, TextInput, TouchableWithoutFeedback, Keyboard, FlatList, ActivityIndicator } from 'react-native';
import { Image } from '#rneui/themed';
import ImageAPI from '../shared-components/ImageAPI';
export default function Home({ navigation }) {
const onCreate = () => {
console.log('create my image now');
};
return (
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<View style={styles.container}>
{/** Enter text prompt */}
<View style={styles.section1}>
<View style={styles.txtInputView}>
<TextInput
style={styles.txtInput}
placeholder='Enter a prompt - a description of what you want to create'
multiline={true}
numberOfLines={4}
/>
</View>
<View style={styles.buttonView}>
<Text
style={styles.createBtnText}
onPress={onCreate}
>Create</Text>
</View>
</View>
{/** PROMPT EXAMPLES */}
<View style={styles.section2}>
<View style={styles.section2_sub0}>
<Text style={styles.promptEgTxt}>Prompt Examples</Text>
</View>
<View style={styles.section2_sub1}>
<ImageAPI />
</View>
</View>
</View>
</TouchableWithoutFeedback>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
section1: {
flex: 2,
width: '100%',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ffc6e2',
},
section2: {
flex: 5,
width: '100%',
backgroundColor: '#F8DB93',
},
// section3: {
// flex: 3,
// backgroundColor: '#BCF893',
// },
txtInputView: {
flex: 3,
width: '85%',
height: '50%',
alignItems: 'center',
justifyContent: 'center',
marginTop: 20,
marginBottom: 20
},
buttonView: {
flex: 2,
width: '70%',
alignItems: 'center',
justifyContent: 'center',
marginBottom: 20,
backgroundColor: '#EE4A4A',
borderRadius: 40
},
txtInput: {
borderColor: '#AAAAAA',
borderWidth: 2,
padding: 10,
borderRadius: 15,
// width: '85%',
// height: '50%',
width: '100%',
height: '100%',
fontSize: 15,
},
createBtnText: {
fontSize: 18,
fontWeight: 'bold',
// backgroundColor: '#EEEC4A'
},
section2_sub0: {
flex: 1,
width: '100%',
height: '100%',
backgroundColor: '#EEEC4A',
justifyContent: 'center',
},
promptEgTxt: {
fontSize: 15,
fontWeight: 'bold',
marginLeft: 10
},
section2_sub1: {
flex: 8,
width: '100%',
height: '100%',
backgroundColor: '#A9F889'
},
});
This is the ImageAPI.js file:
import React from 'react';
import { FlatList, SafeAreaView, StyleSheet, ActivityIndicator, View, ScrollView } from 'react-native';
import { Image } from '#rneui/themed';
const BASE_URI = 'https://source.unsplash.com/random?sig=';
const ImageAPI = () => {
return (
<>
<SafeAreaView>
<FlatList
data={[...new Array(10)].map((_, i) => i.toString())}
style={styles.list}
numColumns={2}
keyExtractor={(e) => e}
renderItem={({ item }) => (
<Image
transition={true}
source={{ uri: BASE_URI + item }}
containerStyle={styles.item}
PlaceholderContent={<ActivityIndicator />}
/>
)}
/>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
list: {
width: '100%',
backgroundColor: '#000',
},
item: {
aspectRatio: 1,
width: '100%',
flex: 1,
},
});
export default ImageAPI
you need to give it a fixed height and set the contentContainerStyle prop to { flexGrow: 1 }. This will allow the content inside the FlatList to exceed the bounds of the container and be scrollable.
<View style={styles.section2_sub1}>
<FlatList
contentContainerStyle={{ flexGrow: 1 }}
data={data}
renderItem={({ item }) => <ImageAPI data={item} />}
keyExtractor={(item) => item.id}
/>
</View>
Try adding flex according to your requirement to your <SafeAreaView> which is the parent to your <Flatlist> Something like this:
<>
<SafeAreaView style = {{flex: 8}} >
<FlatList
data={[...new Array(10)].map((_, i) => i.toString())}
style={styles.list}
numColumns={2}
keyExtractor={(e) => e}
renderItem={({ item }) => (
<Image
transition={true}
source={{ uri: BASE_URI + item }}
containerStyle={styles.item}
PlaceholderContent={<ActivityIndicator />}
/>
)}
/>
</SafeAreaView>
</>
Or remove the SafeAreaView if not required.
Both should work.

index.js:1 Unexpected text node: . A text node cannot be a child of a <View>

hellow, im new on react native, i want to create an app, fisrt in try to build its formula. it show me an error: {index.js:1 Unexpected text node: . A text node cannot be a child of a .}. here is my code i apreciate your help. (its a small calculator)
error: index.js:1 Unexpected text node: . A text node cannot be a child of a .
import React, {useState, useEffect, Component} from 'react';
import { AppRegistry, Text, View, TextInput, StyleSheet, Input, TouchableOpacity } from 'react-native';
import { Ionicons } from '#expo/vector-icons';
export default class App extends Component {
constructor(props){
super(props);
this.state = {
numero1 : 0,
numero2 : 0,
resultado : 0
}
}
sumar = () => {
console.log(this.state.numero1);
let num1 = parseFloat(this.state.numero1);
let num2 = parseFloat(this.state.numero2);
let res = num1 + num2;
this.setState({resultado : res})
}
render(){
return (
<View style={styles.container}>
<View>
<Text style={styles.Titulos}>INVERGEGA</Text>
</View>
<View> <Text> VALOR 1 </Text> </View>
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
value={this.state.numero1}
onChangeText={(text) => {this.setState({numero1 : text})}} />
</View>
<View> <Text>VALOR 2</Text> </View>
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
value={this.state.numero2}
onChangeText={(text) => {this.setState({numero2 : text})}} />
</View>
<View>
<Text>RESULTADO</Text>
</View>
<View style={styles.container2}>
<Text name="resultado">{this.state.resultado}</Text>
</View>
<TouchableOpacity style={styles.container2} name="btnCalcular"
onPress={this.sumar}><Text> Hit me daddy!</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'gray',
},
inputContainer: {
width: '90%',
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 10,
borderWidth: 1,
borderColor: 'gray',
borderRadius: 30,
backgroundColor: 'lightgray'
},
textInput: {
paddingLeft: 10,
flex: 1,
height: 50,
},
container2: {
width: '90%',
height: '5%',
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 10,
borderWidth: 1,
borderColor: 'gray',
borderRadius: 30,
backgroundColor: 'white',
},
Text1: {
fontWeight: 'bold',
fontSize: 22,
color: 'red'
},
Text2: {
fontWeight: 'bold',
fontSize: 22,
},
Titulos: {
fontWeight: 'bold',
fontSize: 40,
}
}
);
AppRegistry.registerComponent('Bursakaxx1', () => App);

Adding ImageBackground to React Native Login Screen

I found this great code sample/layout -- see below -- for a React Native login screen. All I want to do is to have an ImageBackground as opposed to the current solid background.
When I add ImageBackground to the code, it throws everything off and instead of the image covering the entire screen, everything gets squished in the middle and all alingment gets out of whack. What am I doing wrong here?
Here's the original code with solid background:
import React from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';
export default class App extends React.Component {
state={
email:"",
password:""
}
render(){
return (
<View style={styles.container}>
<Text style={styles.logo}>HeyAPP</Text>
<View style={styles.inputView} >
<TextInput
style={styles.inputText}
placeholder="Email..."
placeholderTextColor="#003f5c"
onChangeText={text => this.setState({email:text})}/>
</View>
<View style={styles.inputView} >
<TextInput
secureTextEntry
style={styles.inputText}
placeholder="Password..."
placeholderTextColor="#003f5c"
onChangeText={text => this.setState({password:text})}/>
</View>
<TouchableOpacity>
<Text style={styles.forgot}>Forgot Password?</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.loginBtn}>
<Text style={styles.loginText}>LOGIN</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.loginText}>Signup</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#003f5c',
alignItems: 'center',
justifyContent: 'center',
},
logo:{
fontWeight:"bold",
fontSize:50,
color:"#fb5b5a",
marginBottom:40
},
inputView:{
width:"80%",
backgroundColor:"#465881",
borderRadius:25,
height:50,
marginBottom:20,
justifyContent:"center",
padding:20
},
inputText:{
height:50,
color:"white"
},
forgot:{
color:"white",
fontSize:11
},
loginBtn:{
width:"80%",
backgroundColor:"#fb5b5a",
borderRadius:25,
height:50,
alignItems:"center",
justifyContent:"center",
marginTop:40,
marginBottom:10
},
loginText:{
color:"white"
}
});
This produces this nice layout:
And I simply add an image background with the following code which doesn't work at all:
<View style={styles.container}>
<ImageBackground
source={require("../../assets/images/background/teton_snake_dimmed.jpg")}
style={styles.imageBackground}
>
<Text style={styles.logo}>HeyAPP</Text>
<View style={styles.inputView} >
<TextInput
style={styles.inputText}
placeholder="Email..."
placeholderTextColor="#003f5c"
onChangeText={text => this.setState({ email: text })} />
</View>
<View style={styles.inputView}>
<TextInput
secureTextEntry
style={styles.inputText}
placeholder="Password..."
placeholderTextColor="#003f5c"
onChangeText={text => this.setState({ password: text })} />
</View>
<TouchableOpacity>
<Text style={styles.forgot}>Forgot Password?</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.loginBtn}>
<Text style={styles.loginText}>LOGIN</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.loginText}>Signup</Text>
</TouchableOpacity>
</ImageBackground>
</View>
And here's the updated styles. The only thing I add is the imageBackground:
container: {
flex: 1,
backgroundColor: '#003f5c',
alignItems: 'center',
justifyContent: 'center',
},
logo: {
fontWeight: "bold",
fontSize: 50,
color: "#fb5b5a",
marginBottom: 40
},
imageBackground: {
flex: 1,
resizeMode: "cover"
},
inputView: {
width: "80%",
backgroundColor: "#465881",
borderRadius: 25,
height: 50,
marginBottom: 20,
justifyContent: "center",
padding: 20
},
inputText: {
backgroundColor: "#465881",
height: 50,
color: "white"
},
forgot: {
color: "white",
fontSize: 11
},
loginBtn: {
width: "80%",
backgroundColor: "#fb5b5a",
borderRadius: 25,
height: 50,
alignItems: "center",
justifyContent: "center",
marginTop: 40,
marginBottom: 10
},
loginText: {
color: "white"
}
});
What am I doing wrong here?
P.S. Here's the original code published by #Alhydra:
https://github.com/Alhydra/React-Native-Login-Screen-Tutorial/blob/master/App.js
Here is an example replace the image with the image you want
snack: https://snack.expo.io/#ashwith00/intelligent-banana
code:
import React from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
Image,
} from 'react-native';
export default class App extends React.Component {
state = {
email: '',
password: '',
};
render() {
return (
<View style={styles.container}>
<Image
style={styles.image}
source={{
uri:
'https://media.gettyimages.com/videos/loopable-color-gradient-background-animation-video-id1182636595?s=640x640',
}}
/>
<View style={styles.subContainer}>
<Text style={styles.logo}>HeyAPP</Text>
<View style={styles.inputView}>
<TextInput
style={styles.inputText}
placeholder="Email..."
placeholderTextColor="#003f5c"
onChangeText={(text) => this.setState({ email: text })}
/>
</View>
<View style={styles.inputView}>
<TextInput
secureTextEntry
style={styles.inputText}
placeholder="Password..."
placeholderTextColor="#003f5c"
onChangeText={(text) => this.setState({ password: text })}
/>
</View>
<TouchableOpacity>
<Text style={styles.forgot}>Forgot Password?</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.loginBtn}>
<Text style={styles.loginText}>LOGIN</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.loginText}>Signup</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
image: {
flex: 1,
},
container: {
flex: 1,
backgroundColor: '#003f5c',
},
subContainer: {
...StyleSheet.absoluteFillObject,
alignItems: 'center',
justifyContent: 'center',
},
logo: {
fontWeight: 'bold',
fontSize: 50,
color: '#fb5b5a',
marginBottom: 40,
},
inputView: {
width: '80%',
backgroundColor: '#465881',
borderRadius: 25,
height: 50,
marginBottom: 20,
justifyContent: 'center',
padding: 20,
},
inputText: {
height: 50,
color: 'white',
},
forgot: {
color: 'white',
fontSize: 11,
},
loginBtn: {
width: '80%',
backgroundColor: '#fb5b5a',
borderRadius: 25,
height: 50,
alignItems: 'center',
justifyContent: 'center',
marginTop: 40,
marginBottom: 10,
},
loginText: {
color: 'white',
},
});

Unable to type in a react native text field

I m trying to create a basic login page but I'm not able to write anything in text field. Here is a file login.js. How can I solve this? I'm a beginner in react-native.
import React ,{Component} from 'react';
import {View ,Text,ImageBackground,TouchableOpacity,TextInput} from 'react-native';
export default class Login extends Component
{
constructor(props)
{
super(props)
this.state={
username:"",
password:""
}
}
render()
{
return(
<ImageBackground source={require('./background2.png')}
style={{height:'100%', width:'100%'}} >
<View style={{width:'100%',height:'100%',alignSelf:'center'
,justifyContent:'center',alignContent:'center',alignItems:'center'}}>
<TextInput placeholder={"Enter the user Name"}
onChangeText={(value)=>this.setState({username:value})}
style={{height:42,width:'80%',borderBottomWidth:1}}>
</TextInput>
<TextInput placeholder={"Enter the password"}
onChangeText={(value)=>this.setState({password:value})}
style={{height:42,width:'80%',borderBottomWidth:1,marginTop:'5%'}}>
</TextInput>
<View style={{marginTop:'5%',width:'80%'}}>
<TouchableOpacity style={{borderWidth:1,height:42,width:'80%'
,justifyContent:"center",alignItems:'center',borderRadius:40,
backgroundColor:'black',alignSelf:'center',textAlign:'center'}}>
<Text style={{color:'white'}}>Login</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
);
}
}
You should try to adding value props to TextInput component. Just pass the state value that you changing onChangeText event. Something like <TextInput value={this.state.password} onChangeText={(value) => this.setState({password : value})}/>.
Please check the following snack.
https://snack.expo.io/HMDWDe!eL
It is working!!
Following is the code...
import React, { Component } from 'react';
import {
View,
Text,
ImageBackground,
TouchableOpacity,
TextInput,
} from 'react-native';
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: '',
};
}
render() {
return (
<ImageBackground
source={require('./background2.jpg')}
style={{ height: '100%', width: '100%' }}>
<View
style={{
width: '100%',
height: '100%',
alignSelf: 'center',
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
}}>
<TextInput
placeholder={'Enter the user Name'}
onChangeText={(value) => this.setState({ username: value })}
style={{
height: 42,
width: '80%',
borderBottomWidth: 1,
}}></TextInput>
<TextInput
placeholder={'Enter the password'}
onChangeText={(value) => this.setState({ password: value })}
style={{
height: 42,
width: '80%',
borderBottomWidth: 1,
marginTop: '5%',
}}></TextInput>
<View style={{ marginTop: '5%', width: '80%' }}>
<TouchableOpacity
style={{
borderWidth: 1,
height: 42,
width: '80%',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 40,
backgroundColor: 'black',
alignSelf: 'center',
textAlign: 'center',
}}>
<Text style={{ color: 'white' }}>Login</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
);
}
}

React Native: Difference in image display Android vs iOS

I am trying to show remote images that scale with flexbox surrounded by a white border and Android and iOS both don't handle my solution the way I would like them to.
iOS only shows the white border while Android only shows the image.
This is the corresponding code. Any pointers where the problems originate from?
import React, {Component} from 'react';
import {Text, View, Image} from 'react-native';
import Header from './../Header';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class DailyArticlesScreen extends Component {
constructor(props) {
super(props);
this.displayName = 'DailyArticlesScreen';
}
render() {
return (
<View style={this.props.style}>
<Header text='Heute'/>
<View style={styles.container}>
{
dummyData.articles.map(item => {
return (
<View style={styles.contentItem} key={item}>
<View style={styles.imageContainer}>
<Image
source={{uri: 'http://placekitten.com/100/100'}}
style={styles.image}
resizeMode="contain"
/>
</View>
<View style={styles.teaserTextContainer}>
<Text style={styles.teaserTitle}> Title </Text>
<Text style={styles.teaserText}> Lorem ipsum </Text>
</View>
<View style={styles.arrow}>
<Icon name='chevron-right' size={30} color="#5d686d" />
</View>
</View>
)
})
}
</View>
</View>
);
}
};
const styles={
container: {
flex: 9,
flexDirection: 'column',
alignItems: 'stretch',
backgroundColor: '#ccc'
},
contentItem: {
flex: 3,
flexDirection: 'row',
alignItems: 'stretch',
borderBottomWidth: 1,
borderBottomColor: '#929292'
},
imageContainer: {
flex: 4,
padding: 20
},
image: {
flex: 1,
borderWidth: 5,
borderColor: '#fff'
},
teaserTextContainer: {
flex: 4,
paddingBottom: 20,
paddingTop:20
},
teaserTitle: {
fontWeight: '700',
},
arrow: {
flex: 2,
alignItems: 'center',
justifyContent: 'center'
}
};
const dummyData = {
articles: [1,2,3]
};