React Native Card Styling - react-native

How to stretch the content of the card so it has 100% width. For example I want the red paragraph to touch the edges horizontally so there won't be yellow space on the right and left. In other words I would like to remove the padding from the cad content so there will be no yellow shown.
Here is my code:
import React,{Component} from 'react';
import { Searchbar, Button, Card, Paragraph } from 'react-native-paper';
import { StyleSheet, SafeAreaView, View, ActivityIndicator, StatusBar, TextInput, Text } from 'react-native';
import { FlatList, TouchableOpacity } from 'react-native-gesture-handler';
render()
{
const styles = StyleSheet.create({
container: {
flex: 1,
},
menuContainer:{
// backgroundColor: 'orange',
borderRadius: 10,
margin: 10,
marginTop: 2,
},
menuItemHeader:{
backgroundColor: '#D9B611',
borderRadius: 10,
borderBottomRightRadius: 0,
borderBottomLeftRadius: 0,
},
menuItemHeaderText:{
marginTop:5,
fontSize:17,
fontWeight:'bold',
color:'#fff'
},
menuItemHeaderSubText:{
marginTop:5,
fontSize:15,
color:'#fff'
},
menuItemBody:{
backgroundColor: 'yellow',
borderWidth:1,
borderBottomRightRadius: 5,
borderBottomLeftRadius: 5,
borderColor: 'gray',
borderTopWidth: 0,
alignSelf: 'stretch',
},
menuItemBodyText:{
marginTop:5,
fontSize:15,
},
description_input: {
height: 150,
backgroundColor: 'red',
alignItems: this.multiline ? 'flex-start' : 'center',
},
action_buttons_positioning: {
alignSelf: 'flex-end',
backgroundColor: 'green',
},
action_buttons: {
width: 50,
elevation: 8,
// backgroundColor: "#D9B611",
backgroundColor: "gray",
justifyContent: "center",
alignItems: "center",
borderRadius: 10,
paddingHorizontal: 5,
paddingVertical: 2,
},
action_buttons_text: {
color: '#fff',
fontSize: 16,
padding: 5
},
bottomLogoContainer:{
alignSelf: "center",
justifyContent: 'center',
alignItems: 'center',
textAlign:"center",
height: 100,
marginBottom: 20,
zIndex: 0
},
bottomLogoImage:{
width: 150,
height: 150,
resizeMode: 'contain',
}
});
if (this.state.loading) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator />
</View>
)
}
return (
<>
<StatusBar barStyle="light-content" />
<SafeAreaView style={styles.container}>
<FlatList
data={DATA}
keyExtractor = {(item, index) => index.toString()}
renderItem={({ item }) => (
<Card style={styles.menuContainer}>
{/* <Card.Cover source={{ uri: item.cover_img }} /> */}
<Card.Title title={item.title.toString()} subtitle={item.title.toString()} style={styles.menuItemHeader}/>
<Card.Content style={styles.menuItemBody}>
<Paragraph style = {styles.description_input}>
<View>
<TextInput
underlineColorAndroid = "transparent"
placeholderTextColor = "gray"
autoCapitalize = "none"
multiline={true}
// numberOfLines={4}
placeholder = "Job description"
// onBlur={()=>this.lastNameValidation()}
// onChangeText={last_name => this.setState({ last_name })}
/>
</View>
</Paragraph>
<Paragraph style={styles.action_buttons_positioning}>
<TouchableOpacity onPress={() => alert('Clicked')}>
<View style={styles.action_buttons}>
<Text style={styles.action_buttons_text}>Edit</Text>
</View>
</TouchableOpacity>
</Paragraph>
</Card.Content>
</Card>
)
}
/>
{/* <View style={styles.bottomLogoContainer}>
<Image
style={styles.bottomLogoImage}
source={require('../../../../src/assets/img/logo_120.png')}
/>
</View> */}
</SafeAreaView>
</>
)
}
}

You can add paddingHorizontal: 0 in your menuItemBody styles object, i.e. the styles that apply to the Card.Content component.
The CardContent component apparently sets 16 horizontal padding by default.

Related

react-native-awesome-gallery shows only one image without gesture possible

