Scrolling in FlatList Element React Native - react-native

I am making a todo app, to render the list of todo items i am using flatlist but in flatlist i am not able to scroll through the list is there any way to sroll throught the list
my code
`
<FlatList
data={toDos}
refreshing={isRefreshing}
onRefresh={() => {
loadToDoList();
setIsRefreshing(true);
}}
renderItem={renderToDoItem}
keyExtractor={(item) => item.id}
/>
`
i tried using scroll view but i dont know how to use it can you please help me fix this problem

code
let showToDoList = () => {
return (
<FlatList
data={toDos}
refreshing={isRefreshing}
onRefresh={() => {
loadToDoList();
setIsRefreshing(true);
}}
renderItem={renderToDoItem}
keyExtractor={(item) => item.id}/>
);
};
todo item
let renderToDoItem = ({ item }) => {
return (
<View style={[MyStyles.ToDoItem]}>
<View style={AppStyles.fillSpace}>
<BouncyCheckbox
isChecked={item.completed}
size={25}
fillColor="#0A7AFF"
unfillColor="#fff"
text={item.text}
iconStyle={{ marginLeft: 5 }}
onPress={(isChecked) => {
checkToDoItem(item, isChecked);
}}
/>
</View>
<CustomTextButton
text={<AntDesign name="delete" size={25} color="red" />}
onPress={() => deleteToDo(item.id)}
style={MyStyles.ToDoDelete}
/>
</View>
);
};
styles
import { StyleSheet } from "react-native";
export default StyleSheet.create({
ToDoItem: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
marginTop: 3,
marginBottom: 3,
marginLeft: 7,
marginRight: 7,
backgroundColor: "white",
borderRadius: 3,
borderColor: "#D9D9D9",
},
CustomButtonAddToDo: {
flexDirection: "column",
width: 100,
textAlign: "center",
backgroundColor: "#ff7676",
borderRadius: 5,
marginRight: 5,
marginLeft: 5,
},
Center: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: "center",
alignItems: "center",
},
CustomTextButton: {
fontSize: 20,
color: "#87F1FF",
marginRight: 5,
},
FloatingContainer: {
width: 77,
height: 77,
backgroundColor: "#46A16E",
borderRadius: 100,
display: "flex",
bottom: 0,
right: 0,
position: "absolute",
marginRight: 15,
},
Floating: {},
blackText: {
color: "#000",
},
whiteText: {
color: "#fff",
},
header: {
fontSize: 30,
marginLeft: 10,
marginTop: 20,
},
MainBG: {
backgroundColor: "#798478",
},
TopBar: {
flexDirection: "row",
flexWrap: "wrap",
},
TopBarText: {
marginTop: 20,
marginLeft: 10,
fontSize: 20,
marginBottom: 20,
fontWeight: "bold",
},
TopBarTextMenu: {
marginTop: 20,
marginLeft: 10,
marginBottom: 20,
fontSize: 20,
},
TopBarMenu: {
marginTop: 20,
marginLeft: 10,
marginBottom: 20,
fontSize: 20,
},
addToDoText: {
fontSize: 30,
},
menuicon: {
width: 35,
height: 5,
backgroundColor: 'black',
margin: 50,
},
lightText: {
color: "#fff"
},
lightTextInput: {
color: "#fff"
},
darkText: {
color: "#000"
},
darkTextInput: {
color: "#000"
},
bold: {
fontSize: 15,
fontWeight: "bold"
},
smallText: {
color: "5a5a59",
fontSize: 15,
fontWeight: "300",
},
});
styles2
import { StyleSheet } from "react-native";
export default StyleSheet.create({
imageContainer: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
},
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "white",
padding: 16,
},
rowContainer: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
marginVertical: 8,
},
topMargin: {
marginTop: 16,
},
bottomMargin: {
marginBottom: 16,
},
rightMargin: {
marginRight: 16,
},
leftMargin: {
marginLeft: 16,
},
lightText: {
color: "white",
},
darkText: {
color: "black",
},
errorText: {
color: "#FF0000",
},
header: {
fontSize: 20,
},
textInput: {
alignSelf: "stretch",
padding: 8,
},
lightTextInput: {
borderBottomColor: "white",
},
InlineTextButton: {
fontSize: 20,
color: "#87F1FF",
},
pressedInlineTextButton: {
fontSize: 19,
color: "#87F1FF",
opacity: 0.4,
},
imageContainer: {
flex: 1,
backgroundColor: '#fafafa',
alignItems: 'center',
justifyContent: 'center'
},
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
padding: 16
},
noPadding: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: "red"
},
rowContainer: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
alignSelf: "stretch",
marginVertical: 4,
},
fillSpace: {
flex: 1
},
rightAligned: {
justifyContent: "flex-end"
},
leftAligned: {
justifyContent: "flex-start"
},
topMargin: {
marginTop: 16
},
bottomMargin: {
marginBottom: 16
},
rightMargin: {
marginRight: 16
},
leftMargin: {
marginLeft: 16
},
backgroundCover: {
alignSelf: 'stretch',
alignItems: 'center',
justifyContent: 'center',
marginLeft: 10,
marginRight: 10,
},
lightText: {
color: "#fff"
},
errorText: {
color: "#ff0000"
},
header: {
fontSize: 20,
alignSelf: "center"
},
textInput: {
alignSelf: 'stretch',
padding: 8,
borderBottomWidth: 2,
marginVertical: 8
},
lightTextInput: {
borderBottomColor: "#ffffff"
},
darkTextInput: {
borderBottomColor: "#000000"
},
InlineTextButton: {
fontSize: 15,
fontWeight: "bold",
color: "#87F1FF",
},
pressedInlineTextButton: {
fontSize: 19,
color: "#87F1FF",
opacity: 0.4,
},
});

