react native button does not fit on the screen - reactjs

I have 7 buttons on the screen, but 1 button is half visible, one button does not fit at all.
my code:
render() {
return (
<ScrollView style={styles.container}>
<Header />
<View>
<Text style={styles.headerText}>
LC Teknoloji
</Text>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.Isgr}
title="İş Giriş"
color="#00B0FF"
/>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.Yapilicak}
title="Yapılacaklar"
color="#00B0FF"
/>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.gcms}
title="İş Geçmişi"
color="#00B0FF"
/>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.alnck}
title="Alınıcaklar"
color="#00B0FF"
/>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.ulist}
title="Ürün Listesi"
color="#00B0FF"
/>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.Stok}
title="Stoklar"
color="#00B0FF"
/>
</View>
<View style={styles.btnstyl}>
<Button
onPress={this.Musteri}
title="Müşteriler"
color="#00B0FF"
/>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'grey',
flex: 1,
backgroundColor: "#F5FCFF",
},
headerText: {
fontSize: 20,
textAlign: "center",
margin: 0,
fontWeight: "bold",
top: 45,
},
btnstyl: {
left: 120,
height: 60,
width: 160,
marginBottom: -20,
top: 55,
},
})
enter image description here
I changed the background color or something, when I pull it up, the buttons come up, it doesn't fit on the screen from the place in the picture
Why do you think the screenshot doesn't fit?

In your styles. Remove the marginBottom and top
const styles = {
.....
btnstyl: {
left: 120,
height: 60,
width: 160
},
}
And add height to the View component of the text above the buttons:
<View style={{ height: 100 }}>
<Text style={styles.headerText}>
LC Teknoloji
</Text>
</View>

Related

Why are my buttons disappearing in React Native?

