I'm new to react native and following the tutorial on youtube. When I'm developing the tutorial app there is a place to add flex-1 as a className. But after adding it nothing happened.
This is the tutorial:- https://youtu.be/AkEnidfZnCU
This is my code
import { useNavigation } from '#react-navigation/native';
import React, { useLayoutEffect } from 'react';
import { View, Text, Image, TextInput } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { UserIcon, ChevronDownIcon, MagnifyingGlassIcon, AdjustmentsHorizontalIcon } from "react-native-heroicons/outline";
const HomeScreen = () => {
const navigation = useNavigation();
useLayoutEffect(() => {
navigation.setOptions({
headerShown: false,
})
}, [])
return (
<SafeAreaView className="bg-white pt-5">
<Text className="text-red-500">
{/* Header */}
<View className="flex-row pb-3 items-center mx-4 space-x-2 px-4">
<Image
source={{
uri: 'https://links.papareact.com/wru',
}}
className="h-7 w-7 bg-gray-300 p-4 rounded-full"
/>
<View className="flex-1">
<Text className="font-bold text-gray-400 text-xs">Deliver Now!</Text>
<Text className="font-bold text-xl">Current Location
<ChevronDownIcon size={20} color="#00CCBB" />
</Text>
</View>
<UserIcon size={35} color="#00CCBB" />
</View>
{/* Search box */}
<View className="flex-row items-center space-x-2 pb-2 mx-4 px-4">
<View className="flex-row space-x-2 bg-gray-200 p-3">
<MagnifyingGlassIcon size={20} color="gray" />
<TextInput placeholder='Restaurant and cuisines' keyboardType='default' />
</View>
<AdjustmentsHorizontalIcon color="#00CCBB" />
</View>
</Text>
</SafeAreaView>
);
}
export default HomeScreen;
This is how it looks like
Please help me to solve this problem.
==> Try this may be it works. You have to add View with flex-1
return (
<SafeAreaView className="bg-white pt-5">
<View className="flex-1"> // here
<Text className="text-red-500">
{/* Header */}
<View className="flex-row pb-3 items-center mx-4 space-x-2 px-4">
<Image
source={{
uri: 'https://links.papareact.com/wru',
}}
className="h-7 w-7 bg-gray-300 p-4 rounded-full"
/>
<View className="flex-1">
<Text className="font-bold text-gray-400 text-xs">Deliver Now!</Text>
<Text className="font-bold text-xl">Current Location
<ChevronDownIcon size={20} color="#00CCBB" />
</Text>
</View>
<UserIcon size={35} color="#00CCBB" />
</View>
{/* Search box */}
<View className="flex-row items-center space-x-2 pb-2 mx-4 px-4">
<View className="flex-row space-x-2 bg-gray-200 p-3">
<MagnifyingGlassIcon size={20} color="gray" />
<TextInput placeholder='Restaurant and cuisines' keyboardType='default' />
</View>
<AdjustmentsHorizontalIcon color="#00CCBB" />
</View>
</Text>
</View>
</SafeAreaView>
);
Related
{/* Header */}
<View className="flex-row pb-3 items-center mx-4 space-x-2">
<Image
source={{
uri: "https://Links.papareact.com/wru",
}}
className='h-7 w-7 bg-gray-300 p-4 rounded-full'
/>
<View className="flex-1">
<Text className='font-bold text-gray-400 text-xs'>Deliver Now!</Text>
<Text className='font-bold text-xl'>Current Location
<ChevronDownIcon size={20} color="#00CCBB" />
</Text>
</View>
<UserIcon size={35} color="#00CCBB" />
</View>
{/* Search */}
<View className='flex-row items-center flex-1 space-x-2 pb-2 mx-4'>
<View className='flex-row space-x-2 flex-1 bg-gray-200 p-3'>
<MagnifyingGlassIcon color="#00CCBB" size={20} />
<TextInput placeholder="Reastaurants and Cuisines" keyboardType="default" />
</View>
<AdjustmentsVerticalIcon color="#00CCBB" />
</View>
</Text>
</SafeAreaView>
);
};
export default HomeScreen;
flex-1 class of tailwind doesn't work on this code.If anyone can fixit then, please let me know..
I have a view with 2 flatlist, one vertical is working perfectly while the horizontal one doesn't, I can see one card only and it won't move. I searched through the known issues and most of the times is a missing flex-1 but not here.
Any idea? Some Tailwind CSS in it, if it needs clarification please tell me. Thanks
const Home = () => {
const renderItem = useCallback(
({ item, onpress }) => <VideoListItem onpress={onpress} item={item} />,
[]
);
return (
<>
<SafeAreaView className="flex-1">
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "height" : undefined}
keyboardVerticalOffset={100}
>
<View
className="flex flex-row mx-6 my-2 px-3 py-3 justify-between items-center "
style={styles.searchContainer}
>
<Image
className="rounded-full"
style={{ width: scale(30), height: scale(30) }}
source={require("../assets/mlucas.jpg")}
/>
<Ionicons
name="search-outline"
size={scale(25)}
color="px-2 bg-black border"
/>
</View>
</KeyboardAvoidingView>
<Text className="text-xl px-6 my-3"> Dernières vidéos</Text>
<View style={{ flex: 1 }} className="px-6 mb-3">
{data && (
<>
<FlatList
horizontal={true}
data={data}
renderItem={renderItem}
keyExtractor={(item) => item.title}
/>
</>
)}
</View>
<Text className="text-xl px-6 my-3"> Toutes nos vidéos</Text>
<View style={{ flex: 1 }} className="px-6">
{data && (
<FlatList
showsVerticalScrollIndicator={false}
data={data}
renderItem={renderItem}
keyExtractor={(item) => item.title}
/>
)}
</View>
</SafeAreaView>
</>
and simplified VideoItems
const VideoListItem = ({ item, onpress }) => {
return (
<Pressable className=' bg-gray-200 border my-2 rounded-2xl' onPress={openVideoPage} style={styles.videoCard}>
<View >
<Image style={styles.thumbnail} className="rounded-t-2xl" source={{ uri: item.url_image || "" }} />
</View>
<View style={styles.titleRow}>
<View style={styles.midleContainer}>
<Text className='text-black'style={styles.title}>{item.title}</Text>
<Text style={styles.subtitle}>
{item.User?.name || "No name"}
</Text>
</View>
</View>
</Pressable>
)
}
import {Avatar, ListItem} from 'react-native-elements';
<View style={{flex: 3}}>
<ListItem
key="live-jobs"
title="Live Jobs"
textStyle={{color: 'orange'}}
leftIcon={
<Icon name="access-point" size={25} style={{color: '#4BC6FF'}} />
}
onPress={() =>
this.checkPermissions(LIVE_JOB_END_POINT, 'liveJobs')
}
/>
<Text>Hiiii</Text>
<ListItem
key="notifications"
title="Notifications"
leftIcon={
<Icon name="bell-ring" size={25} style={{color: '#4BC6FF'}} />
}
onPress={() => Actions.userManagement()}
/>
</View>
My React-native version is 0.64.2 ,React native elements version 3.4.2 Why does the content inside the ListItem Not display anything?
<ListItem key="live-jobs" bottomDivider>
<Avatar source={{uri: l.avatar_url}} />
<ListItem.Content>
<ListItem.Title>Live Jobs</ListItem.Title>
<ListItem.Subtitle>Subtitle</ListItem.Subtitle>
</ListItem.Content>
</ListItem>
As I wanted to create a footer, I followed the advices saying I had to put a scrollview within a view to make it right.
Well, that's almost perfect but could you help me with one detail ? in the red circle of the picture, we can see that my view is visible. I would like to make the top of it disappear. I tried marginTop: 0 and paddingTop: 0, but it didn't work.
Thanks for any help !
My code for this page :
import React, { Component } from "react";
import { Image, View, ScrollView, Text } from "react-native";
import Button from "react-native-flat-button";
import styles from "../../assets/Styles";
import Footer from "../../Components/Footer/Footer";
import { Header } from "react-native-elements";
import MenuButton from "../../Drawer/MenuButton";
export default class Welcome extends React.Component {
render() {
return (
<View style={styles.footer}>
<Header
rightComponent={<MenuButton navigation={this.props.navigation} />}
centerComponent={{ text: 'Bienvenue au Gavroche', style: {fontFamily: "Parisienne", fontSize: 24, color: '#fff' } }}
containerStyle={{
backgroundColor: "#013243",
justifyContent: "space-around"
}}
statusBarProps={{ barStyle: "light-content" }}
/>
<ScrollView style={styles.containerScroll}>
<View style={styles.container}>
<Image
style={styles.welcomeimg}
source={require("../../assets/Images/facade.png")}
/>
</View>
<View style={styles.buttonView}>
<Button
type="custom"
activeOpacity={0.5}
containerStyle={styles.buttonContainer}
contentStyle={styles.buttonWelcome}
onPress={() => this.props.navigation.navigate("Restaurant")}
>
Restaurant
</Button>
<Button
type="custom"
activeOpacity={0.5}
containerStyle={styles.buttonContainer}
contentStyle={styles.buttonWelcome}
onPress={() => this.props.navigation.navigate("Carte")}
>
Carte
</Button>
</View>
<View style={styles.buttonView}>
<Button
type="custom"
activeOpacity={0.5}
containerStyle={styles.buttonContainer}
contentStyle={styles.buttonWelcome}
onPress={() => this.props.navigation.navigate("Vins")}
>
Vins
</Button>
<Button
type="custom"
onPress={() => this.props.navigation.navigate("Actus")}
activeOpacity={0.5}
containerStyle={styles.buttonContainer}
contentStyle={styles.buttonWelcome}
>
Actus
</Button>
</View>
<View style={styles.buttonView}>
<Button
type="custom"
onPress={() => this.props.navigation.navigate("Reservation")}
activeOpacity={0.5}
containerStyle={styles.buttonContainer}
contentStyle={styles.buttonWelcome}
>
Réservation
</Button>
<Button
type="custom"
onPress={() => this.props.navigation.navigate("Acces")}
containerStyle={styles.buttonContainer}
contentStyle={styles.buttonWelcome}
>
Accès
</Button>
</View>
</ScrollView>
<Footer />
</View>
);
}
}
I have a parent view container it contains another view having two button components.I need to have a space between the button components for that I add justify-content into the child view container,but it's not working.
code
import React,{Component} from 'react';
import { View,Image,StyleSheet,Dimensions } from 'react-native';
import { Card,Button,Avatar } from 'react-native-elements';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class WelcomePage extends Component {
render() {
const {navigate}=this.props.navigation
return (
<View style={{flexDirection:'column',flex:1,alignItems:'center',justifyContent: 'flex-start'}}>
<Avatar
width={Dimensions.get('window').width}
containerStyle={{flex:85}}
avatarStyle={{flex:85}}
imageProps={{resizeMode:'cover'}}
source={require('../assets/images/logo.png')}
onPress={() => console.log("Works!")}
activeOpacity={0.7}
/>
<View style={{flexDirection:'row',flex:15,marginTop:10,justifyContent:'space-between'}}>
<Button large title='LOGIN' icon={<Icon name="user-secret" size={25} color="white" />} buttonStyle={{height:50,width:130,backgroundColor:"#b3b3b3"}} titleStyle={{fontWeight:"700"}} containerViewStyle={{borderRadius:5}} borderRadius={5} />
<Button large title='REGISTER' icon={<Icon name="user-plus" size={25} color="white" />} buttonStyle={{height:50,width:130,backgroundColor:"#b3b3b3"}} titleStyle={{fontWeight:"700"}} onPress={() => navigate('register')} containerViewStyle={{borderRadius:5}} borderRadius={5} />
</View>
</View>
)
}
}
output
using flexbox algorithm how can I add space in between the button components?
You need to remove the style alignItems:'center' from the parent wrapper.
Since alignItems: 'center' aligns your child elements to the center, then you can't see the effect of justifyContent: 'space-between'
Therefore modify your code as follows
<View style={{flexDirection:'column',flex:1,justifyContent: 'flex-start'}}> // Remove alignItems here
<Avatar
width={Dimensions.get('window').width}
containerStyle={{flex:85}}
avatarStyle={{flex:85}}
imageProps={{resizeMode:'cover'}}
onPress={() => console.log("Works!")}
activeOpacity={0.7}
/>
<View style={{flexDirection:'row',flex:15,marginTop:10,justifyContent:'space-between', paddingLeft: 20, paddingRight: 20}}> // Added some padding for a bettwer view
<Button large title='LOGIN' icon={<Icon name="user-secret" size={25} color="white" />} buttonStyle={{height:50,width:130,backgroundColor:"#b3b3b3"}} titleStyle={{fontWeight:"700"}} containerViewStyle={{borderRadius:5}} borderRadius={5} />
<Button large title='REGISTER' icon={<Icon name="user-plus" size={25} color="white" />} buttonStyle={{height:50,width:130,backgroundColor:"#b3b3b3"}} titleStyle={{fontWeight:"700"}} onPress={() =>{}} containerViewStyle={{borderRadius:5}} borderRadius={5} />
</View>
</View>