related to : https://github.com/Flair-Dev/react-native-awesome-gallery
I tried many things, but nothing is working.
I made the gesture and reanimation installation as wanted.
what I have :
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import Gallery from 'react-native-awesome-gallery';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
const ModalInfos = (props) => {
const [showMenu, setShowMenu] = useState(false)
return (
<View style={style.centeredView}>
<View style={style.modalView}>
<Text>{props.infos.name}</Text>
<Text> lots of infos here</Text>
....
....
....
<Text style={{ fontWeight: 'bold' }}> check menu </Text>
<TouchableOpacity
onPress={() => setShowMenu(true)}
>
<MaterialCommunityIcons name="book-open-variant" size={20} color={'#fff'} />
</TouchableOpacity>
</View>
{
showMenu &&
<View style={style.gallery}>
<GestureHandlerRootView style={{ flex: 1 }}>
<Gallery
data={["http://10.0.2.2:8080/images/menu/" + props.infos.barInfos.photomenu1, "http://10.0.2.2:8080/images/menu/" + props.infos.barInfos.photomenu2]}
onIndexChange={(newIndex) => {
console.log(newIndex);
}}
/>
</GestureHandlerRootView>
</View>
}
</View>
)
}
const style = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 22,
},
modalView: {
width: '95%',
margin: 20,
backgroundColor: "white",
borderRadius: 20,
padding: 35,
alignItems: "center",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5
},
gallery: {
flex: 1,
width: "100%",
height: "100%",
position: 'absolute',
zIndex: 10,
backgroundColor: '#202124e6',
}
});
export default ModalInfos;
With or without the GestureHandlerRootViewits the same result, i can see only the first image, and I can't do anything, no swipe, no zoom, not gesture.
I switched to react-native-image-viewing
works more than perfectly

Slider height is not changing with height property in react-native-swiper

so I'm fairly new to react-native. I'm trying to implement a carousel with react-native-swiper.
Issue -
I want to set the carousel height to 150px, for this I set the property height to 150px, with this the carousel height got changed to 150px but when I try to render a text component below carousel, it is not rendering just below the carousel.
import React from 'react';
import { View, Text, StyleSheet } from "react-native";
import Swiper from 'react-native-swiper';
const styles = StyleSheet.create({
wrapper: { backgroundColor: "black", height: 150 },
slide1: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB'
},
slide2: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5'
},
slide3: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9'
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold'
}
})
const HomeScreen_ = () => {
return (
<>
<Swiper
style={styles.wrapper}
height={150}
showsButtons
autoplay
paginationStyle={{ height: 8, position: 'absolute', top: 130 }}
activeDot={
<View
style={{
backgroundColor: '#c3383833', width: 8,
height: 8, borderRadius: 4, marginLeft: 3,
marginRight: 3, marginTop: 3, marginBottom: 3
}} />
}>
<View style={styles.slide1}>
<Text style={styles.text}>Hello Swiper</Text>
</View>
<View style={styles.slide2}>
<Text style={styles.text}>Beautiful</Text>
</View>
<View style={styles.slide3}>
<Text style={styles.text}>And simple</Text>
</View>
</Swiper >
<Text style={{ height: 100, color: "black", }}>Just a Random Text</Text>
</>
)
};
export default HomeScreen_;
you can check this sample, in React Native, we have covered any component using View
import React from 'react';
import {View, Text, StyleSheet, SafeAreaView} from 'react-native';
import Swiper from 'react-native-swiper';
const SwiperExample = () => {
return (
<>
<View style={{flex: 0.3}}> // here
<Swiper
style={styles.wrapper}
showsButtons
autoplay
paginationStyle={{height: 8, position: 'absolute', top: 130}}
activeDot={
<View
style={{
backgroundColor: '#c3383833',
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 3,
marginRight: 3,
marginTop: 3,
marginBottom: 3,
}}
/>
}>
<View style={styles.slide1}>
<Text style={styles.text}>Hello Swiper</Text>
</View>
<View style={styles.slide2}>
<Text style={styles.text}>Beautiful</Text>
</View>
<View style={styles.slide3}>
<Text style={styles.text}>And simple</Text>
</View>
</Swiper>
</View>
<Text style={{height: 100, color: 'black'}}>Just a Random Text</Text>
</>
);
};
const styles = StyleSheet.create({
wrapper: {backgroundColor: 'black', flex: 1},
slide1: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB',
},
slide2: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5',
},
slide3: {
height: 150,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9',
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold',
},
});
export default SwiperExample;
I solved this issue by removing the height property in the wrapper object of StyleSheet and passing containerStyle={{ height: 150, flex: 0 }} as a prop in Swiper