So I am trying to have two buttons on my React Native project and whenever I add text to my code the buttons disappear. Does anyone know why? The text I am trying to add is below
<Text
style={{
fontSize: 55,
fontFamily: 'Futura',
color: '#707070',
textAlign: 'left',
paddingTop: 50,
paddingLeft: 30
}}
>
Feed
</Text>
<Text
style={{
fontSize: 22,
fontFamily: 'Futura',
color: '#BABABA',
textAlign: 'left',
paddingTop: 10,
paddingLeft: 30
}}
>
Find the Circle for your needs!
</Text>
and the code I am trying to add it to is this
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button title="Button 1"/>
</View>
<View style={styles.buttonContainer}>
<Button title="Button 2"/>
</View>
</View>
All of my code is below but it only shows the text not the buttons.
import React, { Component } from 'react';
import { Button, View, StyleSheet, Text } from 'react-native';
export default class GridView extends Component {
render() {
return (
<View>
<Text
style={{
fontSize: 55,
fontFamily: 'Futura',
color: '#707070',
textAlign: 'left',
paddingTop: 50,
paddingLeft: 30
}}
>
Feed
</Text>
<Text
style={{
fontSize: 22,
fontFamily: 'Futura',
color: '#BABABA',
textAlign: 'left',
paddingTop: 10,
paddingLeft: 30
}}
>
Find the Circle for your needs!
</Text>
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button title="Button 1"/>
</View>
<View style={styles.buttonContainer}>
<Button title="Button 2"/>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
flex: 1,
},
headers: {
fontSize: 50,
}
});
This should fix your issue: My guess is there is something wrong with a parent component that is cutting of the render. If this is the only view on page also try adding the style {flex:1} to the outer most layer. This can happen sometimes if there is some styling on navigation setup that get passed to childern.
<View style={{flex:1}>
<Text style={{...}}>Feed</Text>
<Text style={{...}}>Find the Circle for your needs!</Text>
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button title="Button 1"/>
</View>
<View style={styles.buttonContainer}>
<Button title="Button 2"/>
</View>
</View>
</View>

How can I show some components when i click on a button?

next to Entertain text, there is an icon, called Button,
When I click on that icon, I want those parts(netflix to twitch) to come that place.
How can I do that? I mean, i want those part to be hide at first, but after i click on that icon, it should come to that place.
Here are my code,
ThirdScreen.js
import React from "react";
import { Text, SafeAreaView, View, StyleSheet, ScrollView } from "react-native";
import Transfer from "../icons/transfer.svg";
import Entertain from "../icons/entertain.svg";
import Netflix from "../icons/netflix.svg";
import Button from "../icons/button.svg";
import Dribble from "../icons/dribble.svg";
import Spotify from "../icons/spotify.svg";
import Twitch from "../icons/twitch.svg";
import Bill from "../icons/bill.svg";
import Time from "../icons/time.svg";
import Home from "../icons/home.svg";
import User from "../icons/user.svg";
import Ratio from "../icons/ratio.svg";
const ThirdScreen = () => {
return (
<SafeAreaView style={{ flex: 1, backgroundColor:"#ffffff"}}>
<View style={{ alignItems: "center", padding: 20 }}>
<Text style={styles.transaction}>Transaction History</Text>
</View>
<View style={{ padding: 10, }}>
<View style={styles.rows}>
<Text style={styles.bigBold}>Category</Text>
<Text style={{ color: "#7cb3d9" }}>This week</Text>
</View>
<View style={{ padding: 20 }}>
{/* Transfer */}
<View style={[styles.elevation, {marginBottom:10,}]}>
<View style={[styles.rows, {padding:5}]}>
<View style={styles.iconText}>
<Transfer height={30} width={22} fill={"#1E2439"} />
<Text style={styles.bigBold}>Transfer</Text>
</View>
<View>
<Button height={30} width={22} fill={"#1E2439"} />
</View>
</View>
</View>
{/* Entertain */}
<View style={styles.elevation}>
<View style={[styles.rows,{padding:5,}]}>
<View style={styles.iconText}>
<Entertain height={30} width={22} fill={"#1E2439"} />
<Text style={styles.bigBold}>Entertain</Text>
</View>
<View>
<Button height={30} width={22} fill={"#1E2439"} />
</View>
</View>
</View>
<ScrollView style={{padding:10}}>
{/* Netflix */}
<View style={styles.rows}>
<View style={styles.iconText}>
<View style={[styles.iconBackground, { backgroundColor: "#ffd4d5"}]}>
<Netflix height={30} width={22} fill={"#1E2439"} />
</View>
<View style={styles.entertainItems}>
<Text style={styles.entertainItemsText}>Netflix</Text>
<Text style={styles.grayText}>4 March</Text>
</View>
</View>
<View style={{ flexDirection: "column", alignItems: "flex-end" }}>
<Text style={styles.redText}>-$8.99</Text>
<Text style={styles.grayText}>Subscription</Text>
</View>
</View>
{/* Dribble */}
<View style={styles.rows}>
<View style={styles.iconText}>
<View style={[styles.iconBackground, { backgroundColor: "#fdd7e6" }]}>
<Dribble height={30} width={22} fill={"#1E2439"} />
</View>
<View style={styles.entertainItems}>
<Text style={styles.entertainItemsText}>Dribble</Text>
<Text style={styles.grayText}>12 March</Text>
</View>
</View>
<View style={{ flexDirection: "column", alignItems: "flex-end" }}>
<Text style={styles.redText}>-$120.00</Text>
<Text style={styles.grayText}>Subscription</Text>
</View>
</View>
{/* Spotify */}
<View style={{ marginVertical: 10, flexDirection: "row", justifyContent: "space-between" }}>
<View style={styles.iconText}>
<View style={[styles.iconBackground, { backgroundColor: "#d5ffd9" }]}>
<Spotify height={30} width={22} fill={"#1E2439"} />
</View>
<View style={styles.entertainItems}>
<Text style={styles.entertainItemsText}>Spotify</Text>
<Text style={styles.grayText}>25 March</Text>
</View>
</View>
<View style={{ flexDirection: "column", alignItems: "flex-end" }}>
<Text style={styles.redText}>-$9.99</Text>
<Text style={styles.grayText}>Subscription</Text>
</View>
</View>
{/* Twitch */}
<View style={{ marginVertical: 10, flexDirection: "row", justifyContent: "space-between" }}>
<View style={styles.iconText}>
<View style={[styles.iconBackground, { backgroundColor: "#efd6ff" }]}>
<Twitch height={30} width={22} fill={"#1E2439"} />
</View>
<View style={styles.entertainItems}>
<Text style={styles.entertainItemsText}>Twitch</Text>
<Text style={styles.grayText}>25 March</Text>
</View>
</View>
<View style={{ flexDirection: "column", alignItems: "flex-end" }}>
<Text style={styles.redText}>-$24.99</Text>
<Text style={styles.grayText}>Subscription</Text>
</View>
</View>
</ScrollView>
{/* Bill */}
<View style={styles.elevation}>
<View style={[styles.rows, { padding: 5, }]}>
<View style={styles.iconText}>
<Bill height={30} width={22} fill={"#1E2439"} />
<Text style={styles.bigBold}>Bill</Text>
</View>
<View>
<Button height={30} width={22} fill={"#1E2439"} />
</View>
</View>
</View>
</View>
{/* Footer */}
<View style={{flexDirection:"row", alignItems:"center", justifyContent:"space-between",marginHorizontal:35,}}>
<Home height={30} width={22} fill={"#1E2439"} />
<Ratio height={30} width={22} fill={"#1E2439"} />
<Time height={30} width={22} fill={"#1E2439"} />
<User height={30} width={22} fill={"#1E2439"} />
</View>
</View>
</SafeAreaView>
)
}
const styles = StyleSheet.create({
transaction: {
fontSize: 17,
fontWeight: "bold",
letterSpacing: .5,
},
elevation: {
backgroundColor: "#fdfdfd",
elevation: 3,
height: 60,
borderRadius: 10,
},
rows: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
marginVertical:10,
},
iconText: {
flexDirection: "row",
alignItems: "center",
},
iconBackground: {
height: 40,
width: 40,
borderRadius: 13,
alignItems: "center",
justifyContent: "center"
},
entertainItems: {
flexDirection: "column",
marginLeft:20,
},
bigBold: {
fontSize: 17,
fontWeight: "bold",
marginLeft:15,
},
entertainItemsText: {
fontSize:15,
fontWeight:"bold",
},
redText : {
color:"#e46e6a",
fontWeight: "bold",
fontSize:15,
},
grayText: {
color: "#b2b4c3",
},
})
export default ThirdScreen;
Here is the screenshot:
A simple approach is to store a boolean isShown that is toggled when interacting with the button. Use the useState hook to store and update that boolean:
const ThirdScreen = () => {
// Default to `false` so the section is initially hidden
const [isShown, setIsShown] = React.useState(false);
return (
<SafeAreaView style={{ flex: 1, backgroundColor:"#ffffff"}}>
<View style={{ alignItems: "center", padding: 20 }}>
<Text style={styles.transaction}>Transaction History</Text>
</View>
<View style={{ padding: 10, }}>
{/* ... */}
<View style={{ padding: 20 }}>
{/* Transfer */}
{/* ... */}
{/* Entertain */}
<View style={styles.elevation}>
<View style={[styles.rows,{padding:5,}]}>
<View style={styles.iconText}>
<Entertain height={30} width={22} fill={"#1E2439"} />
<Text style={styles.bigBold}>Entertain</Text>
</View>
<View>
<Button
height={30}
width={22}
onClick={() => { setIsShown((currIsShown) => !currIsShown); }}
fill={"#1E2439"}
/>
</View>
</View>
</View>
{/* Render the inner <ScrollView> only if `isShown` is true */}
{isShown && (
<ScrollView style={{padding:10}}>
{/* Netflix */}
{/* ... */}
</ScrollView>
)}
{/* Bill */}
{/* ... */}
</View>
{/* Footer */}
{/* ... */}
</View>
</SafeAreaView>
)
}
You can use the onClick event to change your required dom
For this first, make a state and set the initial value to false. Then use the onClick event and change the state using useEffect of setState.
At Last, change the CSS of the section to display: "none" on false and display: "block"( or other value ) on true

