How to fix issue with KeyboardAwareScrollView? - react-native

Screenshot
Screenshot2
import React from 'react';
import { View, SafeAreaView, StyleSheet, TextInput, Text, TouchableOpacity, Platform } from 'react-native';
import MapView, { UrlTile } from 'react-native-maps';
import tw from 'tailwind-react-native-classnames';
import { Card } from 'react-native-shadow-cards';
import { useNavigation } from '#react-navigation/native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
const MapScreen = () => {
const navigation = useNavigation();
let location = {
latitude: 5.354846154402075,
longitude: 100.30152659738222,
latitudeDelta: 0.001,
longitudeDelta: 0.002
}
return (
<SafeAreaView style={tw`bg-white h-full`}>
<View style={tw`h-2/3`}>
<MapView
style={styles.map}
mapType='standard'
region={location}>
<UrlTile
urlTemplate='https://api.maptiler.com/maps/openstreetmap/256/{z}/{x}/{y}.jpg?key=2fFGEOiBVDCSMRNfaU70'
shouldReplaceMapContent={true}>
</UrlTile>
</MapView>
</View>
<KeyboardAwareScrollView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
bounces={false}
enableOnAndroid={true}
scrollEnabled={true}
enableAutomaticScroll={true}
contentContainerStyle={{ flex: 1 }}>
<View style={styles.cardContainer}>
<Card style={styles.cardView}>
<Text style={{ fontSize: 11, paddingTop: 10, paddingLeft: 10 }}>From</Text>
<View style={styles.inputBox}>
<TextInput
style={{ paddingVertical: 0, paddingLeft: 10 }}
placeholder='Current Location'
keyboardType='current-location'>
</TextInput>
</View>
<Text style={{ fontSize: 11, paddingTop: 10, paddingLeft: 10 }}>To</Text>
<View style={styles.inputBox}>
<TextInput
style={{ paddingVertical: 0, paddingLeft: 10 }}
placeholder='Destination'
keyboardType='destination'>
</TextInput>
</View>
<View>
<TouchableOpacity
onPress={() => navigation.navigate('ShowResultScreen')}
style={styles.button}>
<Text
style={{
textAlign: 'center',
fontWeight: '700',
fontSize: 17,
color: '#fff'
}}>
Search
</Text>
</TouchableOpacity>
</View>
</Card>
</View>
</KeyboardAwareScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
map: {
width: '100%',
height: '100%',
},
cardContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
borderRadius: 25,
shadowOpacity: 0.8
},
cardView: {
width: '97%',
height: '95%',
paddingLeft: 10,
paddingTop: 3
},
button: {
backgroundColor: '#5AA9E6',
padding: 10,
borderRadius: 10,
marginTop: 15,
marginRight: 10
},
inputBox: {
borderRadius: 10,
width: '97%',
height: '15%',
backgroundColor: '#F5F3F4',
marginTop: 10
}
});
export default MapScreen;
I want to make the input section below is scrollable and not covered by the keyboard when the keyboard is pop up so that the Search button can be pressed after typing the required input.
Update: I have used KeyboardAwareScrollView instead of using KeyboardAvoidingView and ScrollView. However, the result is like the Screenshot2.

The easiest way is to use the package react-native-keyboard-aware-scroll-view.

Related

index.js:1 Unexpected text node: . A text node cannot be a child of a <View>

