ReactNative - Button Not Visible - react-native

I'm having an issue where I'm creating a simple button that isn't visible (but it is there because I'm able to trigger the onPress method) within this view, but I am able to create other components within this View that appear. My code in App.js is below, any help would be greatly appreciated!
import React from 'react';
import {
View,
StyleSheet,
Text,
TouchableOpacity,
} from 'react-native';
export default function App() {
return (
<View style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
}}>
<TouchableOpacity style={styles.button} onPress={() => console.log("Clicked")}>
<Text style={styles.text}>Login</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
button: {
color: "tomato",
borderRadius: 25,
justifyContent: "center",
alignItems: "center",
padding: 15,
height: 50,
width: "100%",
},
text: {
color: "#fff",
fontSize: 18,
fontWeight: "bold",
textTransform: "uppercase",
}
})

You have a white button with white text in front of a white background so it all blends in. Look at this expo snack and the code below to see why (https://snack.expo.dev/#heytony01/thankful-juice-box)
import React from 'react';
import {
View,
StyleSheet,
Text,
TouchableOpacity,
} from 'react-native';
export default function App() {
return (
<View style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
}}>
<TouchableOpacity style={styles.button} onPress={() => console.log("Clicked")}>
<Text style={styles.text}>Login</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
button: {
borderColor:"red", // give border color
borderWidth:2, // give border width
color: "tomato",
borderRadius: 25,
justifyContent: "center",
alignItems: "center",
padding: 15,
height: 50,
width: "100%",
},
text: {
color: "black", // change font to black
fontSize: 18,
fontWeight: "bold",
textTransform: "uppercase",
}
})

I was setting the color of the button instead of the backgroundColor

Related

How do I set my text like this in React Native?

I have tried textAlign="center" but it only aligns the text in the center but I want to align the whole text in the center including the last line
<Text
style={{
marginTop: 16,
alignSelf: 'center',
fontSize: 15,
width: '75%',
textAlignVertical: 'center',
justifyContent: 'center',
}}>
Making a luxurious lifestyle accessible for a generous group of
women is our daily drive.
</Text>
Here is the full example. please read about textAlign property.
import React, {useState} from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
const App = () => {
return (
<View style={styles.container}>
<Text
style={styles.text}>
Making a luxurious lifestyle accessible for a generous group of
women is our daily drive.
</Text>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems:"center",
padding: 8,
backgroundColor: 'white',
},
text:{
marginTop: 16,
alignSelf: 'center',
fontSize: 15,
textAlign:"center",
width: '75%',
textAlignVertical: 'center',
justifyContent: 'center',
}
});

Display Checkboxes Horizontally

I imported some custom checkboxes but they're displaying vertically and I want them to be displayed horizontally in a row
I tried changing the flex-direction and some other things but none of that has changed anything.
Here is my code:
import { Pressable, StyleSheet, Text, View } from "react-native";
import React from "react";
import { MaterialCommunityIcons } from "#expo/vector-icons";
const CheckBox = (props) => {
const iconName = props.isChecked
? "checkbox-marked"
: "checkbox-blank-outline";
return (
<View style={styles.container}>
<Pressable onPress={props.onPress}>
<MaterialCommunityIcons name={iconName} size={40} color="#000" />
</Pressable>
<Text style={styles.title}>{props.title}</Text>
</View>
);
};
export default CheckBox;
const styles = StyleSheet.create({
container: {
justifyContent: "center",
alignItems: "center",
flexDirection: "column",
width: 150,
marginTop: 5,
marginHorizontal: 5,
flexWrap: "wrap",
},
title: {
fontSize: 20,
color: "#000a",
textAlign: "left",
top: 50,
marginTop: 40,
},
});
You need to change the flexDirection from column to row. Furthermore, you need to remove the topMargin from the title style for otherwise the checkbox and the text won't be aligned.
The adapted styles:
const styles = StyleSheet.create({
container: {
justifyContent: "center",
alignItems: "center",
flexDirection: "row",
width: 150,
marginTop: 5,
marginHorizontal: 5,
flexWrap: "wrap",
},
title: {
fontSize: 20,
color: "#000a",
},
});
The final product:
You can do it by just updating your CSS like this in your container stylesheet class :
{
flexDirection: "row",
Display:in-line,
float:left,
},

