How to achieve the desired UI in react native - react-native

I am trying to acheive a styling as shown in the image attached below
See how here the fingerprint icon happens to be inside the border of the Textinput field but instead I am getting the output as shown below
PS:- ignore the left and right side black color borders it happens to be the simulator body just focus on the UI.
Here's my code :-
import { View, Text, TextInput, StyleSheet } from 'react-native'
import React from 'react'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
const TestAtom = () => {
return (
<View style={styles.searchSection}>
<TextInput style={styles.input} placeholder='User' onChangeText={(searchString) => {this.setState({searchString})}}
underlineColorAndroid="transparent"/>
<Icon style={styles.searchIcon} name='fingerprint' size={20} color= '#000' />
</View>
)
}
const styles = StyleSheet.create({
searchSection: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
searchIcon: {
// padding: 10
paddingRight: 10
},
input: {
flex: 1,
paddingTop: 10,
paddingRight: 10,
paddingBottom: 10,
paddingLeft: 0,
backgroundColor: '#fff',
color: '#424242',
borderBottomColor: '#000',
borderBottomWidth: 1
}
});
export default TestAtom
Can anyone help me with it.

You should make a View and place the Text Input and Fingerprint icon inside.
A small example of how it will look like.
<View style={{
borderWidth:1,
flex:1,
flexDirection:'row',
alignItems:'center'
}}>
<TextInput/>
<FingerIcon/>
</View>

Have the Textinput and the fingerprint icon as two components in the same view styled as flex-direction:row. Have the bottom ruler part as a separate item which draws under the View of Textinput and the Icon.
import { View, StyleSheet,SafeAreaView,TextInput } from 'react-native'
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
function UIComponent(){
<View style={styles.container}>
<View style={styles.componentWrapper}>
<View style={styles.passwordFieldWrapper}>
<TextInput style={styles.textInput} placeholder='umana Password'>
</TextInput>
<MaterialCommunityIcons name="fingerprint" color='green' size={24} />
</View>
<View style={styles.bottomPart}>
</View>
</View>
</View>
}
export default UIComponent
const styles = StyleSheet.create({
container:{
backgroundColor:'#ffffff',
flex:1
},
componentWrapper:{
alignItems:'center',
justifyContent:'center'
},
passwordFieldWrapper:{
flexDirection:'row'
},
textInput:{
width:'50%'
},
bottomPart:{
marginTop:3,
borderBottomColor:'gray',
borderBottomWidth:1,
width:'60%'
}
})

Related

How to add a Button inside TextInput in React Native

I wanna add a "Verify" button inside my TextInput as shown in the picture. I tried adding a TouchableOpacity component but I think I'm doing it wrong. You guys have a solution?
Try this code it should work for you
<View style={{flexDirection:'row'}}>
<View>
<TextInput
style={{alignItems:'center',justifyContent:'center',backgroundColor:'white'}}
value = {this.state.emailId}
onChangeText = {(emailId) => {this.setState({emailId})}}
placeholder = 'Enter your email id'
onSubmitEditing = {()=>{this._fetchResults()}}
/>
</View>
<TouchableHighlight style={{alignItems:'center',justifyContent:'center'}} onPress = {()=>{this._fetchResults()}} underlayColor = 'transparent'>
<View>
<Text>Verify</Text>
</View>
</TouchableHighlight>
I couldnt get the styling down right but here's this will get you in the right direction
import * as React from 'react';
import {
Text,
View,
StyleSheet,
TextInput,
TouchableOpacity,
} from 'react-native';
import Constants from 'expo-constants';
export default function App() {
return (
<View style={styles.container}>
<View style={styles.firstBox}>
<View style={styles.row}>
<TextInput
placeholder="Email id"
placeholderTextColor="gray"
style={styles.input} />
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Verify</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
padding: 8,
backgroundColor: 'lightgreen',
},
buttonText:{
textDecorationLine:"underline"
},
input: {
flex: 2,
borderRadius:5
},
button: {
flex: 0.5,
alignItems: 'center',
},
firstBox: {
backgroundColor: 'green',
paddingBottom: 2,
top:-2,
borderRadius:5
},
row: {
flexDirection: 'row',
width: '100%',
backgroundColor: 'white',
padding:5,
borderRadius:5
},
});

