NativeBase FAB is not working in React Native - 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,

Related

How to fix issue with KeyboardAwareScrollView?

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.

TouchableOpacity outside parent View in absolute positive not works react native

I was making Picker component but what I found is Touchable Opacity in absolute positions outside from it's parent view not works.
const App = () => {
const data = [2, 3, 4, 23]
const [isOpen, setIsOpen] = useState(true);
return (
<View style={{ flex: 1, backgroundColor: 'white', justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity style={styles.container} onPress={setIsOpen.bind(null, true)} disabled={isOpen}>
<Text>3</Text>
<Image source={require('./assets/downArrow2.png')} />
{
isOpen && (
<View style={styles.optionsContainer}>
{
data.map((number, index) => (
<View key={index}>
<TouchableOpacity onPress={() => { setIsOpen(false) }}>
<View style={{ padding: 10, paddingRight: 40 }}>
<Text>{number}</Text>
</View>
</TouchableOpacity>
<View style={{ height: 1, width: '100%', backgroundColor: 'white' }} />
</View>
))
}
</View>
)
}
</TouchableOpacity>
</View>
)
}
const styles = StyleSheet.create({
container: {
width: 48,
paddingVertical: 8,
paddingRight: 5,
paddingLeft: 8,
borderWidth: 1,
borderColor: 'grey',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
position: 'relative'
},
optionsContainer:
position: 'absolute',
top: -1,
left: -1,
backgroundColor: 'grey'
}
})
So, There is outer TouchableOpacity Component & inside we are mapping many TouchableOpacity Component where children are in Absolute View.
TouchableOpacity inside it's parent's view works, but not Works outside Parent View with absolute position. Is their someOne to help me out with it???
It even Not works with TouchableNativeFeedback
Using TouchableOpacity from react-native-gesture-handler solves the issue of absolute position touches. However, it leads to some styling issues such as the overflow "visible" property not working.
So what you can do is that, for the parent TouchableOpacity you can use react-native's TouchableOpacity and for children you can use react-native-gesture-handler's TouchableOpacity to get the touch to work even when positioned absolutely.
This is the updates code. Please note the imports.
import { useState } from 'react';
import {View, StyleSheet, Text, TouchableOpacity as TouchableRN} from 'react-native';
import {TouchableOpacity} from 'react-native-gesture-handler'
const App = () => {
const data = [2, 3, 4, 23]
const [isOpen, setIsOpen] = useState(false);
return (
<View style={{ flex: 1, backgroundColor: 'white', justifyContent: 'center', alignItems: 'center' }}>
<TouchableRN style={styles.container} onPress={setIsOpen.bind(null, true)} disabled={isOpen}>
<Text>3</Text>
<Image source={require('./assets/downArrow2.png')} />
{
isOpen && (
<View style={styles.optionsContainer}>
{
data.map((number, index) => (
<View key={index}>
<TouchableOpacity onPress={() => { setIsOpen(false) }}>
<View style={{ padding: 10, paddingRight: 40 }}>
<Text>{number}</Text>
</View>
</TouchableOpacity>
<View style={{ height: 1, width: '100%', backgroundColor: 'white' }} />
</View>
))
}
</View>
)
}
</TouchableRN>
</View>
)
}
const styles = StyleSheet.create({
container: {
width: 48,
paddingVertical: 8,
paddingRight: 5,
paddingLeft: 8,
borderWidth: 1,
borderColor: 'grey',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
position: 'relative'
},
optionsContainer: {
position: 'absolute',
top: -1,
left: -1,
backgroundColor: 'grey'
}
})
export default App;

React Native Card Styling

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.

React Native: ScrollView and Layout Elements with flex

Hi i'm trying to add a ScrollView but it doesn't work like expected.
If i add flex:1 to ScrollView then i can style the child elements but there is no scroll bar so i can't scroll.
If I remove flex:1 or change it to flexGrow then i have the scrollbar but the styles are broken on the child elements.
How i can add i ScrollView and the styles to the childs?
I need some Information why is it happen. Thank you.
import React, { useContext, useState, useEffect } from 'react';
import {
Text,
TextInput,
StyleSheet,
View,
TouchableOpacity,
Alert,
ScrollView,
} from 'react-native';
import { globalStyles } from '../styles/global';
import colors from '../styles/color';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import Feather from 'react-native-vector-icons/Feather';
import * as Animatable from 'react-native-animatable';
import Button from '../components/Button';
const SignInScreen = (props) => {
return (
<View style={styles.container}>
<ScrollView contentContainerStyle={styles.scrollViewContainer}>
<View style={styles.containerTop}>
<Text style={globalStyles.h1}>Login</Text>
</View>
<View style={styles.containerBottom}>
<View style={styles.viewAction}>
<FontAwesome name='user-o' color='#ccc' size={20} style={{ width: 20 }} />
<TextInput
style={[styles.input]}
placeholder="Your Email"
value={data.email}
autoCapitalize='none'
onChangeText={(val) => textInputEmailChange(val)}
/>
</View>
<View style={styles.viewAction}>
<FontAwesome name='lock' color='#ccc' size={20} style={{ width: 20 }} />
<TextInput
style={[styles.input]}
placeholder="Password"
value={data.password}
autoCapitalize='none'
secureTextEntry={data.secureTextEntry ? true : false}
onChangeText={(val) => handlePasswordChange(val)}
/>
<TouchableOpacity onPress={updateSecureTextEntry}>
{data.secureTextEntry ? <Feather name='eye-off' color='#ccc' size={20} style={{ width: 20 }} />
: <Feather name='eye' color='#80c904' size={20} style={{ width: 20 }} />
}
</TouchableOpacity>
</View>
{uiErrors.errors ? (<Text style={styles.errorMsg}>{uiErrors.errors}</Text>) : (<Text></Text>)}
<Button
content={'Login'}
buttonStyles={{ marginVertical: 20, paddingVertical: 15, }}
onPress={handleLogin}
/>
<Button
content={'Login'}
buttonStyles={{ marginVertical: 20, paddingVertical: 15, }}
onPress={handleLogin}
/>
<Button
content={'Login'}
buttonStyles={{ marginVertical: 20, paddingVertical: 15, }}
onPress={handleLogin}
/>
<Button
content={'Login'}
buttonStyles={{ marginVertical: 20, paddingVertical: 15, }}
onPress={handleLogin}
/>
<Button
content={'Login'}
buttonStyles={{ marginVertical: 20, paddingVertical: 15, }}
onPress={handleLogin}
/>
<Button
content={'Create an account'}
buttonStyles={{ backgroundColor: 'transparent' }}
textStyles={styles.signUpBtnText}
onPress={() => { navigation.navigate('SignUp'); }}
/>
</View>
</ScrollView>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.light_theme.splashgb,
},
scrollViewContainer: {
// flex: 1,
// flexGrow: 1,
// justifyContent: 'space-between'
},
containerTop: {
flex: 1, // it add this only if flex:1 is added to scrollViewContainer but the then i can't scroll.
padding: 25,
backgroundColor: 'blue'
},
containerBottom: {
flex: 1,
padding: 25,
flexDirection: 'column',
backgroundColor: colors.light_theme.container,
borderTopLeftRadius: 25,
borderTopRightRadius: 25,
},
viewAction: {
flexDirection: 'row',
width: '100%',
borderBottomWidth: 1,
borderBottomColor: colors.light_theme.lightgray,
paddingVertical: 0,
alignItems: 'center',
},
input: {
flex: 1,
padding: 15,
},
text: {
color: colors.light_theme.white,
},
errorMsg: {
color: colors.light_theme.errorMsg,
fontSize: 14,
marginVertical: 5,
},
signUpBtnText: {
color: colors.light_theme.primary
}
});
export default SignInScreen;
1: Put your ScrollView inside a View:
... <View><ScrollView> ... </ScrollView></View> ...
2: Remove "flex:1" from your scrollViewContainer style so it will be only with felxGrow and justifyContent

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.