hellow, im new on react native, i want to create an app, fisrt in try to build its formula. it show me an error: {index.js:1 Unexpected text node: . A text node cannot be a child of a .}. here is my code i apreciate your help. (its a small calculator)
error: index.js:1 Unexpected text node: . A text node cannot be a child of a .
import React, {useState, useEffect, Component} from 'react';
import { AppRegistry, Text, View, TextInput, StyleSheet, Input, TouchableOpacity } from 'react-native';
import { Ionicons } from '#expo/vector-icons';
export default class App extends Component {
constructor(props){
super(props);
this.state = {
numero1 : 0,
numero2 : 0,
resultado : 0
}
}
sumar = () => {
console.log(this.state.numero1);
let num1 = parseFloat(this.state.numero1);
let num2 = parseFloat(this.state.numero2);
let res = num1 + num2;
this.setState({resultado : res})
}
render(){
return (
<View style={styles.container}>
<View>
<Text style={styles.Titulos}>INVERGEGA</Text>
</View>
<View> <Text> VALOR 1 </Text> </View>
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
value={this.state.numero1}
onChangeText={(text) => {this.setState({numero1 : text})}} />
</View>
<View> <Text>VALOR 2</Text> </View>
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
value={this.state.numero2}
onChangeText={(text) => {this.setState({numero2 : text})}} />
</View>
<View>
<Text>RESULTADO</Text>
</View>
<View style={styles.container2}>
<Text name="resultado">{this.state.resultado}</Text>
</View>
<TouchableOpacity style={styles.container2} name="btnCalcular"
onPress={this.sumar}><Text> Hit me daddy!</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'gray',
},
inputContainer: {
width: '90%',
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 10,
borderWidth: 1,
borderColor: 'gray',
borderRadius: 30,
backgroundColor: 'lightgray'
},
textInput: {
paddingLeft: 10,
flex: 1,
height: 50,
},
container2: {
width: '90%',
height: '5%',
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 10,
borderWidth: 1,
borderColor: 'gray',
borderRadius: 30,
backgroundColor: 'white',
},
Text1: {
fontWeight: 'bold',
fontSize: 22,
color: 'red'
},
Text2: {
fontWeight: 'bold',
fontSize: 22,
},
Titulos: {
fontWeight: 'bold',
fontSize: 40,
}
}
);
AppRegistry.registerComponent('Bursakaxx1', () => App);

How to remove default left and right padding in react native

Image of Text.
Want to remove the left and right padding of forget password Text.Please Help
import React, { useState } from "react"
import { View, Text, SafeAreaView, Button, StyleSheet, TextInput, TouchableOpacity, Platform } from "react-native"
const Practice = (props) => {
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
function onTappedLogIn() {
}
function onTappedForgetPass() {
}
function onTappedShow() {
}
return (
<SafeAreaView style={styles.containerView}>
<View style={styles.upperView}>
<TouchableOpacity>
<Text style={{ textDecorationLine: 'underline' }}>Sign Up</Text>
</TouchableOpacity>
</View>
<View style={styles.middleView}>
<Text style={[styles.text, { marginTop: 30 }]}>Email Address</Text>
<TextInput style={styles.textInput} onChangeText={(email) => setEmail(email)} />
<Text style={styles.text}>Password</Text>
<View style = {styles.passTextInputView}>
{/* <Text>Show</Text> */}
<TextInput style={styles.textInput} onChangeText={(pass) => { setPassword(pass) }} />
</View>
<TouchableOpacity style={styles.button} onPress={onTappedLogIn()}>
<View>
<Text style={styles.buttonText}>
Log In
</Text>
</View>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.forgetPass}>Forget Password?</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
)
}
const styles = StyleSheet.create({
containerView: {
flex: 1,
// justifyContent: 'center',
backgroundColor: 'grey'
},
middleView: {
flex: 0.45,
flexDirection: 'column',
backgroundColor: 'white',
marginLeft: 25,
marginRight: 25
},
upperView: {
flex: 0.30,
justifyContent: 'flex-start',
alignItems: 'flex-end',
marginRight: 15
},
text: {
marginLeft: 15,
marginTop: 15,
marginBottom: 20
},
textInput: {
borderBottomWidth: 1,
borderBottomColor: 'black',
marginLeft: 15,
marginRight: 15
},
button: {
padding: 15,
backgroundColor: 'green',
marginTop: 30,
marginLeft: 15,
marginRight: 15,
borderRadius: 25,
marginBottom: 20
},
buttonText: {
textAlign: "center",
fontWeight: 'bold',
color: 'white',
textDecorationLine: "underline"
},
forgetPass: {
textAlign: 'center',
textDecorationLine: 'underline',
includeFontPadding: false,
flex:0
},
passTextInputView:{
// flex:.3
}
})
export default Practice
Probably you need to set the text containers style to flex:0
Apply alignitems:'center' to the text container (sample)