React Native Can't set margin after image

Why can't I separate the last two components?
First, I tried to set justifyContent, but it did not work.
Then, I tried to set margin. It works for title and image, but not for components after Image
I think is because I'm setting image height, but without it image will not appear
import React, {useState, useEffect} from 'react';
import {View, Text, Image, StyleSheet} from 'react-native';
const Card = ({ evento }) => {
return (
<View style={styles.card_container}>
<Text style={styles.titulo}>
{evento.titulo} - R$ {evento.valor}
</Text>
<Image
style={styles.img}
source={{uri: 'https://via.placeholder.com/150'}}
/>
<Text styles={styles.descricao}>{evento.descricao}</Text>
<Text styles={styles.guia}>Organizador: {evento.guia}</Text>
</View>
);
};
const styles = StyleSheet.create({
card_container: {
// flex: 1,
// display: 'flex',
// flexDirection: 'column',
// justifyContent: 'space-between',
fontFamily: 'Rubik-Light',
margin: 3,
marginBottom: 15,
padding: 10,
borderRadius: 10,
backgroundColor: '#ffffff',
elevation: 1,
},
titulo: {
fontFamily: 'Rubik-Medium',
margin: 10,
},
img: {
//alignSelf: 'center',
width: 350, //TODO tamanho dinĂ¢mico
height: 200,
marginBottom: 10, // word
},
descricao: {
marginBottom: 10,
},
guia: {
marginTop: 10
}
});
export default Card;
It's a typo on the Text component. It should be style for the prop in Text component not styles. Here are the correct codes for the last two components.
<Text style={styles.descricao}>{evento.descricao}</Text>
<Text style={styles.guia}>Organizador: {evento.guia}</Text>

How to set one icon in left and text in center in header in react native

Am trying to set my icon in left and text in center (like Image which I have give) in header by using flex but they both are going in center how to solve it.
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Text,
View,
} from 'react-native'
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.cross}>X</Text>
<Text style={styles.headerText}>Invester Profile</Text>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
header: {
backgroundColor:'#212121',
height: 159.9,
flexDirection: 'row',
},
headerText: {
color: 'white',
marginTop: 20,
textAlign: 'center',
},
cross: {
color: 'white',
marginTop: 20,
}
})
Just add flex: 1 to headerText. Like this:
headerText: {
color: 'white',
marginTop: 20,
textAlign: 'center',
flex: 1
}

Invalid prop types: Prop.style key fontSize supplied to view

I've built a screen which just contains content in the center of the screen and includes background image. I checked the code but haven't found something that wrong. Here is the code:
import React, {Component} from "react";
import {Image} from "react-native";
import {
Content,
Button,
Text,
Icon,
} from "native-base";
class ThankyouScreen extends Component {
render() {
return (
<Image style={styles.image} source={require("../img/cover.jpg")}>
<Content
contentContainerStyle={{
alignSelf: "center",
justifyContent: "center",
flex: 1,
}}
>
<Icon name="checkmark" style={styles.icon} />
<Text style={styles.text}> Thank You For Joining Us!!</Text>
<Button
bordered
style={styles.button}
onPress={() => this.props.navigation.navigate("Home")}
>
<Text style={{color: "#42e5f4"}}> Back To Home</Text>
</Button>
</Content>
</Image>
);
}
}
const styles = {
image: {
flex: 1,
alignSelf: "stretch",
width: undefined,
height: undefined,
},
icon: {
justifyContent: "center",
alignSelf: "center",
fontSize: 90,
fontWeight: "bold",
color: "#42e5f4",
},
text: {
justifyContent: "center",
alignSelf: "center",
fontSize: 20,
color: "#42e5f4",
},
button: {
alignSelf: "center",
marginTop: 15,
fontSize: 10,
fontWeight: "bold",
color: "#0dc49d",
borderColor: "#42e5f4",
},
};
export default ThankyouScreen;
Error looks strange and its difficult to understand why it causes. What's wrong on this code and how it can be solved?
This might be a problem with NativeBase. There is a discussion for this in github