Button Styles not working in react native

I want to change button borderRadius,color, and padding but it doesn't work
this is my view
import * as React from 'react';
import { StatusBar } from 'expo-status-bar';
import { Button, StyleSheet, Text, View, Image} from 'react-native';
import {NavigationContainer} from '#react-navigation/native';
import {createStackNavigator} from '#react-navigation/stack';
function HomeScreen({navigation}) {
return(
<View
style={styles.container}>
<Text>Home Screen</Text>
<Button
style={styles.button}
title= "Go To Details"
onPress={()=> navigation.navigate('Details')}
/>
</View>
)
}
and this is my styles
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
button: {
width: 200,
marginTop: 20,
backgroundColor: "green",
padding: 15,
borderRadius: 50,
},
});
this is my screen
are there something that i miss?
I don't think so you can customize like your own with react native Button. But you can change something like title, color, etc. Check their doc https://reactnative.dev/docs/button
A better way is to make your own Button with your custom Style like this :
<TouchableOpacity onPress={()=> navigation.navigate('Details')}>
<View style={styles.button}>
<Text>Go To Details</Text>
</View>
</TouchableOpacity>
I'll suggest you to use View, because button from 'react-native' have some default styling and there can be some difficulty to override them, you can customise View like anything you want. just have a View and give them desired styles.
function HomeScreen({navigation}) {
return(
<View
style={styles.container}>
<Text>Home Screen</Text>
<View
style={styles.button}
title= "Go To Details"
onPress={()=> navigation.navigate('Details')}
/>
</View>
)
}
just give styles you want
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
button: {
width: 200,
marginTop: 20,
backgroundColor: "green",
padding: 15,
borderRadius: 50,
},
});

React native align icon and text

for the love of God, every styling i put on the stylesheet doesn't change anything.
i tried style the view, sectionheader & sectionbox but no luck
i want to align 4 icons in the boxsection and text below then as such, please any help would be appreciated.
export default class HomePage extends Component {
render() {
return (
<View>
<SectionHeader title={'Food'} />
<View >
<SectionBox >
<Icon style={styles.icons} name="icon name" size={50} />
<Icon style={styles.icons} name="icon name" size={50} />
<Icon style={styles.icons} name="icon name" size={50} />
<Icon style={styles.icons} name="icon name" size={50} />
<Text style={styles.sectiontext}>burgers</Text>
</SectionBox>
</View>
const styles = StyleSheet.create({
icons: {
flexDirection: 'row',
paddingTop: 7,
paddingLeft: 5,
},
sectiontext: {
fontSize: 15,
fontWeight: 'bold',
paddingLeft: 5,
alignItems: 'center',
}
});
For the icons-containing-box you would need to indicate flexDirection and flexWrap, not directly on the icon's style. Then to get the text below each icon you need to wrap icon and text in its own view and give that 'column' direction.
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Ionicons } from '#expo/vector-icons';
import { Constants } from 'expo';
const ICON_SIZE = 70;
const FONT_SIZE = 18;
const getItem = () => (
<View style={styles.iconStyle}>
<Ionicons name="md-checkmark-circle" size={ICON_SIZE} color="green" />
<Text style={styles.textStyle}>name</Text>
</View>
);
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.iconContainer}>
{getItem()}
{getItem()}
{getItem()}
{getItem()}
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
iconContainer: {
width: ICON_SIZE * 2,
flexDirection: 'row',
flexWrap: 'wrap',
},
iconStyle: {
flexDirection: 'column',
alignItems: 'center',
padding: 5,
},
textStyle: {
fontSize: FONT_SIZE,
},
});
You need a view for each group of icon and text with a flexDirection: 'column' and one another view for each row (or column), like the example below:
https://snack.expo.io/HJY7IWsFm
Other option is to use a GridView lib:
https://github.com/saleel/react-native-super-grid