React Native close Modal that is opened by different component

Hello I am fairly new to React Native and am currently having an issue with my modal component. My modal component has two props, gameData and isModalVisible. In Home.js modal prop isModalVisible has the value of a state variable isVisible that gets changed to true when a certain TouchableOpacity is pressed. Then inside my FeaturedGameModal.js isModalVisible is set from props. The issue I am having is closing the modal. Opening the modal this way works fine, but how should I close the modal since its visibility is being controlled by props that are in Home.js? Any help would be greatly appreciated. I have been working on this for two days now and it is driving me crazy. Thanks! I will include my two files in case you want to more closely inspect my code.
Home.js:
import React from 'react';
import {
View,
Text,
Image,
SafeAreaView,
TouchableOpacity,
ActivityIndicator,
Linking,
ScrollView,
TouchableHighlight,
} from 'react-native';
import {homeStyles} from '../styles/homeStyles';
import {styles} from '../styles/styles';
import {createIconSetFromIcoMoon} from 'react-native-vector-icons';
import icoMoonConfig from '../../assets/fonts/selection.json';
import {fetchData} from '../functions/fetch';
import Modalz from '../modals/FeaturedGameModal';
const Icon = createIconSetFromIcoMoon(icoMoonConfig);
class Home extends React.Component {
myData = {};
constructor(props) {
super(props);
this.state = {
error: false,
isFetching: true,
featuredGameModal: false,
isVisible: false,
};
}
handleFeaturedGame = async () => {
this.setState({}, async () => {
try {
const featureGameData = await fetchData(
'http://dev.liberty.edu/templates/flames/json/json_appHomeFeed.cfm',
);
this.setState({
error: false,
featuredGameData: featureGameData,
isFetching: false,
});
} catch (e) {
this.setState({
error: true,
});
console.log(e.message);
}
});
};
handleFeaturedModal() {
this.setState({featuredGameModal: false});
}
componentDidMount() {
this.handleFeaturedGame();
}
render() {
const {featuredGameData} = this.state;
return this.state.isFetching ? (
<View style={styles.center}>
<ActivityIndicator size="large" color="#AE0023" />
</View>
) : (
<ScrollView>
<SafeAreaView>
<View style={homeStyles.featuredGameContainer}>
<View style={homeStyles.centerHor}>
<Image
style={homeStyles.logo}
source={require('../../assets/images/FlamesLogo.png')}
/>
</View>
<View style={homeStyles.gameTimeContainer}>
<Text style={homeStyles.gameTime}>
{featuredGameData.featuredGame.eventdate}
</Text>
<Text style={homeStyles.gameTime}>
{featuredGameData.featuredGame.eventtime}
</Text>
</View>
<TouchableOpacity
activeOpacity={0.6}
onPress={() => {
this.setState({isVisible: true});
}}>
<View style={homeStyles.contentContainer}>
<View style={homeStyles.contentLeft}>
<Text style={homeStyles.teamText}>
{featuredGameData.featuredGame.teamname}
</Text>
<Text style={homeStyles.opponentText}>
vs {featuredGameData.featuredGame.opponent}
</Text>
<Text style={homeStyles.locationText}>
<Icon size={12} name={'location'} />
{featuredGameData.featuredGame.location}
</Text>
</View>
<View style={homeStyles.contentRight}>
<Image
style={homeStyles.opponentLogo}
source={{
uri: featuredGameData.featuredGame.OpponentLogoFilename,
}}
/>
</View>
</View>
</TouchableOpacity>
<View style={homeStyles.allContent}>
<Modalz
gameData={this.state.featuredGameData.featuredGame}
isModalVisible={this.state.isVisible}
/>
<View style={homeStyles.contentContainerBottom}>
<View style={homeStyles.contentLeft}>
<TouchableOpacity
style={homeStyles.buyTicketBtn}
onPress={() =>
Linking.openURL(featuredGameData.featuredGame.buyTickets)
}>
<Text style={homeStyles.buyTicketBtnText}>Buy Tickets</Text>
</TouchableOpacity>
</View>
<View style={homeStyles.liveContainer}>
<Text style={homeStyles.live}>Experience Live:</Text>
<View style={homeStyles.liveIconsContainer}>
<Icon
style={{color: '#FFF', marginRight: 4}}
size={15}
name={'radio'}
/>
<Icon style={{color: '#FFF'}} size={12} name={'LFSN'} />
</View>
</View>
</View>
</View>
</View>
<View style={homeStyles.newsContainer}>
{featuredGameData.News.map((item, key) => (
<View
key={key}
style={[homeStyles.centerHor, homeStyles.newsCard]}>
<Image
style={homeStyles.newsImage}
source={{
uri: item.Thumbnail,
}}
/>
<Text style={homeStyles.headline}>{item.Headline}</Text>
<View style={homeStyles.teamNameView}>
<Text style={homeStyles.teamNameText}>{item.teamname}</Text>
<Text>{item.GameDate}</Text>
</View>
</View>
))}
</View>
</SafeAreaView>
</ScrollView>
);
}
}
export default Home;
FeaturedGameModal.js:
import React from 'react';
import {
Alert,
Modal,
StyleSheet,
Text,
TouchableHighlight,
View,
Image,
Dimensions,
TouchableOpacity,
SafeAreaView,
} from 'react-native';
import {createIconSetFromIcoMoon} from 'react-native-vector-icons';
import icoMoonConfig from '../../assets/fonts/selection';
import {homeStyles} from '../styles/homeStyles';
const Icon = createIconSetFromIcoMoon(icoMoonConfig);
const windowWidth = Dimensions.get('window').width;
export default class Modalz extends React.Component {
constructor(props) {
super(props);
this.state = {
teamName: props.gameData.teamname,
opponentName: props.gameData.opponent,
eventDate: props.gameData.eventdate,
liveAudioURL: props.gameData.LiveAudioURL,
liveStatsURL: props.gameData.LiveStatsURL,
videoURL: props.gameData.VideoURL,
opponentLogoURL: props.gameData.OpponentLogoFilename,
};
}
render() {
const {
opponentName,
teamName,
eventDate,
opponentLogoURL,
liveStatsURL,
liveAudioURL,
videoURL,
location,
} = this.state;
const {isModalVisible} = this.props;
return (
<View>
<View style={styles.centeredView}>
<Modal
animationType="slide"
transparent={true}
visible={isModalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
<SafeAreaView style={{flex: 1, backgroundColor: 'transparent'}}>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Icon
style={styles.closeButton}
size={25}
name={'x'}
onPress={() => {}}
/>
<Text style={styles.upcomingGameTitle}>
{teamName} vs {opponentName}
</Text>
<Text style={styles.upcomingGameSubtitle}>{eventDate}</Text>
<View style={styles.facingLogosBlock}>
<View style={styles.leftTeamBlock} />
<View style={styles.rightTeamBlock} />
<View style={styles.vsTextWrapper}>
<Text style={styles.vsText}>VS</Text>
</View>
<View style={styles.logoWrapper}>
<Image
style={styles.facingLogoImg}
source={{
uri:
'https://www.liberty.edu/templates/flames/images/flamesMonogram.png',
}}
/>
<Image
style={styles.facingLogoImg}
source={{uri: opponentLogoURL}}
/>
</View>
</View>
<View>
<TouchableOpacity style={styles.buyTicketBtn}>
<Text style={styles.buyTicketBtnText}>Buy Tickets</Text>
</TouchableOpacity>
</View>
<View style={styles.buttonRow}>
<TouchableOpacity
style={{...styles.iconButton, ...styles.iconButtonLeft}}>
<Icon
style={styles.iconButtonIcon}
size={25}
name={'flag'}
onPress={() => {
this.toggleModal(!this.state.modalVisible);
}}
/>
<Text style={styles.iconButtonText}>Game Day</Text>
</TouchableOpacity>
<TouchableOpacity
style={{...styles.iconButton, ...styles.iconButtonRight}}>
<Icon
style={styles.iconButtonIcon}
size={25}
name={'stats'}
onPress={() => {
this.toggleModal(!this.state.modalVisible);
}}
/>
<Text style={styles.iconButtonText}>Live Stats</Text>
</TouchableOpacity>
</View>
<View style={styles.liveLinkBlock}>
<View style={styles.liveLinkLeft}>
<Icon
style={styles.iconButtonIcon}
size={18}
name={'LFSN'}
/>
<Text>The Journey 88.3 FM</Text>
</View>
<TouchableOpacity style={styles.liveButton}>
<Text style={styles.liveButtonText}>Listen Live</Text>
</TouchableOpacity>
</View>
<View style={styles.liveLinkBlock}>
<View style={styles.liveLinkLeft}>
<Icon
style={styles.iconButtonIcon}
size={18}
name={'espn3'}
/>
<Text>LFSN TV Production</Text>
</View>
<TouchableOpacity style={styles.liveButton}>
<Text style={styles.liveButtonText}>Watch Live</Text>
</TouchableOpacity>
</View>
</View>
</View>
</SafeAreaView>
</Modal>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modalView: {
flex: 1,
alignSelf: 'stretch',
backgroundColor: 'white',
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
paddingTop: 14,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
openButton: {
backgroundColor: '#F194FF',
borderRadius: 20,
padding: 10,
elevation: 2,
},
closeButton: {
position: 'absolute',
right: 16,
top: 16,
color: '#000',
},
closeText: {
color: '#000',
fontWeight: 'bold',
textAlign: 'center',
fontSize: 20,
},
upcomingGameTitle: {
color: '#19191A',
fontSize: 18,
fontWeight: 'bold',
},
upcomingGameSubtitle: {
color: '#747676',
fontSize: 13,
fontWeight: 'bold',
marginBottom: 16,
},
modalText: {
marginBottom: 15,
textAlign: 'center',
},
facingLogosBlock: {
flexDirection: 'row',
position: 'relative',
alignItems: 'center',
},
facingLogoImg: {
width: 100,
height: 100,
resizeMode: 'contain',
flex: 1,
},
leftTeamBlock: {
width: 0,
height: 0,
backgroundColor: 'transparent',
borderStyle: 'solid',
borderRightWidth: 35,
borderTopWidth: 185,
borderRightColor: 'transparent',
borderTopColor: '#AE0023',
borderLeftColor: '#AE0023',
borderLeftWidth: windowWidth / 2,
left: 15,
zIndex: -1,
position: 'relative',
},
rightTeamBlock: {
width: 0,
height: 0,
backgroundColor: 'transparent',
borderStyle: 'solid',
borderLeftWidth: 35,
borderBottomWidth: 185,
borderBottomColor: '#461964',
borderRightColor: '#461964',
borderLeftColor: 'transparent',
borderRightWidth: windowWidth / 2,
right: 15,
zIndex: -1,
position: 'relative',
},
vsTextWrapper: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: 'center',
alignItems: 'center',
},
vsText: {
color: '#000000',
backgroundColor: '#FFFFFF',
padding: 5,
fontWeight: 'bold',
},
logoWrapper: {
position: 'absolute',
width: windowWidth,
height: 185,
top: 0,
left: 35,
flexDirection: 'row',
alignItems: 'center',
},
buyTicketBtn: {
marginTop: 24,
backgroundColor: '#AE0023',
borderRadius: 4,
paddingVertical: 20,
paddingHorizontal: 12,
width: windowWidth - 24,
},
buyTicketBtnText: {
fontSize: 21,
color: '#fff',
fontWeight: 'bold',
alignSelf: 'center',
textTransform: 'uppercase',
},
buttonRow: {
paddingVertical: 24,
paddingHorizontal: 12,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
iconButton: {
backgroundColor: '#F0F3F5',
borderRadius: 4,
paddingVertical: 14,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
flex: 1,
},
iconButtonText: {
color: '#19191A',
fontWeight: 'bold',
fontSize: 16,
marginLeft: 10,
},
iconButtonIcon: {
color: '#000',
},
iconButtonLeft: {
marginRight: 6,
},
iconButtonRight: {
marginLeft: 6,
},
liveLinkBlock: {
padding: 12,
borderStyle: 'solid',
borderTopColor: '#F0F3F5',
borderTopWidth: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
},
liveButton: {
backgroundColor: '#F0F3F5',
borderRadius: 4,
paddingVertical: 14,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
liveButtonText: {
color: '#19191A',
fontWeight: 'bold',
fontSize: 16,
},
liveLinkLeft: {
flex: 2,
},
});
You should create hideModal function in Home.js then pass it to Modalz component.
In Home.js, add this function:
hideModalz = () => {
this.setState({isVisible: true});
}
And pass this function to Modalz props:
<Modalz
gameData={this.state.featuredGameData.featuredGame}
isModalVisible={this.state.isVisible}
hide={hideModalz}
/>
In Modalz, call this.props.hide(); if you want to hide modal.

How can I get a popup and type in image link in there and make my image appear on the box below?

import React, {useState} from "react";
import {StyleSheet, Text, View, StatusBar, Dimensions, TextInput, Platform, ScrollView,TouchableOpacity, Button } from 'react-native';
import { AppLoading } from "expo";
import { createStackNavigator } from '#react-navigation/stack';
import { NavigationContainer } from '#react-navigation/native';
const { height, width } = Dimensions.get("window");
import Display from "./display";
import Modal from "react-native-modal";
const Stack = createStackNavigator();
function HomeScreen({ navigation }) {
return(
<View style={styles0.container}>
<StatusBar barStyle= "light-content" />
<Text style={styles0.title}>Junior Facebook</Text>
<View style={styles0.mainwhite}>
<View style={styles0.first}>
<TextInput
style={styles0.input1}
placeholder = "Enter your email"
/>
<TextInput
style={styles0.input1}
placeholder = "Enter your password"
/>
</View>
<View style={styles0.second}>
<TouchableOpacity
style={styles0.button}
onPress={()=>navigation.navigate("Newsfeed")}
>
<Text>SignUp</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text>Log In</Text>
</TouchableOpacity>
</View>
</View>
</View>
)
}
function Member({navigation}) {
return (
<View style={{alignItems: "center", backgroundColor: "lightgreen", flex: 1}}>
<Text>Junior Facebook</Text>
<TextInput placeholder="Email" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Password" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Confirm Password" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Name" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Gender" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Location" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Alma Mater" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<Button style={{width: 100, height: 30}}title="Meeting"
onPress={()=>navigation.navigate("Meeting")}
>Meeting</Button>
</View>
);
}
export default class App extends React.Component{
render(){
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Member" component={Member} />
<Stack.Screen name="Newsfeed" component={Newsfeed} />
</Stack.Navigator>
</NavigationContainer>
)
}
}
const styles0 = StyleSheet.create({
container:{
flex:1,
backgroundColor : "#FFD6ED",
alignItems : "center"
},
title: {
color: "white",
marginTop : 100,
fontSize : 30,
fontWeight: "bold"
},
mainwhite:{
backgroundColor : "white",
width : width -65,
marginTop : 50,
borderRadius: 20
},
input1:{
borderStyle: "solid",
borderWidth: 2,
width: 300,
height: 50,
padding: 10,
marginVertical: 25,
},
input2:{},
first:{
marginVertical: 40,
alignItems : "center"
},
second: {
alignItems : "center",
marginVertical: 20,
},
button : {
marginBottom : 30
}
})
class Newsfeed extends React.Component{
render(){
return(
<View style={styles1.container}>
<StatusBar barStyle= "light-content" />
<View style={styles1.title}>
<Text style={styles1.title}>Junior Facebook</Text>
</View>
<View style={styles1.first}>
<TouchableOpacity style={styles1.profile}>
<Text>프로필</Text>
</TouchableOpacity>
<View style={styles1.allinput}>
<TouchableOpacity>
<TextInput
style={styles1.input}
placeholder = "글 입력"
/>
</TouchableOpacity>
<View style={styles1.button}>
<TouchableOpacity >
<Text style={styles1.picturebutton}>사진</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles1.pushbutton}>입력</Text>
</TouchableOpacity>
</View>
</View>
</View>
<View style={styles1.second}>
<ScrollView>
<Display/>
</ScrollView>
</View>
</View>
)
}
}
const styles1 = StyleSheet.create({
container:{
flex:1,
backgroundColor : "#FFD6ED",
alignItems:"center",
},
title: {
color: "white",
marginTop : 5,
fontSize : 18,
fontWeight: "bold",
marginBottom : 5,
alignItems:"center",
},
first :{
flex:1,
flexDirection : "row",
borderBottomWidth : StyleSheet.hairlineWidth,
marginLeft: 40
},
second:{
flex:3,
},
profile:{
backgroundColor : "white",
borderStyle: "solid",
borderWidth: 2,
width: 90,
height : 110,
marginTop : 3
},
allinput: {
flexDirection : "column",
alignItems:'flex-end',
borderBottomColor: "black",
padding : 3,
},
input:{
borderStyle: "solid",
borderWidth: 2,
width: 200,
height: 110,
padding: 10,
marginLeft : 5,
backgroundColor : "white",
},
button:{
flexDirection : "row"
},
picturebutton:{
fontSize: 24,
width: 60,
height:40,
borderStyle: "solid",
borderWidth: 1,
backgroundColor : "white",
marginVertical : 10,
marginHorizontal : 0
},
pushbutton:{
fontSize: 24,
width: 60,
height:40,
borderStyle: "solid",
borderWidth: 1,
marginLeft : 5,
backgroundColor : "white",
marginVertical : 10
}
})
and my Display component is as follows
import React from "react";
import {View, Text, TextInput, Button, StyleSheet, ScrollView, TouchableOpacity} from "react-native";
export default class Display extends React.Component{
render(){
const {text} = this.props;
return (
<View style={styles.pushtext}>
<Text>일단 한개</Text>
</View>
)
}
}
const styles = StyleSheet.create({
pushtext: {
backgroundColor : "white",
width: 300,
height: 50,
marginTop: 30
}
})
When I click the "Enter" TouchableOpacity, a popup should appear. And I should be able to type in an image link in the popup. And when I type in image link in there and click the "enter" text, an image from that link should appear below. How can I do so?
Please help me out here
Thank you so much!
According to your requirements, I made below sample
import React, { Component } from 'react';
import { View, StyleSheet, Button, Modal, TextInput, Image, } from 'react-native';
export default class App extends Component {
state = {
modalVisible: false,
link: '',
};
setModalVisible = () => {
this.setState({ modalVisible: !this.state.modalVisible });
};
onChangeText = text => {
this.setState({
link: text,
});
};
render() {
return (
<View style={styles.container}>
<Button title='Enter' onPress={this.setModalVisible} />
{
this.state.modalVisible &&
<Modal
visible={this.state.modalVisible}
transparent={true}
animationType="slide"
onRequestClose={this.setModalVisible}>
<View style={styles.modelStyle}>
<View style={styles.modelWrapperStyle}>
<TextInput
style={styles.inputStyle}
onChangeText={this.onChangeText}
value={this.state.link}
/>
<Button title='Enter' onPress={this.setModalVisible} />
</View>
</View>
</Modal>
}
{
!this.state.modalVisible && !!this.state.link &&
<Image
source={{ uri: this.state.link }}
style={{ width: 200, height: 200 }}
/>
}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modelStyle: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
modelWrapperStyle: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-around',
backgroundColor: '#ffffff',
padding: 10,
width: '90%',
},
inputStyle: {
height: 40,
width: '80%',
borderColor: 'gray',
borderWidth: 1,
}
});
Hope this helps you. Feel free for doubts.

How to center a TextInput when the keyboard opens in React Native

I have a view with 3 textinput and I am trying to center them when the keyboard is opened. I already tried with KeyboardAvoidingView and the result is that all, except the save button disappear. What am I doing wrong?
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TextInput,
ScrollView,
ListView,
KeyboardAvoidingView,
TouchableOpacity,
AsyncStorage,
} from 'react-native';
import Note from './Note.js';
export default class NoteBody extends Component {
static navigationOptions = {
header: null,
};
constructor(props){
super(props);
this.state = {
noteText: '',
noteTitle: '',
callType: '',
};
}
render() {
return (
<View style={styles.container}>
<View style={styles.header1}>
<Text style={styles.title}>New Note</Text>
</View>
<View style={styles.headerDesign}>
</View>
<View style={styles.header2}>
</View>
<View style= {styles.mainPage}>
<View style={styles.noteBody}>
<TextInput
style = {styles.subject}
placeholder='Raport Number/Note Indentifier'
onChangeText={(noteTitle)=> this.setState({noteTitle})}
value={this.state.noteTitle}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
<TextInput
style = {styles.calltype}
multiline = {true}
numberOfLines = {5}
placeholder='Call Type/Other Information'
onChangeText={(callType)=> this.setState({callType})}
value={this.state.callType}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
<TextInput
multiline = {true}
numberOfLines = {8}
style={styles.textInput}
placeholder='Notes'
onChangeText={(noteText)=> this.setState({noteText})}
value={this.state.noteText}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
</View>
<View style= {styles.footer}>
<TouchableOpacity onPress={ this.addNote.bind(this) } style={styles.addButton}>
<Text style={styles.addButtonText}>SAVE</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
addNote(){
const { navigate } = this.props.navigation;
if(this.state.noteText && this.state.noteTitle && this.state.callType){
var d = new Date();
this.props.navigation.state.params.noteArray.push({
'noteName':this.state.noteTitle,
'date':(d.getMonth()+1)+
"/"+d.getDate() +
"/"+ d.getFullYear(),
'callType': this.state.callType,
'note': this.state.noteText
});
this.setState({ noteArray: this.props.navigation.state.params.noteArray });
this.setState({noteText:''});
this.setState({noteTitle:''});
this.setState({callType:''});
AsyncStorage.setItem('arr', JSON.stringify(this.props.navigation.state.params.noteArray));
this.props.navigation.state.params.onNavigateBack();
this.props.navigation.goBack();
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
mainPage:{
flex: 2,
alignItems: 'center',
justifyContent:'center',
},
header1:{
backgroundColor: '#000',
alignItems: 'center',
height: 40,
justifyContent: 'center',
},
title:{
color: '#fff',
fontSize: 20,
},
header2:{
marginBottom: 10,
backgroundColor: '#000',
alignItems: 'center',
height: 40,
justifyContent: 'center',
},
headerDesign:{
backgroundColor: '#0000FF',
alignItems: 'center',
height: 20,
justifyContent: 'center',
},
noteBody:{
flex: 2,
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
zIndex: 10,
alignItems: 'center',
marginBottom: 100,
},
textInput: {
alignSelf: 'stretch',
textAlignVertical: 'top',
backgroundColor: '#fff',
color: '#000',
padding: 20,
borderTopWidth:1,
borderTopColor: '#D3D3D3',
borderBottomWidth:1,
borderBottomColor: '#000',
},
addButton: {
position: 'absolute',
zIndex: 11,
bottom: 20,
alignItems: 'center',
justifyContent: 'center',
width: 200,
backgroundColor: '#0000FF',
height: 40,
elevation: 8
},
addButtonText: {
color: '#fff',
fontSize: 20,
},
subject:{
alignSelf: 'stretch',
textAlignVertical: 'top',
backgroundColor: '#fff',
padding: 20,
borderTopWidth:1,
borderTopColor: '#000',
borderBottomWidth:1,
borderBottomColor: '#D3D3D3',
},
calltype:{
alignSelf: 'stretch',
textAlignVertical: 'top',
backgroundColor: '#fff',
padding: 20,
},
footer:{
flex: 3,
alignItems: 'center',
justifyContent:'center',
}
});
Please, copy the code in your text editor and give it a try. Just replace the wrapping view with KeyboardAvoidingView like so: https://facebook.github.io/react-native/docs/keyboardavoidingview.html#keyboardverticaloffset and tell me what else can I do?
You must insert the KeyboardAvoidingView in a ScrollView.
Like so:
<ScrollView>
<KeyboardAvoidingView styles={styles.container} behavior = 'padding' enabled>
</KeyboardAvoidingView>
</ScrollView>