Create A Dating Site In React
DatePicker dialog is used to pick date in Android and iOS applications. By default react native has two different DatePicker component 1st one is DatePickerIOS and 2nd is DatePickerAndroid, but it is very difficult to configure two component for single task. So after finding a lot on Internet finally i found an immersive library called as react-native-datepicker-dialog . This library comes with an awesome functionality that using a single code developers can create DatePicker for both android and iOS applications. So let’s get started 🙂 .
Contents in this project React Native Common DatePicker for Android and iOS tutorial :
Create A Dating Site In React App
1. Start a fresh React Native project. If you don’t know how then read my this tutorial.
Create react app is a starter kit that helps to start a React website without learning and configuring many build tools. You don’t need to rebuild the whole application when developing. Instant reloads do all the work for you. Under the hood, Create react app use Webpack, Babel, ESLint, and other projects. React datepicker is reusable datepicker component. React does not have a datepicker module but we can use the react-datepicker third-party library.
- Nov 16, 2021 So, after a successful installation of Node.js, create a React application using NPX. Npx create-react-app react-multi-page-website. This command will create a react application with the project name react-multi-page-website. Now enter the project directory and start the app. Cd react-multi-page-website npm start. It will open up the React application we have created in our browser window with the address The port may vary if 3000 is busy.
- The production build has all the tools necessary to generate a first-class.
2. Add react-native-datepicker-dialog library inside your project :
Open Your project in command prompt and execute below command inside your project’s folder.
3. After successfully installed the react-native-datepicker-dialog library we need to install another library known as moment. To install the moment library inside your project execute the below command in project’s folder.
4. Import AppRegistry, StyleSheet, Text, View, TouchableOpacity in your project.
2 | import{AppRegistry,StyleSheet,Text,View,TouchableOpacity}from'react-native'; |
How To Create A Multi-page Website With React In 5 Minutes ← Techom…
5. Import DatePickerDialog and moment .
2 | import{DatePickerDialog}from'react-native-datepicker-dialog' import moment from'moment'; |
6. Create constructor in your main class with props and define two variables DateText and DateHolder using state.
DateText : is used to show date on screen using Text component.
DateHolder : is used to get date from DatePicker dialog.
2 4 6 8 10 12 | } |
7. Create a function named as DatePickerMainFunctionCall() . This function would call on Text box onPress event.
Medium.com › @Preda › Getting-started-on-building-aGetting Started On Building A Personal Website/webapp With React
2 4 6 | this.setState({ DateText:moment(date).format('DD-MMM-YYYY') } |
9. Create a Parent View in render’s return block and add Text Component inside it to show the Application name, After that Create a TouchableOpacity component and call the DatePickerMainFunctionCall on the onPress of TouchableOpacity. Now make a View inside the TouchableOpacity and create another Text component inside it, Which would show us the selected date.
2 4 6 8 10 12 14 16 18 20 22 24 26 | return( <TouchableOpacity onPress={this.DatePickerMainFunctionCall.bind(this)}> <View style={styles.datePickerBox}> <Text style={styles.datePickerText}>{this.state.DateText}</Text> </View> </TouchableOpacity> {/* Place the dialog component at end of your views and assign the references, event handlers to it.*/} <DatePickerDialog ref='DatePickerDialog'onDatePicked={this.onDatePickedFunction.bind(this)}/> </View> } |
10. Create CSSStylesheet for all views.
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 | container:{ padding:10, }, content:{ textAlign:'center', }, datePickerBox:{ borderColor:'#FF5722', padding:0, borderTopRightRadius:4, borderBottomRightRadius:4, justifyContent:'center' fontSize:14, borderWidth:0, }); |
11. Now call the AppRegistry .
AppRegistry.registerComponent('Mainproject',()=>Mainproject); |
12. Complete source code for index.android.js / index.ios.js file
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 | import{AppRegistry,StyleSheet,Text,View,TouchableOpacity}from'react-native'; import{DatePickerDialog}from'react-native-datepicker-dialog' import moment from'moment'; exportdefaultclassMainprojectextendsComponent{ constructor(props){ super(props); this.state={ DateText:', DateHolder:null, } * Textbox click listener DatePickerMainFunctionCall=()=>{ let DateHolder=this.state.DateHolder; if(!DateHolder DateHoldernull){ DateHolder=newDate(); DateHolder:DateHolder } //To open the dialog * Call back for dob date picked event */ this.setState({ DateText:moment(date).format('DD-MMM-YYYY') } render(){ <View style={styles.container}> <Text style={styles.content}> React NativeDate Picker Dialog Example </Text> <TouchableOpacity onPress={this.DatePickerMainFunctionCall.bind(this)}> <View style={styles.datePickerBox}> <Text style={styles.datePickerText}>{this.state.DateText}</Text> </View> </TouchableOpacity> {/* Place the dialog component at end of your views and assign the references, event handlers to it.*/} <DatePickerDialog ref='DatePickerDialog'onDatePicked={this.onDatePickedFunction.bind(this)}/> </View> } container:{ padding:10, }, content:{ textAlign:'center', }, datePickerBox:{ borderColor:'#FF5722', padding:0, borderTopRightRadius:4, borderBottomRightRadius:4, justifyContent:'center' fontSize:14, borderWidth:0, }); AppRegistry.registerComponent('Mainproject',()=>Mainproject); |
Www.techomoro.com › How-to-create-a-multi-pageHow To Create A Multi-page Website With React In 5 Minutes ...
Screenshot in Android device :
Screenshot in iOS device :