Invariant Violation: ScrollView child layout (["justifyContent"]) must be applied through the contentContainerStyle prop

[The Error image 1]
Current Behaviour
I receive this image if I am trying to nest a ScrollView within the View.
Expected Behaviour
Since the KeyBoardAvoidingView pushes the input boxes to the top and hides some of them I want a ScrollView to be able to scroll through the input boxes so hiding content can be seen but when I try to do it with my code I get the error in the above image.
import React from 'react';
import {StyleSheet, View, TextInput, TouchableOpacity, Text, KeyboardAvoidingView, StatusBar, ScrollView} from 'react-native';
export default class SignUp extends React.Component {
constructor(props) {
super(props);
}
render() {
return(
<KeyboardAvoidingView behavior="padding" keyboardVerticalOffset={60} style={styles.container}>
<StatusBar backgroundColor = "#FFFFFF" barStyle = "dark-content" hidden = {true}/>
<View style={styles.boxContainer}>
<View style = {[styles.boxContainer, styles.boxOne]}>
<ScrollView style = {[styles.boxContainer, styles.boxOne]} >
<TextInput
style={styles.inputBox}
placeholder="full name"
placeholderTextColor="#00000030"
underlineColorAndroid="transparent">
</TextInput>
<TextInput
style={styles.inputBox}
placeholder="email or phone"
placeholderTextColor="#00000030"
underlineColorAndroid="transparent"
autoCapitalize="none">
</TextInput>
<TextInput
style={styles.inputBox}
placeholder="date of birth"
placeholderTextColor="#00000030"
underlineColorAndroid="transparent"
autoCapitalize="none">
</TextInput>
<TextInput
style={styles.inputBox}
placeholder="username"
placeholderTextColor="#00000030"
underlineColorAndroid="transparent"
autoCapitalize="none">
</TextInput>
<TextInput
style={styles.inputBox}
secureTextEntry={true}
placeholder="password"
placeholderTextColor="#00000030"
underlineColorAndroid="transparent"
autoCapitalize="none">
</TextInput>
</ScrollView>
</View>
<View style={styles.boxContainerToggle}>
<TouchableOpacity
style={[styles.boxContainer, styles.boxTwo]}>
<Text style={styles.paragraph}>Login</Text>
</TouchableOpacity>
</View>
</View>
</KeyboardAvoidingView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
boxContainer: {
flex: 1, // 1:3
justifyContent: 'center',
},
boxContainerToggle: {
flex: 1,
flexDirection: 'row',
padding: 20,
backgroundColor: 'white',
},
boxOne: {
flex: 5, // 5:6
backgroundColor: 'white',
padding: 20
},
boxTwo: {
flex: 1, // 1:6
backgroundColor: '#252525',
flexDirection: 'row',
width: '100%',
height: '100%',
alignItems: 'center'
},
inputBox: {
height: 40,
backgroundColor: '#B6B6B630',
marginBottom: 10,
paddingHorizontal: 10,
},
paragraph: {
fontSize: 27,
fontWeight: 'bold',
textAlign: 'center',
color: '#FFFFFF',
},
});
So looks like the problem lies with the style for boxContainer. ScrollView does not support justifyContent unless you either pass it as a part of the contentContainerStyle prop or you wrap all your content inside the ScrollView and give justify content to that view. Personal experience says wrap your content inside the scrollview in its own view tag.
<ScrollView style={ styles.boxOne }
<View style={ style.boxContainer }>
{content goes here}
</View>
</ScrollView>
Please Use contentContainerStyle instead style
<ScrollView contentContainerStyle={styles.scrollView}>
<Text>Hello World!</Text>
</ScrollView>
I had same issue with my flatlist. That's enought to move to another alignItems: 'center' and justifyContent: 'center',
<FlatList
style={styles.screen}
data={orders}
renderItem={itemData =>
<View style={styles.screenView}>
<Text>{itemData.item.totalAmount}</Text>
</View>}
/>
const styles = StyleSheet.create({
screen: {
flex: 1,
backgroundColor: Colors.background,
},
screenView: {
alignItems: 'center',
justifyContent: 'center',
}})
The positioning of child elements of the ScrollView must be done through contentContainerStyle prop.
In this case the justify content must be part of the contentContainerStyle prop and other styles can be part of style prop. Example code is shown as below:
<ScrollView horizontal={true} style={styles.scrollWrapper} contentContainerStyle={styles.scrollContent}>
... {children}
</ScrollView>
and the styles can be applied as below. flex: 1 along with justifyContent: 'center' centers the content of ScrollView.
const styles = StyleSheet.create({
scrollWrapper: {
borderBottomColor: COLORS.line_grey,
borderBottomWidth: 1
},
scrollContent:{
justifyContent: 'center',
flex:1
}
})

Progress Dialog in ReactNative

I'm pretty new to ReactNative world. Im struggling to find an api or a library that shows the Progress Dialog as below in React Native. I believe ActivityIndicator can be used, but it does not show as overlay. Can anyone help me how can I show as an overlay using styles or if there is good library to make this.
Thanks
Here is the code to Open Prgressbar:
import React from 'react';
import { Modal, View, Text, ActivityIndicator, Button } from 'react-native';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = { isProgress: false }
}
openProgressbar = () => {
this.setState({ isProgress: true })
}
render() {
return (
this.state.isProgress ?
<CustomProgressBar />
:
<View style={{ flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center' }}>
<Button title="Please click here to Open ProgressBar" onPress={this.openProgressbar} />
</View>
);
}
}
const CustomProgressBar = ({ visible }) => (
<Modal onRequestClose={() => null} visible={visible}>
<View style={{ flex: 1, backgroundColor: '#dcdcdc', alignItems: 'center', justifyContent: 'center' }}>
<View style={{ borderRadius: 10, backgroundColor: 'white', padding: 25 }}>
<Text style={{ fontSize: 20, fontWeight: '200' }}>Loading</Text>
<ActivityIndicator size="large" />
</View>
</View>
</Modal>
);
Expo url for live demo
https://snack.expo.io/#jitendra.mca13/progress-bar-demo
I would approach this by using the React Native Modal component with two Views.
This solution is a React solution and not native, so you will need to style your Modal accordingly for each platform.
import React from 'react';
import {
Modal,
View,
StyleSheet,
Text,
ActivityIndicator
} from 'react-native';
const ProgressDialog = ({ visible }) => (
<Modal
visible={visible}
>
<View style={styles.container}>
<View style={styles.content}>
<Text style={styles.title}>Please Wait</Text>
<View style={styles.loading}>
<View style={styles.loader}>
<ActivityIndicator size="large" />
</View>
<View style={styles.loadingContent}>
<Text>Loading</Text>
</View>
</View>
</View>
</View>
</Modal>
);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, .5)',
alignItems: 'center',
justifyContent: 'center',
},
content: {
padding: 35,
backgroundColor: 'white'
},
title: {
fontSize: 18,
fontWeight: 'bold',
},
loading: {
flexDirection: 'row',
alignItems: 'center',
},
loader: {
flex: 1,
},
loadingContent: {
flex: 3,
fontSize: 16,
paddingHorizontal: 10,
}
})
export default ProgressDialog;
Here's a demo on Expo, of course you will probably want to tweak the CSS.
Android & iOS solution
Create a directory called ProgressDialog
Create index.ios.js and index.android.js
Paste the above code into both index.ios.js and index.android.js
Make CSS changes for iOS
You can use the below npm package which is a very easy and attractive loader with many options.
https://github.com/maxs15/react-native-spinkit
import React from 'react';
import { StyleSheet, View } from "react-native";
import Spinner from "react-native-spinkit";
export default LoadingCmpBig = props => {
return (
<View style={styles.container}>
<StatusBar barStyle="default" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
//backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
}
});
You can use this component and use it where you want to show the Progress. You just have to maintain the state for visible the loading or not in your render function of the component.