NativeBase FAB is not working in React Native

First of all excuse me for asking a question which may or may not been answered before. I could not find the right answer for me.
I try to add a FAB in a react native project. Clicking on it to expand is working, but the items below it are not clickable. Neither on iOS as on Android.
I use this code:
import {useNavigation} from '#react-navigation/native';
import {Button, Fab, Icon, View} from 'native-base';
import React, {useEffect, useState} from 'react';
import {Image, Platform, SafeAreaView, StyleSheet} from 'react-native';
import {red} from '../../Settings/Theme';
const Header = () => {
const [fabActive, setFabActive] = useState(false);
const navigation = useNavigation();
useEffect(() => {
setFabActive(false);
}, []);
return (
<SafeAreaView style={styles.container}>
<View style={{flex: 1, alignItems: 'center'}}>
<Icon name="home" type="FontAwesome5" style={styles.iconStyle} />
</View>
<View style={{flex: 1, alignItems: 'center'}}>
<Image
style={styles.logoStyle}
source={{
uri: `urltologo`,
}}
/>
</View>
<View style={{flex: 1}}>
<Fab
active={fabActive}
direction="down"
containerStyle={{
marginTop: 24,
marginRight: 15,
}}
style={{
backgroundColor: red,
height: 63,
width: 63,
borderRadius: 32.5,
shadowOffset: {height: 0, width: 0},
shadowOpacity: 0,
elevation: 0,
}}
position="topRight"
onPress={() => setFabActive(!fabActive)}>
<Icon
name={fabActive ? 'times' : 'plus'}
type="FontAwesome5"
style={{fontSize: 28}}
/>
{fabActive ? (
<Button
style={{
backgroundColor: red,
height: 48,
width: 48,
borderRadius: 24,
}}
onPress={() => {
setFabActive(false);
navigation.navigate('Contact');
}}>
<Icon name="newspaper" type="FontAwesome5" />
</Button>
) : null}
{fabActive ? (
<Button
style={{
marginTop: 10,
backgroundColor: red,
height: 48,
width: 48,
borderRadius: 24,
}}>
<Icon name="lightbulb" type="FontAwesome5" />
</Button>
) : null}
{fabActive ? (
<Button
style={{
marginTop: 20,
backgroundColor: red,
height: 48,
width: 48,
borderRadius: 24,
}}>
<Icon name="calendar-week" type="FontAwesome5" />
</Button>
) : null}
{fabActive ? (
<Button
style={{
marginTop: 30,
backgroundColor: red,
height: 48,
width: 48,
borderRadius: 24,
}}>
<Icon name="list" type="FontAwesome5" />
</Button>
) : null}
</Fab>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
paddingTop: Platform.OS === 'android' ? 30 : 0,
backgroundColor: 'transparent',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-evenly',
},
iconStyle: {
marginTop: 40,
color: 'white',
fontSize: 32,
backgroundColor: red,
padding: 15,
borderWidth: 0,
overflow: 'hidden',
borderRadius: 32,
},
logoStyle: {
height: 135,
width: 135,
resizeMode: 'contain',
},
});
export default Header;
And I import it like this:
import React from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
import BackImage from "../Components/Common/BackgroundImage";
import HeaderComponent from "../Components/Common/Header";
import NewsComponent from "../Components/NewsComponent";
const NewsScreen = ({ navigation }) => {
return (
<BackImage>
<HeaderComponent />
<View style={styles.container}>
<NewsComponent />
</View>
</BackImage>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default NewsScreen;
Any ideas what i do wrong here?
I found your problem.
container: {
paddingTop: Platform.OS === 'android' ? 30 : 0,
backgroundColor: 'transparent',
flex: 0.2,
flexDirection: 'row',
justifyContent: 'space-evenly',
},
Change flex: 0.2 to flex: 1,

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.