Related
I am stuck with a problem, when am trying to search elements from listed data it's not working, I seem lots of document ad I applied it, but still, its work for me, can anyone help me.
if you have any questions please free feel to ask any time.
home.js
This is Home.js file where I wrote my all code. and here I use some React native paper components.
import React, { useEffect, useState } from 'react'
import { Text, View, FlatList, StyleSheet, ScrollView, TouchableOpacity } from 'react-native';
import { Avatar } from 'react-native-elements';
import { Searchbar, Provider, Portal, TextInput, Button } from 'react-native-paper';
import { AntDesign, Entypo } from '#expo/vector-icons';
import Modal from "react-native-modal";
export default function Home() {
const [searchquery, setSearchquery] = React.useState();
const [isModalVisible, setModalVisible] = useState(false);
const [name, setName] = React.useState('');
const [number, setNumber] = React.useState('');
const toggleModal = () => {
setModalVisible(!isModalVisible);
};
const filterItem = (text) => {
users.filter((item) => {
return item.name.toLowerCase().inludes(text.toLowerCase())
})
setSearchquery(text)
}
const [users, setUser] = useState([
{
id: 1,
name: "Ashish Nirvikar",
number: 3289768909,
},
{
id: 2,
name: "Drew Macntyre",
number: 3345661276
},
{
id: 3,
name: "Jonh Cena",
number: 9087392878
},
{
id: 4,
name: "Rock Samoa",
number: 9723780928
},
{
id: 5,
name: "Boby Lashely",
number: 8769213678
},
{
id: 6,
name: "Seth Rollins",
number: 6890326741
},
])
return (
<View >
<Searchbar
placeholder="Search Contacts"
onChangeText={(text) => setSearchquery(text)}
value={searchquery}
style={{ marginTop: 30, marginHorizontal: 10 }}
/>
<ScrollView>
{
filterItem(users).map((item, index) => {
return (
<View key={index} style={styles.names}>
<Text style={{ color: 'black', fontSize: 20, fontWeight: 'bold' }}>Name : {item.name}</Text>
<Text style={{ color: 'black' }}>Mobile no : {item.number}</Text>
</View>
)
})
}
</ScrollView>
<Modal isVisible={isModalVisible} style={{ backgroundColor: 'white', height: 50, marginBottom: 200, marginTop: 100 }}>
<View style={{ flex: 2 }}>
<Text style={{ color: 'black', fontSize: 50, textAlign: 'center' }}>Add Contact</Text>
<TextInput
style={styles.input}
label="Enter Full name"
value={name}
onChangeText={text => setName(text)}
/>
<TextInput
style={styles.input1}
label="Enter Mobile Number"
value={number}
onChangeText={text => setNumber(text)}
/>
<Button title="Hide modal" onPress={toggleModal} style={{ color: 'black', backgroundColor: 'white', borderWidth: 1, borderColor: 'gray', marginHorizontal: 10, marginTop: 15 }}>Cancle</Button>
</View>
</Modal>
<AntDesign name="plus" size={34} color="black" style={styles.plus} onPress={toggleModal} />
</View>
);
}
const styles = StyleSheet.create({
customText: {
padding: 10,
marginTop: 20,
textAlign: 'center',
backgroundColor: 'lightgray',
fontWeight: 'bold',
fontSize: 20
},
plus: {
fontSize: 50,
position: 'absolute',
top: 680,
right: 40,
backgroundColor: 'pink',
borderRadius: 15,
borderWidth: 0.5,
padding: 5,
},
names: {
padding: 15,
fontSize: 25,
fontWeight: 'bold',
backgroundColor: 'lightgray',
marginTop: 10,
borderRadius: 20,
color: 'black'
},
addcontactname: {
fontSize: 30,
textAlign: 'center',
marginTop: 10,
marginBottom: 30
},
input: {
marginHorizontal: 10,
marginBottom: 20,
marginTop: 20
},
input1: {
marginHorizontal: 10,
marginBottom: 10,
}
});
Your Searchbar should be a controlled input (call setSearchquery with the change value from the Searchbar).
Then you can use the value of searchquery to perform the filtering inline in your jsx.
Finally, use FlatList to render a list of items instead of a map inside a ScrollView.
In your example, there's no need for the list of users to be stored in state.
import React, { Component } from 'react';
import { Text, View, StyleSheet, ScrollView, FlatList } from 'react-native';
import { Searchbar } from 'react-native-paper';
const data = [...];
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
searchquery: '',
};
}
renderHeader = () => {
return (
<Searchbar
placeholder="Search Contacts"
onChangeText={(searchquery) =>
this.setState({
searchquery,
})
}
value={this.state.searchquery}
/>
);
};
renderItem = ({ item, index }) => {
return (
<View key={index} style={styles.names}>
<Text>
Name : {item.name}
</Text>
<Text>Mobile no : {item.number}</Text>
</View>
);
};
render() {
return (
<FlatList
data={data.filter((item) => {
if (!this.state.searchquery) return true
return item.name
.toUpperCase()
.includes(this.state.searchquery.toUpperCase());
})}
ListHeaderComponent={this.renderHeader}
renderItem={this.renderItem}
/>
);
}
}
Snack
you can try with this code if it will not work then call filterItem function with bracket and parameter also my code is working while the name is lowercase.
<Searchbar
placeholder="Search Contacts"
onChangeText={filterItem}
onClear={(users) => setUser('')}
value={searchquery}
style={{ marginTop: 30, marginHorizontal: 10 }}
/>
const filterItem = (text) => {
setSearchquery(text)
let searchText = text.toLowerCase()
let filterData = users
filterData = filterData.filter(function (id) {
return id.name.toLowerCase().includes(searchText)
})
setUser(filterData);
if (text === "") {
setUser(
[
{
id: 1,
name: "Ashish Nirvikar",
number: 3289768909,
},
{
id: 2,
name: "Drew Macntyre",
number: 3345661276
},
{
id: 3,
name: "Jonh Cena",
number: 9087392878
},
{
id: 4,
name: "Rock Samoa",
number: 9723780928
},
{
id: 5,
name: "Boby Lashely",
number: 8769213678
},
{
id: 6,
name: "Seth Rollins",
number: 6890326741
},
]
);
}
}
Try this
const filterItem = (searchItems) => {
searchItems.filter((item) => {
return item.name.toLowerCase().inludes(searchquery.toLowerCase())
})
}
<Searchbar
placeholder="Search Contacts"
onChangeText={(text) => setSearchquery(text)}
onClear={(text) => searchquery("")}
value={searchquery}
style={{ marginTop: 30, marginHorizontal: 10 }}
/>
<ScrollView>
{
filterItem(users).map((item, index) => {
return (
<View key={index} style={styles.names}>
<Text style={{ color: 'black', fontSize: 20, fontWeight: 'bold' }}>Name : {item.name}</Text>
<Text style={{ color: 'black' }}>Mobile no : {item.number}</Text>
</View>
)
})
}
</ScrollView>
I want to store username to local storage using #react-native-async-storage/async-storage in React Native. When I checked through console.log, username was saved successfully but while retrieving the data back to different screen using getData function, It says null. Help me to figure out the issue.
this is my storage.js file where I've kept all the Async Storage functions.
import AsyncStorage from '#react-native-async-storage/async-storage';
const storeData = async (key, value) => {
try {
await AsyncStorage.setItem(key, value)
} catch (e) {
console.log('Error on saving')
}
}
const getData = async (key) => {
try {
const value = await AsyncStorage.getItem(key)
if (value !== null) {
console.log('Promise', value)
return value
}
} catch (e) {
// error reading value
}
}
export { storeData, getData };
this is my Log In Screen file
import React, { Component, useState } from 'react';
import { View, Text, Button, ScrollView, TextInput, TouchableHighlight, StyleSheet } from 'react-native';
import * as yup from 'yup'
import { Formik } from 'formik'
import { storeData } from '../utils/storage';
const Login = (props) => {
const handleLogin = (name) => {
storeData('username',name)
props.navigation.navigate('Home')
}
return (
<Formik
initialValues={{
name: '',
password: ''
}}
onSubmit={values => Alert.alert(JSON.stringify(values))}
validationSchema={yup.object().shape({
name: yup
.string()
.required('Please, provide your name!'),
password: yup
.string()
.min(4)
.max(10, 'Password should not excced 10 chars.')
.required(),
})}
>
{({ values, handleChange, errors, setFieldTouched, touched, isValid, handleSubmit }) => (
<ScrollView style={styles.scrollb}>
<View style={styles.container}>
<Text style={styles.title}>LOGIN PAGE</Text>
<Text style={styles.subtitle}>Welcome Back.</Text>
</View>
<View style={styles.container2}>
<TextInput
style={styles.tinput}
placeholder="Username"
value={values.name}
onChangeText={handleChange('name')}
onBlur={() => setFieldTouched('name')}
/>
{touched.name && errors.name &&
<Text style={{ fontSize: 12, color: '#FF0D10' }}>{errors.name}</Text>
}
</View>
<View style={styles.container2}>
<TextInput
style={styles.tinput}
placeholder="Password"
value={values.password}
onChangeText={handleChange('password')}
placeholder="Password"
onBlur={() => setFieldTouched('password')}
secureTextEntry={true}
/>
{touched.password && errors.password &&
<Text style={{ fontSize: 12, color: '#FF0D10' }}>{errors.password}</Text>
}
</View>
<View style={styles.container3}>
<TouchableHighlight
style={{
borderRadius: 10,
}}>
<Button
title="Login"
borderRadius={25}
containerViewStyle={{ borderRadius: 25 }}
buttonStyle={{ width: 145, height: 45, borderRadius: 25 }}
accessibilityLabel="Learn more about this button"
onPress={() => handleLogin(values.name)}
disabled={!isValid}
/>
</TouchableHighlight>
</View>
</ScrollView>
)}
</Formik>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
backgroundColor: "#61dafb",
},
container2: {
flex: 1,
paddingTop: 14,
paddingHorizontal: 24,
backgroundColor: "#61dafb",
},
container3: {
flex: 1,
paddingTop: 284,
paddingHorizontal: 34,
backgroundColor: "#61dafb",
borderRadius: 40,
},
title: {
marginTop: 16,
borderRadius: 6,
backgroundColor: "#61dafb",
color: "white",
textAlign: "center",
fontSize: 50,
fontWeight: "bold",
},
subtitle: {
borderRadius: 6,
paddingLeft: 33,
backgroundColor: "#61dafb",
color: "white",
textAlign: "left",
fontSize: 30,
fontWeight: '400',
},
tinput: {
height: 50,
textAlign: "center",
paddingVertical: 8,
backgroundColor: "white",
borderRadius: 27,
},
scrollb: {
backgroundColor: "#61dafb",
},
});
export default Login;
This is my Home screen file. Where I want to retrieve that username from Login Page via async storage.
import React, { Component, useEffect, useState } from 'react';
import { View, Text, ScrollView, TouchableHighlight, Image, StyleSheet } from 'react-native';
import { getData } from '../utils/storage';
const Home = (props) => {
const [username, setUsername] = useState('');
useEffect(() => {
getData('username')
console.log('useEffect',getData('username'))
}, [])
const CategoriesAr = [
{
name: "Business",
path: "Business",
imgURL: "https://img.icons8.com/clouds/100/000000/analytics.png",
},
{
name: "Technology",
path: "Technology",
imgURL: "https://img.icons8.com/clouds/100/000000/transaction-list.png",
},
{
name: "Science",
path: "Science",
imgURL: "https://img.icons8.com/clouds/100/000000/innovation.png",
},
{
name: "Health",
path: "Health",
imgURL: "https://img.icons8.com/clouds/100/000000/client-company.png",
}
]
const GridItem = (gridProps) => {
const { data } = gridProps;
return (
<>
<TouchableHighlight onPress={() => props.navigation.navigate(data.path)}>
<View style={styles.card}>
<View style={styles.header}>
<Text style={{ fontWeight: "bold", fontSize: 18 }}>{data.name}</Text>
</View>
<View style={styles.imgbody}>
<Image
style={styles.tinyLogo}
source={{
uri: data.imgURL,
}}
/>
</View>
</View>
</TouchableHighlight>
</>
)
}
return (
<ScrollView style={styles.sclb}>
<Text style={styles.title}>Hi {username}</Text>
<View style={styles.containerX}>
{CategoriesAr.map((item) => <GridItem data={item} />)}
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
title: {
marginTop: 16,
borderRadius: 6,
backgroundColor: "#61dafb",
color: "white",
textAlign: "center",
fontSize: 50,
fontWeight: "bold",
},
containerX: {
flex: 1,
flexWrap: "wrap",
marginTop: 8,
maxHeight: 400,
backgroundColor: "#61dafb",
},
card: {
height: 150,
width: 150,
backgroundColor: "white",
alignItems: "center",
borderRadius: 15,
elevation: 10,
padding: 10,
margin: 22,
},
imgbody: {
paddingTop: 20,
},
tinyLogo: {
height: 90,
width: 90,
},
header: {
flexDirection: "row",
},
sclb: {
backgroundColor: "#61dafb",
}
});
export default Home;
You need to put await before getData like this.
useEffect(() => {
(async()=>{
await getData('username')
console.log('useEffect',await getData('username'))
})();
}, [])
useEffect(() => {
CallMethod()
}, [])
const CallMethod = async() =>{
await getData('username')
}
I am trying to use the Flatlist component to show some registers and select some multiple registers.
<FlatList
horizontal
bounces={false}
key={ingredientList.id}
data={ingredientList}
renderItem={({ item }) => (
<Card key={item.id} onPress={selectedIngredient(item)}>
<Text key={item.title} style={styles.titleText}>{item.name}</Text>
<ImageBackground key={item.illustration} source={item.illustration} style={styles.cardImage}></ImageBackground>
</Card>
)
}
keyExtractor={(item) => item.index}
/>
function selectedIngredient(item) {
console.log('selecionado: ' + item.name)
}
How can I do to get only the details about the Card I selected?
this is what the "ingredientList" return:
Array [
Object {
"id": 8,
"name": "leite condensado",
},
Object {
"id": 9,
"name": "creme de leite",
},
You can use TouchableOpacity for the click event.
Snapshot:
Here is the working example of how you can implement it:
import React, { useState } from 'react';
import {
Text,
View,
StyleSheet,
FlatList,
TouchableOpacity,
} from 'react-native';
import Constants from 'expo-constants';
// You can import from local files
// or any pure javascript modules available in npm
const ingredientList = [
{
id: 1,
name: 'item1',
},
{
id: 2,
name: 'item 2',
},
{
id: 3,
name: 'item 3',
},
{
id: 8,
name: 'item 4',
},
{
id: 4,
name: 'item 5',
},
{
id: 5,
name: 'item 6',
},
];
export default function App() {
const [selectedItem, setSelectedItem] = useState(null);
const selectedIngredient = (item) => {
console.log('selecionado: ' + item.name);
setSelectedItem(item);
};
return (
<View style={styles.container}>
<FlatList
style={styles.flatlist}
horizontal
bounces={false}
key={ingredientList.id}
data={ingredientList}
renderItem={({ item }) => (
<TouchableOpacity
style={styles.flatListItem}
key={item.id}
onPress={() => selectedIngredient(item)}>
<Text>{item.name}</Text>
</TouchableOpacity>
)}
keyExtractor={(item) => item.index}
/>
{selectedItem ? (
<View style={styles.selectedTextView}>
<Text style={styles.selectedText}>{`${selectedItem.name} selected`}</Text>
</View>
) : (
<View style={styles.selectedTextView}>
<Text style={styles.selectedText}>{`Nothing selected`}</Text>
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
flatListItem: {
width: 100,
height: 100,
backgroundColor: 'white',
margin: 5,
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
selectedTextView: {
flex: 1,
backgroundColor: 'white',
margin: 5,
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
fontSize: 20
},
selectedText: {
fontSize: 30
},
});
Working Demo: Expo Snack
Try this const selectedIngredient = (item) => { console.log(item); }
and
<Card key={item.id} onPress={() => selectedIngredient(item)}>
I'm not getting how to get the current item object of a flat list
I used react-native-swipeout and react-native-swipe-list-view and in both examples I stuck.
And on google I found very big answers. Which are not pointing only the particular issue which confused me a lot.
the below is the deleted function when I used react-native-swipeout plugin
const swipeSettings = {
left: [
{
text: 'Delete',
onPress: () => {
console.log('-----delete-----');
},
type: 'delete',
},
}
All I need is to get the current item object data like below inside onpress() when i tapped the delete button .
{
id: 1,
prodName : "abcdefg",
}
That's all, I came from native script background and in that framework I never faced such issue. Because the documentation was crystal clear. But here In react native everything seems to be complicated for me.
Kindly any one help me.
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={({item, index}) => (
<Swipeout {...swipeSettings}>
<View style={styles.listView}>
<Text style={styles.listViewText}>{item.prodName}</Text>
</View>
</Swipeout>
)}
/>
entire page
import React, {useState} from 'react';
import {View} from 'react-native-animatable';
import {
TextInput,
TouchableOpacity,
FlatList,
} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/FontAwesome';
import {StyleSheet, Pressable, Text, Button} from 'react-native';
import * as Animatable from 'react-native-animatable';
import Swipeout from 'react-native-swipeout';
import ButtonPressable from '../../components/ButtonPressable';
var sqlite_wrapper = require('./sqliteWrapper');
const DATA = [
{
prodName: 'Added data will look like this',
},
];
const swipeSettings = {
style: {
marginBottom: 10,
},
autoClose: false,
backgroundColor: 'transparent',
close: false,
disabled: false,
onClose: (sectionID, rowId, direction) => {
console.log('---onclose--');
},
onOpen: (sectionID, rowId, direction) => {
console.log('---onopen--');
},
right: [
{
backgroundColor: 'dodgerblue',
color: 'white',
text: 'Edit',
onPress: () => {
console.log('-----edit-----');
},
},
],
left: [
{
backgroundColor: 'red',
color: 'white',
text: 'Delete',
onPress: () => {
console.log('-----delete-----');
sqlite_wrapper.deleteById
},
type: 'delete',
// component : (<ButtonPressable text="delete" />)
},
],
// buttonWidth: 100,
};
const AddProductList = ({route, navigation}) => {
const {navData} = route.params;
const [prodName, setProdName] = useState('');
var [data, setData] = useState(DATA);
return (
<View style={styles.container}>
<Animatable.View
animation="bounceIn"
duration={1000}
style={styles.inputFieldView}>
<TextInput
style={styles.textInput}
onChangeText={(value) => setProdName(value)}
placeholder="Add the Product"
defaultValue={prodName}
/>
<TouchableOpacity
style={styles.addView}
onPress={() => {
sqlite_wrapper
.insert({prodName: prodName}, sqlite_wrapper.collection_product)
.then((result) => {
console.log('---result---');
console.log(result);
if (result.rowsAffected) {
fetchAllData();
}
});
function fetchAllData() {
sqlite_wrapper
.readAll(sqlite_wrapper.collection_product)
.then((resultData) => {
console.log('---resultData---');
console.log(resultData);
setData(resultData);
setProdName('');
});
}
// without sql this is how to update the state having a array
// const updatedArray = [...data];
// updatedArray.push({prodName: prodName});
// setData(updatedArray);
// setProdName('');
}}>
<Icon name="plus" size={16} style={styles.add} color="white" />
</TouchableOpacity>
</Animatable.View>
<Animatable.View
animation="bounceInLeft"
duration={1500}
style={{flex: 1}}>
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={({item, index}) => (
<Swipeout {...swipeSettings}>
<View style={styles.listView}>
<Text style={styles.listViewText}>{item.prodName}</Text>
</View>
</Swipeout>
)}
/>
</Animatable.View>
</View>
);
};
var styles = StyleSheet.create({
container: {
flex: 1,
},
inputFieldView: {
flexDirection: 'row',
alignItems: 'center',
alignSelf: 'stretch',
margin: 10,
},
textInput: {
flex: 1,
backgroundColor: '#b2ebf2',
borderTopLeftRadius: 7,
borderBottomLeftRadius: 7,
fontSize: 16,
},
addView: {
backgroundColor: '#0f4c75',
alignSelf: 'stretch',
alignItems: 'center',
justifyContent: 'center',
borderTopEndRadius: 7,
borderBottomEndRadius: 7,
padding: 9,
},
add: {
padding: 7,
},
listView: {
padding: 20,
backgroundColor: 'green',
margin: 0,
borderRadius: 0,
},
listViewText: {
color: 'white',
},
});
export default AddProductList;
So if I get you right you have one generic swipe setting that you want to adjust to each element in the list.
Try changing the renderItem of the Flatlist like this and let me know how it worked for you:
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={({ item, index }) => {
let right = [...swipeSettings.right]; <---- ADDED
let left = [...swipeSettings.left]; <---- ADDED
right[0].onPress = () => console.log('edit', item.prodName); <---- ADDED
left[0].onPress = () => console.log('delete', item.prodName); <---- ADDED
<Swipeout {...swipeSettings} {...{ right, left}} > <---- CHANGED
<View style={styles.listView}>
<Text style={styles.listViewText}>{item.prodName}</Text>
</View>
</Swipeout>
}}
/>
So what I have done here is sending the generic swipe settings to each instance of Swipeout but changed their "Left" and "Right" in order to overwrite their "onPress" function and adjust it to the rendered item.
I know it is hard to understand it like this and it's probably not the best explanation but I hope it will help you somehow.
EDIT
import React, { useState } from 'react';
import { View } from 'react-native-animatable';
import {
TextInput,
TouchableOpacity,
FlatList,
} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/FontAwesome';
import { StyleSheet, Pressable, Text, Button } from 'react-native';
import * as Animatable from 'react-native-animatable';
import Swipeout from 'react-native-swipeout';
import ButtonPressable from '../../components/ButtonPressable';
var sqlite_wrapper = require('./sqliteWrapper');
const DATA = [
{
prodName: 'Added data will look like this',
},
];
const AddProductList = ({ route, navigation }) => {
const { navData } = route.params;
const [prodName, setProdName] = useState('');
var [data, setData] = useState(DATA);
const renderItem = ({ item, index }) => {
const swipeSettings = {
style: {
marginBottom: 10,
},
autoClose: false,
backgroundColor: 'transparent',
close: false,
disabled: false,
onClose: (sectionID, rowId, direction) => {
console.log('---onclose--');
},
onOpen: (sectionID, rowId, direction) => {
console.log('---onopen--');
},
right: [
{
backgroundColor: 'dodgerblue',
color: 'white',
text: 'Edit',
onPress: () => console.log('-----edit-----', item.prodName)
},
],
left: [
{
backgroundColor: 'red',
color: 'white',
text: 'Delete',
onPress: () => {
console.log('-----delete-----', item.prodName);
sqlite_wrapper.deleteById
},
type: 'delete',
// component : (<ButtonPressable text="delete" />)
},
],
// buttonWidth: 100,
};
return (
<Swipeout {...swipeSettings}>
<View style={styles.listView}>
<Text style={styles.listViewText}>{item.prodName}</Text>
</View>
</Swipeout>
)
}
return (
<View style={styles.container}>
<Animatable.View
animation="bounceIn"
duration={1000}
style={styles.inputFieldView}>
<TextInput
style={styles.textInput}
onChangeText={(value) => setProdName(value)}
placeholder="Add the Product"
defaultValue={prodName}
/>
<TouchableOpacity
style={styles.addView}
onPress={() => {
sqlite_wrapper
.insert({ prodName: prodName }, sqlite_wrapper.collection_product)
.then((result) => {
console.log('---result---');
console.log(result);
if (result.rowsAffected) {
fetchAllData();
}
});
function fetchAllData() {
sqlite_wrapper
.readAll(sqlite_wrapper.collection_product)
.then((resultData) => {
console.log('---resultData---');
console.log(resultData);
setData(resultData);
setProdName('');
});
}
// without sql this is how to update the state having a array
// const updatedArray = [...data];
// updatedArray.push({prodName: prodName});
// setData(updatedArray);
// setProdName('');
}}>
<Icon name="plus" size={16} style={styles.add} color="white" />
</TouchableOpacity>
</Animatable.View>
<Animatable.View
animation="bounceInLeft"
duration={1500}
style={{ flex: 1 }}>
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={renderItem}
/>
</Animatable.View>
</View>
);
};
var styles = StyleSheet.create({
container: {
flex: 1,
},
inputFieldView: {
flexDirection: 'row',
alignItems: 'center',
alignSelf: 'stretch',
margin: 10,
},
textInput: {
flex: 1,
backgroundColor: '#b2ebf2',
borderTopLeftRadius: 7,
borderBottomLeftRadius: 7,
fontSize: 16,
},
addView: {
backgroundColor: '#0f4c75',
alignSelf: 'stretch',
alignItems: 'center',
justifyContent: 'center',
borderTopEndRadius: 7,
borderBottomEndRadius: 7,
padding: 9,
},
add: {
padding: 7,
},
listView: {
padding: 20,
backgroundColor: 'green',
margin: 0,
borderRadius: 0,
},
listViewText: {
color: 'white',
},
});
export default AddProductList;
I am using the tab navigator in stack navigator ..when in tab navigator i move to next tab there a little bit pause then move to next tab...the code of index file is
import React, { Component } from 'react';
import { AppRegistry,Alert,ScrollView, Image, Dimensions,
Text,View,TouchableOpacity,StyleSheet} from 'react-native'
import Login from './login'
import SignUp from './signup'
import forget from './forget'
import Tabo from './DefaultTabBar'
import { StackNavigator,TabNavigator } from 'react-navigation';
import HomeButton from './HomeButton'
import ProfileScreen from './ProfileScreen'
import Granjur from './granjur'
const background=require("./flag/1.jpg");
export default class TabViewExample extends Component {
render(){
const { navigation } = this.props;
return(
<App navigation={ navigation }/>
);
}
}
const MyApp = TabNavigator({
Home: {
screen: HomeButton,
},
Notifications: {
screen: ProfileScreen,
},
},
{
swipeEnabled:false,
initialRouteName: 'Home',
tabBarOptions: {
activeTintColor: '#e91e63',
},
});
const Simple = StackNavigator({
Login: {
screen: Login,
},
signup: {
screen: SignUp,
},
forget:{
screen:forget
},
dashbord:{
screen:Granjur
}
});
AppRegistry.registerComponent('TabNavigator', () => Simple);
i also use scrollable tabView in that tab view also that problem occur..In second tab i have a swipable list view may be due to this error come how i resolv this the code for profile screen is that
import React, {
Component,
} from 'react';
import {
AppRegistry,
ListView,
StyleSheet,
Text,
TouchableOpacity,
TouchableHighlight,
View,
Alert,
Dimensions
} from 'react-native';
import { SwipeListView, SwipeRow } from 'react-native-swipe-list-view';
var alertMessage="You want to Delete it";
var alertMessage1='why press it'
var v1=1.0;
const wid=Dimensions.get('window').width;
export default class App extends Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
basic: true,
listViewData: Array(5).fill('').map((_,i)=>`item #${i}`)
};
}
deleteRow(secId, rowId, rowMap) {
rowMap[`${secId}${rowId}`].closeRow();
const newData = [...this.state.listViewData];
newData.splice(rowId, 1);
this.setState({listViewData: newData});
}
// undoRow(rowId) {
// const newData = [...this.state.listViewData];
// this.setState({listViewData: newData});
// this.setState({listViewData: newData});
// }
render() {
return (
<SwipeListView
dataSource={this.ds.cloneWithRows(this.state.listViewData)}
renderRow={ data => (
<TouchableHighlight
onPress={ _ => Alert.alert(
'Alert Title',
alertMessage1,
) }
style={styles.rowFront}
underlayColor={'#AAA'}
>
<Text>I am {data} in a SwipeListView</Text>
</TouchableHighlight>
)}
renderHiddenRow={ (data, secId, rowId, rowMap) => (
<View style={styles.rowBack}>
<TouchableOpacity style={{backgroundColor:'#2c3e50',alignItems: 'center',bottom: 0,justifyContent: 'center',position: 'absolute',top: 0,width: 75}}
onPress={ _ => rowMap[ `${secId}${rowId}` ].closeRow() } >
<Text style={styles.backTextWhite}>Undo</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.backRightBtn, styles.backRightBtnRight]}
onPress={ _ => Alert.alert(
'Are You Sure',alertMessage,
[{text: 'OK', onPress: () =>this.deleteRow(secId, rowId, rowMap)},
{text: 'Cancel',}]
) }>
<Text style=
{styles.backTextWhite}>Delete</Text>
</TouchableOpacity>
</View>
)}
leftOpenValue={wid}
rightOpenValue={-wid}
disableLeftSwipe={true}
/>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1
},
standalone: {
marginTop: 30,
marginBottom: 30,
},
standaloneRowFront: {
alignItems: 'center',
backgroundColor: '#CCC',
justifyContent: 'center',
height: 50,
},
standaloneRowBack: {
alignItems: 'center',
backgroundColor: '#8BC645',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
padding: 15
},
backTextWhite: {
color: '#FFF'
},
rowFront: {
alignItems: 'center',
backgroundColor: '#CCC',
borderBottomColor: 'black',
borderBottomWidth: 1,
justifyContent: 'center',
height: 50,
},
rowBack: {
alignItems: 'center',
backgroundColor: '#DDD',
flex: 1,
flexDirection: 'row',
//justifyContent: 'space-between',
paddingLeft: 15,
},
backRightBtn: {
alignItems: 'center',
bottom: 0,
justifyContent: 'center',
position: 'absolute',
top: 0,
width: 75
},
backRightBtnLeft: {
backgroundColor: 'blue',
//right: 75
},
backRightBtnRight: {
backgroundColor: '#2c3e50',
right: 0
},
controls: {
alignItems: 'center',
marginBottom: 30
},
switchContainer: {
flexDirection: 'row',
justifyContent: 'center',
marginBottom: 5
},
switch: {
alignItems: 'center',
borderWidth: 1,
borderColor: 'black',
paddingVertical: 10,
width: 100,
}
});
App.navigationOptions = {
title: 'Signup Screen',
headerVisible:false
};
AppRegistry.registerComponent('TabNavigator', () => App);
How i remove this pause plz tell me early as soon as possible..Thanks