import { useState } from "react";
import { View,Text, Button, TextInput} from "react-native";
export default function Prime()
{
const[key,setKey] =useState("")
const[num1,setNum1] = useState(0)
const changeState=()=>
{
var out = ""
const data = num1;
var i=0;
for(i=2;i<data;i++)
{
if(data%i==0)
{
out = "not prime";
break
}
}
if(data==i)
{
out = "prime"
}
setKey(out)
}
return(
<View>
<TextInput type="number" placeholder="Enter First Number"
onChangeText={v=>{setNum1(v)}} />
<Button title="click" onPress={changeState} />
<Text>{key}</Text>
</View>)
}
Assignment:-
Create Marksheet Program in React-native:-
Q) WAP to create a mark sheet of Students using five different subjects with the following condition?
1) All Subject Marks Should be 0 to 100.
2) If only Subject Mark is <33 Then Student will Suppl
3) If the Minimum Two Subjects Marks is <33 Then Student Will Fail
4) IF all Subject Marks is > 33 then percentage and division should be calculated.
5) IF only one subject Mark is >28 and <33 then 5 grace marks will be applied and the student will be passing by grace.
6) Display Grace Subject Name, Distinction Subject name, Supp Subject name, and Failed Subject name.
ListView Element in React-Native:-
React Native ListView
React Native ListView is a view component which contains the list of items and displays in a vertical scrollable list.
The minimum API to create list view is ListView.DataSource.
It populates a simple array of data blobs, and instantiate a ListView component with
data source and a renderRow callback.
The renderRow takes a blob from data array and returns a renderable component.
Now ListView is deprecated because ListView Work can be managed by FlatList
import { Component } from "react"
import {View,StyleSheet,FlatList,Text,Alert} from "react-native"
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 22,
},
item: {
padding: 10,
fontSize: 18,
height: 44,
},
});
class ListViewExample extends Component {
constructor()
{
super()
this.state={dataSource:[
{key: 'Devin'},
{key: 'Dan'},
{key: 'Dominic'},
{key: 'Jackson'},
{key: 'James'},
{key: 'Joel'},
{key: 'John'},
{key: 'Jillian'},
{key: 'Jimmy'},
{key: 'Julie'},
]}
}
render(){
return (
<View style={styles.container}>
<FlatList
data={this.state.dataSource}
renderItem={({item}) => <Text style={styles.item}>{item.key}</Text>}
/>
</View>
);
}
};
export default ListViewExample;
React Native SectionList
The React Native SectionList component is a list view component
which sets the list of data into the broken logical section.
The broken data can be implemented using its section header prop renderSectionHeader.
To implement the SectionList component,
we need to import SectionList from 'react-native' library.
React Native SectionList Example
In this example, we create a SectionList with title and data.
The section prop is used to create the list of title and data values.
The renderSectionHeader displays the header section of the list view.
import React, { Component } from 'react';
import { AppRegistry, SectionList, StyleSheet, Text, View } from 'react-native';
export default class SectionListBasics extends Component {
render() {
return (
<View style={styles.container}>
<SectionList
sections={[
{title: 'A', data: ['ALTERED','ABBY','ACTION U.S.A.','AMUCK','ANGUISH']},
{title: 'B', data: ['BEST MEN','BEYOND JUSTICE','BLACK GUNN','BLOOD RANCH','BEASTIES']},
{title: 'C', data: ['CARTEL', 'CASTLE OF EVIL', 'CHANCE', 'COP GAME', 'CROSS FIRE',]},
]}
renderItem={({item}) => <Text style={styles.item}>{item}</Text>}
renderSectionHeader={({section}) => <Text style={styles.sectionHeader}>{section.title}</Text>}
keyExtractor={(item, index) => index}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#5ead97"
},
sectionHeader: {
paddingTop: 2,
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 2,
fontSize: 22,
fontWeight: 'bold',
color: "#fff",
backgroundColor: '#8fb1aa',
},
item: {
padding: 10,
fontSize: 18,
height: 44,
}
})
Adding Separator in SectionList
ItemSeparatorComponent prop adds the Separator between the lists of data.
Using this prop, call a renderSeparatormethod in which we add a View component as separator.
renderSeparator = () => {
return (
<View
style={{
height: 1,
width: "100%",
backgroundColor: "#000",
}}
/>
);
};
ItemSeparatorComponent={this.renderSeparator}
Performing action on SectionList items
To perform an action on clicking (pressing) the list item, we use a onPress prop. The onPress prop and handle the event in another method getListViewItem.
//handling onPress action
getListViewItem = (item) => {
alert(item);
}
renderItem={({item}) => <Text style={styles.item}
onPress={this.getListViewItem.bind(this, item)}>{item}</Text>}
thanks for valuable information
ReplyDeleteReact Training in Hyderabad
I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog,
ReplyDeletekeep updates regularly.
salesforcemasters.in/salesforce-lightning-training-in-hyderabad/