FlattList not scrolling all content

I'm learning react native and decided to make a list of my games, for that I use a FlatList (code below), but for some reason the FlatList just scroll a little and I can't see the entire content. I've tryed to add 'flex: 1' in a style (like some awnsers in the internet) but when I do this, all my content turn blank. Here are a screenshot of the maximum I can scroll.
My code (The function don't change nothing in layout, I just pick some data from a API, so I don't paste here):
import React from 'react';
import { Button, FlatList, Image, SafeAreaView, StatusBar, StyleSheet, Text, TextInput, View } from 'react-native'
export default function App() {
const [id, setId] = React.useState('');
const [apps, setApps] = React.useState([]);
return (
<SafeAreaView style={{padding: 20}}>
<StatusBar hidden={false} backgroundColor={"white"} barStyle={'dark-content'} />
<View>
<TextInput style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} onChangeText={text => setId(text)} keyboardType={'numeric'} value={id} placeholder={"Insira o ID do jogo aqui"} />
<Button onPress={e => addApp()} title="Adicionar" color="#841584" accessibilityLabel="Salvar Id" />
<View style={{marginTop: 32}}>
<FlatList data={apps} scrollEnabled={true}
renderItem={({item}) =>
<View style={{alignItems: 'center', marginBottom: 32}}>
<Image style={{width: "100%", height: 200}} source={{ uri: item.image}} />
<Text style={{fontSize: 20}}>{item.name}</Text>
<View style={{width: '100%', flexDirection: 'row', flex: 4, justifyContent: 'space-around'}}>
<View style={{flexDirection:'row', alignItems: 'center'}}>
<Image style={{width: 15, height: 15, marginRight: 5}} source={require('./assets/disc.png')} />
<Text>{item.disc}</Text>
</View>
<View style={{flexDirection:'row', alignItems: 'center'}}>
<Image style={{width: 15, height: 15, marginRight: 5}} source={require('./assets/calendar.png')} />
<Text>{item.dateLaunch}</Text>
</View>
<View style={{flexDirection:'row', alignItems: 'center'}}>
<Image style={{width: 15, height: 15, marginRight: 5}} source={require('./assets/calendar.png')} />
<Text>{item.dateBuy}</Text>
</View>
<View style={{flexDirection:'row', alignItems: 'center'}}>
<Image style={{width: 15, height: 15, marginRight: 5}} source={require('./assets/coin.png')} />
<Text style={{fontWeight: 'bold'}}>{item.price}</Text>
</View>
</View>
</View>
}
/>
</View>
</View>
</SafeAreaView>
);
}
Try this:
<FlatList style={{ flex: 0 }}
initialNumToRender={apps.length}
Or try:
Try using flex: 1 in the listContainer styling, this should make it stay in the boundaries of your parent view.