Related

how to use TapGestureHandler on Class Components

I'm trying to add a tap gesture to the render card of react-native-deck-swiper using the TapGestureHanlder from react-native-reanimated.
Currently, it works when tapping the red zone outside the swiper, but I want to tap the picture and get the x position where I tapped.
This is the code of the red zone, there I'm calling a class component in which I'm using the deck-swiper with some extra functions.
const onSingleTapEvent = (event) => {
if (event.nativeEvent.state === State.ACTIVE) {
alert('Hey single tap!');
}
};
return (
<GestureHandlerRootView style={{ zIndex: 10 }}>
<TapGestureHandler onHandlerStateChange={onSingleTapEvent}>
<AnimatedView style={styles.container}>
<ImageSwiperDeck
index={index}
listOfAssetsWithinTheAlbum={listOfAssetsWithinTheAlbum}
moveImageToTrashBin={moveImageToTrashBin}
keepImageInAlbum={keepImageInAlbum}
/>
</AnimatedView>
</TapGestureHandler>
</GestureHandlerRootView>
);
};
const styles = StyleSheet.create({
container: {
height: 560,
width: 500,
zIndex: 10,
backgroundColor: 'red',
},
});
export default ImageSwiper;
This is the deck-swiper code which works fine.
return (
<Swiper
ref={(swiper) => {
this.swiper = swiper;
}}
cards={this.props.listOfAssetsWithinTheAlbum}
cardIndex={this.props.index}
renderCard={this.Card}
backgroundColor={'transparent'}
onSwipedLeft={this.deleteImage}
onSwipedRight={this.keepImage}
cardVerticalMargin={10}
stackSize={5}
stackScale={20}
stackSeparation={5}
animateOverlayLabelsOpacity
animateCardOpacity
disableTopSwipe
disableBottomSwipe
overlayLabels={{
left: {
title: 'DELETE',
style: {
label: {
backgroundColor: colors.red,
borderColor: colors.red,
color: colors.white,
borderWidth: 1,
fontSize: 24,
},
wrapper: {
flexDirection: 'column',
alignItems: 'flex-end',
justifyContent: 'flex-start',
marginTop: 20,
marginLeft: -20,
},
},
},
right: {
title: 'KEEP',
style: {
label: {
backgroundColor: colors.blue,
borderColor: colors.blue,
color: colors.white,
borderWidth: 1,
fontSize: 24,
},
wrapper: {
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'flex-start',
marginTop: 20,
marginLeft: 20,
},
},
},
}}
/>
);

react native why my absolute view is not showing all only the half?