How to full width card using Flatlist react-native

I don't know why my card is not full width by using the FlatList
My current:
What I wish card should be full width
and here is my code
return (
<View style={styles.container}>
<View>
<Text style={{fontWeight: 'bold', fontSize: 20}}>Cateogories:</Text>
<FlatGrid
itemDimension={90}
items={items}
style={styles.gridView}
renderItem={({item, index}) => (
<TouchableOpacity>
<View
style={[styles.itemContainer, {backgroundColor: item.code}]}>
<Text style={styles.itemName}>{item.name}</Text>
<Image style={styles.iconSize} source={item.picture} />
</View>
</TouchableOpacity>
)}
/>
</View>
<FlatList
data={DATA}
showsHorizontalScrollIndicator={false}
horizontal={false}
keyExtractor={item => item.id}
renderItem={({item}) => {
return (
<List>
<ListItem noBorder style={{flex: 1}}>
<View style={{flex: 1}}>
<Card style={{flex: 1}}>
<CardItem style={{flex: 1}}>
<Left>
<Thumbnail
source={{
uri:
'https://www.foodbusinessafrica.com/wp-content/uploads/2019/04/milled-rice.jpg',
}}
/>
<Body>
<Text>NativeBase</Text>
<Text note>GeekyAnts</Text>
</Body>
</Left>
</CardItem>
<CardItem cardBody>
<Image
source={{
uri:
'https://www.foodbusinessafrica.com/wp-content/uploads/2019/04/milled-rice.jpg',
}}
style={{height: 200, width: null, flex: 1}}
/>
</CardItem>
<CardItem>
<Left>
<Button transparent>
<Icon active name="thumbs-up" />
<Text>12 Likes</Text>
</Button>
</Left>
<Body>
<Button transparent>
<Icon active name="chatbubbles" />
<Text>4 Comments</Text>
</Button>
</Body>
<Right>
<Text>11h ago</Text>
</Right>
</CardItem>
</Card>
</View>
</ListItem>
</List>
);
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
title: {
alignSelf: 'flex-end',
color: '#638A37',
fontSize: 15,
},
rowItem: {
flexDirection: 'row',
},
itemContainer: {
borderRadius: 10,
padding: 10,
height: 128,
borderWidth: 1,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: {width: 0, height: 5},
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 10,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
},
itemName: {
// color: '#5E782F',
fontSize: 22,
},
iconSize: {
alignSelf: 'flex-end',
marginTop: 27,
paddingLeft: 20,
width: 56,
height: 56,
},
});
Full-width card view util:
import 'react-native-gesture-handler';
import React from 'react';
import {Dimensions} from 'react-native';
import {Card} from 'react-native-elements';
const FullWidthCard = ({
gap = {horizontal: 0},
borderRadius = {topLeft: 0, topRight: 0},
children,
}) => {
return (
<Card
containerStyle={{
width: Dimensions.get('window').width - gap.horizontal,
borderTopLeftRadius: borderRadius.topLeft,
borderTopRightRadius: borderRadius.topRight,
children,
}}>
{children}
</Card>
);
};
export {FullWidthCard};
from UI component:
<FullWidthCard
gap={{horizontal: 0}}
borderRadius={{topLeft: 50, topRight: 50}}>
<ProfileContent navigation={navigation}></ProfileContent>
</FullWidthCard>

I want my view to fit all the screen in React Native

I am trying to put a background color for an app I am making but it doesn't fit to all the screen and the bottom of it doesn't take the style.
This is my code:
<ScrollView>
<View style={styles.main}>
<View style={{ marginTop: 10 }}>
<Image style={{ flex: 1, height: 80, width: 80, alignSelf: 'center', marginTop: 23 }}
source={require('./../src/img/profile.png')} />
</View>
<View style={styles.fourblock}>
<TouchableOpacity
style={styles.redbox}
onPress={() => Actions.personal()}>
<Text style={styles.redboxText}>
Personal Detail
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.redbox}
onPress={() => Actions.savedschools()}>
<Text style={styles.redboxText}>
Saved Schools
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.redbox}
onPress={() => Actions.languages()}>
<Text style={styles.redboxText}>
Your Reviews
</Text>
</TouchableOpacity>
</View>
</View>
</ScrollView>
And this is the style I want to put:
main: {
//marginTop: 52,
backgroundColor: '#F8F8FF',
flex: 1,
},
<ScrollView> must be inside <View style={styles.main}>
so
<View style={styles.main}>
<ScrollView>
<View>
// .........
</View>
</ScrollView>
</View>
<Image style={{ flex: 1, height: 80, width: 80, alignSelf: 'center', marginTop: 23 }}
resizeMode: 'stretch', // or 'cover' . <<------------------
source={require('./../src/img/profile.png')} />
One more way you can fit view on all screen is using positioning absolute and make all left, top, right and bottom 0.
Here is an example.
<View style={{ position : 'absolute', top : 0, left : 0, right : 0,bottom : 0,}}</View>

Resources