why my purple absolute view is not showing all, only the half ?
look at the image
Code:
CardView:
const { width } = Dimensions.get('window');
const MAX_NAME_WIDTH = width / 2 - 48;
const CARD_WIDTH = width * 0.45;
const UserCardAdvanced = ({ user_id, username, profile_image, followingShops, is_verification, isD, stars, onPress, onPressReviews, onPressFollow }: IUserCardAdvanced) => {
return (
<Pressable onPress={onPress} style={s.card}>
{ isD &&
<PurpleNotice />
}
<Image source={{uri: profile_image}} resizeMode='contain' style={s.profile_image} />
<View style={s.starContainer}>
<Stars
star_filled={stars?.fill}
disabled
is_all
size={15}
onPressAll={onPressReviews}
/>
<Text style={s.reviewTotal}>{stars?.total_reviews}</Text>
</View>
<View style={s.nameContainer}>
<NameWithVerification
name={username}
is_verification={is_verification}
nameStyle={s.nameStyle}
/>
</View>
<FollowBtn
onPress={onPressFollow}
is_followed={false}
size={24}
/>
</Pressable>
)
}
const s = StyleSheet.create({
card: {
padding: 12,
backgroundColor: '#fff',
borderRadius: 8,
elevation: 3,
margin: 6,
justifyContent: 'center',
alignItems: 'center',
marginBottom: 20,
zIndex: 99921,
width: CARD_WIDTH
},
starContainer: {
flexDirection: 'row',
alignItems: 'center',
marginTop: 8
},
reviewTotal: {
fontFamily: globalStyles.font_regular,
color: '#333',
marginLeft: 4
},
nameContainer: {
marginVertical: 8
},
nameStyle: {
color: '#333',
fontSize: 13,
maxWidth: MAX_NAME_WIDTH
},
profile_image: {
height: 84,
width: 84,
borderRadius: 50,
},
username: {
fontFamily: globalStyles.font_regular,
color: '#555',
marginTop: 12,
textAlign: 'center'
}
})
Purple Notice
const PurpleNotice = (isD: isD) => {
return (
<View style={s.view}>
<Text style={s.text}>TESTTESTETS</Text>
</View>
)
}
const s = StyleSheet.create({
view: {
padding: 2,
paddingHorizontal: 10,
backgroundColor: globalStyles.globalColor,
borderRadius: 6,
position: 'absolute',
top: -10,
left: 0,
zIndex: 99999
},
text: {
fontFamily: globalStyles.font_light,
color: '#fff',
fontSize: 11,
textTransform: 'uppercase',
textShadowColor: '#fff',
textShadowOffset: {
height: 2,
width: 2
}
}
});
I dont know what I am doing wrong i am very thankful for your help!!
.........................................
.........................................
.........................................
.........................................
.........................................
You can add zIndex={1} to that purple view.
use right:0 in style
const s = StyleSheet.create({
view: {
padding: 2,
paddingHorizontal: 10,
backgroundColor: globalStyles.globalColor,
borderRadius: 6,
position: 'absolute',
top: -10,
left: 0,
right:0, //use this also
zIndex: 99999
},
text: {
fontFamily: globalStyles.font_light,
color: '#fff',
fontSize: 11,
textTransform: 'uppercase',
textShadowColor: '#fff',
textShadowOffset: {
height: 2,
width: 2
}
}
});

Text lowered and cutoff in android but not ios - react native

The text should look like this
IOS
But on Android it looks like this:
Android
The code for the styling of the text and container is:
text: {
fontFamily: 'Roboto',
fontSize: 40,
width: 250,
height: 40,
textAlignVertical: 'center',
textAlign: 'center',
},
container: {
backgroundColor: '#DDDDDD',
width: 250,
height: 55,
margin: 12.5,
borderRadius: 10,
justifyContent: 'center'
}
and the components:
<TouchableOpacity
style={styles.container}
onPress={_ => this.navigation.push('Join')} >
<Text style={styles.text}>Join</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.container}
onPress={_ => this.navigation.push('Create')} >
<Text style={styles.text}>Create</Text>
</TouchableOpacity>
Replace your styles with this :
text: {
fontFamily: 'Roboto',
fontSize: 40,
textAlignVertical: 'center',
textAlign: 'center',
},
container: {
backgroundColor: '#DDDDDD',
margin: 12.5,
borderRadius: 10,
justifyContent: 'center',
alignSelf: 'center',
width: 250,
},
Change your styles to below -
text: {
fontFamily: 'Roboto',
fontSize: 40,
textAlignVertical: 'center',
textAlign: 'center',
},
container: {
backgroundColor: '#DDDDDD',
width: 250,
minHeight: 55,
margin: 12.5,
borderRadius: 10,
justifyContent: 'center'
alignItems: 'center',
alignSelf: 'center',
}

Prevent TextInput box from starting small

I didn't have this problem before, but for some reason right now, my text input box is starting with 0 and it won't start with the place holder I had set. When I delete the 0 when I start entering, it goes away and sort of expands, with the place holder seen. Does anyone have any advice on how I can make it start with a full-text input banner and without the 0?
Here are pictures of what is happening:
Starting
After clicking into text input
Here's my code:
return (
<View style={styles.container}>
<TextInput
style={styles.input}
placeholderTextColor="#aaaaaa"
secureTextEntry
placeholder='Blood Pressure'
underlineColorAndroid="transparent"
autoCapitalize="none"
multiline
onChangeText={(bp) => this.setState({ bp })}
value={`${this.state.bp}`}
/>
<View style={styles.modalContainer}>
<View style={styles.innerContainer}>
<TouchableOpacity onPress=
{
this.updateInfo,
this.onFooterLinkPress
}
>
<Text style={styles.buttonTitle}>Submit Data</Text>
</TouchableOpacity>
</View>
);
Styles:
import { StyleSheet } from 'react-native';
export default StyleSheet.create({
container: {
flex: 5,
alignItems: 'center'
},
title: {
},
logo: {
flex: 1,
height: 120,
width: 90,
alignSelf: "center",
margin: 30
},
input: {
height: 48,
borderRadius: 5,
overflow: 'hidden',
backgroundColor: 'white',
marginTop: 10,
marginBottom: 10,
marginLeft: 30,
marginRight: 30,
paddingLeft: 16
},
button: {
backgroundColor: '#788eec',
marginLeft: 30,
marginRight: 30,
marginTop: 20,
height: 48,
borderRadius: 5,
alignItems: "center",
justifyContent: 'center'
},
buttonTitle: {
color: 'white',
fontSize: 16,
fontWeight: "bold"
},
footerView: {
flex: 1,
alignItems: "center",
marginTop: 20
},
footerText: {
fontSize: 16,
color: '#2e2e2d'
},
footerLink: {
color: "#788eec",
fontWeight: "bold",
fontSize: 16
}
})

Issues with Flexbox in React Native not displaying the Full Text

I'm having some troubles displaying information which I believe they have to do with the Flexbox Properties, but no matter how I play around with the Styles I don't get to fit everything in some components.
First I have this Component which is a Simple Card Component where I pass my data from API:
<PartidoItem
localImage={logoLocal}
marcadorLocal={marcadorLocal}
time={date}
partidoId={partidoId}
estatus={estatus}
minute={elapsed}
estadio={estadio}
marcadorVisita={marcadorVisita}
visitImage={logoVisita}
onSelect={estatus !== 'NS' && estatus !== 'TBD' ? () => {
selectPartidoHandler(partidoId, tituloPartido)
}
: () => { }
}
/>
This comes from this Component:
import React from 'react';
import { View, Text, Image, StyleSheet, TouchableNativeFeedback, TouchableOpacity, Platform } from 'react-native';
import Card from '../UI/Card';
import Colors from '../../constants/Colors';
const PartidoItem = props => {
let TouchableCmp = TouchableOpacity;
if (Platform.OS === 'android' && Platform.Version >= 21) {
TouchableCmp = TouchableNativeFeedback;
}
return (
<Card style={styles.product}>
<View style={styles.touchable}>
<TouchableCmp onPress={props.onSelect} useForeground>
<View style={styles.container}>
<View style={styles.column}>
<View style={styles.imageContainer}>
<Image
resizeMode="cover"
style={styles.image}
source={{ uri: props.localImage }}
/>
</View>
</View>
<View style={styles.column}>
<Text style={styles.number}>{props.marcadorLocal}</Text>
</View>
{props.estatus === 'NS' || props.estatus === 'TBD'
? <View style={styles.column}>
<Text style={styles.date}>{props.time}</Text>
<Text style={styles.title}>{props.estadio}</Text>
</View>
: props.estatus === 'FT' ?
<View style={styles.column}>
<Text style={styles.title2}>Final</Text>
<Text style={styles.title}>{props.estadio}</Text>
</View>
:
<View style={styles.column}>
<Text style={styles.title}>Tiempo:</Text>
<Text style={styles.title}>{props.minute} '</Text>
</View>
}
<View style={styles.column}>
<Text style={styles.number}>{props.marcadorVisita}</Text>
</View>
<View style={styles.column}>
<View style={styles.imageContainer}>
<Image
resizeMode="cover"
style={styles.image}
source={{ uri: props.visitImage }}
/>
</View>
</View>
</View>
</TouchableCmp>
</View>
</Card>
);
};
const styles = StyleSheet.create({
product: {
height: 100,
margin: 20,
justifyContent: 'center',
alignItems: 'center',
},
touchable: {
borderRadius: 10,
},
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
column: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
width: '20%',
},
space_between_columns: {
width: 100
},
box: {
height: 50,
width: 50
},
imageContainer: {
width: '100%',
height: '70%',
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
overflow: 'hidden',
marginHorizontal: 10,
overflow: 'hidden',
},
image: {
width: '100%',
height: '100%',
flex: 1,
},
hora: {
fontSize: 14,
color: '#888',
fontWeight: 'bold',
textAlign: 'center',
},
number: {
fontSize: 50,
marginVertical: 4,
fontWeight: 'bold',
justifyContent: 'center',
color: Colors.secondary,
},
title: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
//flexWrap: 'wrap',
flex: 2,
flexGrow: 1,
},
title2: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
color: 'red',
},
date: {
fontSize: 14,
marginVertical: 4,
textAlign: 'center',
flex: 1,
flexGrow: 1,
marginHorizontal: 2,
},
});
export default PartidoItem;
Which Holds this Component as well:
import React from 'react';
import { View, StyleSheet } from 'react-native';
//Importacion de los colores
import Colors from "../../constants/Colors";
const Card = props => {
return (
<View style={{...styles.card, ...props.style}}>
{props.children}
</View>
);
};
const styles = StyleSheet.create({
card: {
shadowColor: 'black',
shadowOpacity: 0.26,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 8,
elevation: 5,
borderRadius: 10,
backgroundColor: Colors.background,
}
});
export default Card;
Now the problem is that when I see it in the Android Emulator and it has large Strings I see this:
As you can see the Component is the one in the Primary Box and the Property "Estadio" is too big that doesn't show completely
The same happens when I check this on my iOS device (through Expo):
Is there a way to get this info to fit into that space so it shows the Full Name?
Kind Regards
PD: After Change Advise on first Answer this is the result with the Logos not showing correctly:
Try this for your styles :
const styles = StyleSheet.create({
product: {
height: 120,
margin: 20,
justifyContent: 'center',
alignItems: 'center',
},
touchable: {
borderRadius: 10,
},
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
column: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
},
space_between_columns: {
width: 100
},
box: {
height: 50,
width: 50
},
imageContainer: {
width: 100,
height: 100,
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
overflow: 'hidden',
marginHorizontal: 10,
overflow: 'hidden',
},
image: {
width: '100%',
height: '100%',
flex: 1,
},
hora: {
fontSize: 14,
color: '#888',
fontWeight: 'bold',
textAlign: 'center',
},
number: {
fontSize: 50,
marginVertical: 4,
fontWeight: 'bold',
justifyContent: 'center',
color: Colors.secondary,
},
title: {
fontSize: 14,
margin: 5,
fontWeight: 'bold',
textAlign: 'center',
//flexWrap: 'wrap',
flex: 2,
flexGrow: 1,
},
title2: {
fontSize: 14,
marginVertical: 4,
fontWeight: 'bold',
textAlign: 'center',
color: 'red',
},
date: {
fontSize: 14,
marginVertical: 4,
textAlign: 'center',
flex: 1,
flexGrow: 1,
marginHorizontal: 2,
},
});