Touchable Highlight not getting blurry when modal opens in react native - react-native

I have a modal which blurs the background view when it opens up.But the background has a Touchable Highlight which is not getting blurred.My code for the background View looks like this:
import React, {Component} from 'react';
import {View, Text, Image, StyleSheet, TouchableHighlight} from 'react-native';
import ModalContent from './modalView';
export default class Customquotesconfirmation extends Component {
constructor(props) {
super(props);
this.state={
modalVisible: false,
phoneNumber: '9018938260',
clearTextInputValue: false
}
this.hideModal=this.hideModal.bind(this);
this.showModal=this.showModal.bind(this);
}
showModal(modalState) {
this.setState({ modalVisible: modalState});
}
hideModal(modalState) {
this.setState({modalVisible: modalState});
}
render(){
return(
<View style={(this.state.modalVisible == true) ? styles.modalStyle : styles.modalCloseStyle }>
<Text style={{textAlign:'center', color: '#097543', fontSize: 28, fontFamily: 'SourceSansPro-Black', marginTop:40, marginLeft:40, marginRight:40}}>Thank you for your interest!</Text>
<Text style={{textAlign: 'center', color: '#666666',fontSize: 18, fontFamily: 'SourceSansPro-Black', marginLeft: 40, marginRight:40, marginTop:20 }}>Tap "Submit" and a lawn care professional will contact you with information about tailored service.</Text>
<Image style={{width: 150, height:150, justifyContent:'center', alignItems:'center', marginLeft:150, marginTop: 40}}
source={require('../../../assets/img/mobile_image.png')}></Image>
<Text style={{marginLeft: 20, marginRight:20, marginTop:20, fontSize:8, color:'#666666'}}>By tapping "Submit" I provide my personal information including phone number and consent to: (1) receive autodialed calls, texts, and prerecorded messages from Trygreen regarding my account, including current and possible future services, customer service and billing; and (2) Trugreen's Privacy Policy and Terms and Conditions(including this arbitration provision).I understand that my consent is not required to purchase TruGreen services and that I may revoke consent for automated communications at any time.</Text>
<TouchableHighlight
onPress={() => {this.setState({ modalVisible: true})}}
underlayColor="#FFFFFF">
<View style={styles.submitButtonStyle}>
<Text style={{color: '#FFFFFF', fontSize:25, textAlign: 'center',marginTop:10, fontStyle:'SourceSansPro-Bold'}}>Submit</Text>
</View>
</TouchableHighlight>
{/* Modal Content */}
{
this.state.modalVisible ?
<ModalContent
modalVisible={this.state.modalVisible}
showModal={this.showModal}
hideModal={this.hideModal}
phoneNumber={this.state.phoneNumber}
/> : null
}
</View>
);
}
}
const styles = StyleSheet.create({
modalStyle: {
backgroundColor: 'rgba(0,0,0,0.5)', height:800
},
modalCloseStyle: {
backgroundColor:'rgba(0,0,0,0)'
},
modalViewStyle:{
flex: 1, flexDirection:'column' , marginTop:200, marginBottom:200, marginLeft:80, marginRight:80, height:220, backgroundColor:'#FFFFFF'
},
submitButtonStyle: {
width:200, height:50, backgroundColor: '#ff9933', marginLeft:120, borderRadius:2, marginTop:20
},
blurButtonOnModalOpen: {
width:200, height:50, marginLeft:120, borderRadius:2, marginTop:20, backgroundColor: 'rgba(0,0,0,0.5)',
}
})
And my modal view code is:
import React, { Component } from 'react';
import {View, Text, TouchableHighlight, Modal, TextInput, StyleSheet} from 'react-native';
export default class ModalPopup extends Component {
constructor(props) {
super(props);
this.state={
modalVisible: this.props.modalVisible,
}
}
render() {
return(
<View style={{flex:1, alignItems:'center', justifyContent:'center'}}>
<Modal
animationType='slide'
visible={this.state.modalVisible}
transparent={true}
onRequestClose={() => {
this.props.hideModal(false);
}
}
>
<View style={ (this.state.modalVisible ? styles.modalViewStyle : null )}>
<View style={{ backgroundColor: '#32CD32', height: 100}}>
<TouchableHighlight
onPress={() => {this.setState({ clearTextInputValue: true})}}
underlayColor="##32CD32">
<Text style={{ marginLeft:10, marginTop:10, color:'#FFFFFF', fontSize: 20}}> x </Text>
</TouchableHighlight>
<Text style={{ marginLeft:60, color:'#FFFFFF', fontSize: 15, marginTop: -25}}> Contact Info </Text>
<Text style={{ marginLeft:40, marginTop:10, color:'#FFFFFF', fontSize: 20, fontStyle: 'SourceSansPro-Bold' }}> Phone Number </Text>
</View>
<View style={{backgroundColor:'#FFFFFF'}}>
<Text style={{ marginLeft:20, marginTop:10, color:'grey', fontSize: 20, fontStyle: 'SourceSansPro-Bold', marginRight:20 }}> Please confirm best contact number. </Text>
<TextInput
style={{fontSize:20, height:40, justifyContent:'center', borderTopWidth: 2, borderLeftWidth: 2, borderColor:'grey', width:200, height: 50, marginLeft: 20, marginTop: 20}}
keyboardType= 'numeric'
defaultValue={this.state.clearTextInputValue ? '' : this.props.phoneNumber}
maxLength={10}></TextInput>
<TouchableHighlight
onPress={() => {this.props.hideModal(false)}}
underlayColor="#FFFFFF">
<View style={{ width:200, height:50, backgroundColor: '#ff9933', marginLeft:20, borderRadius:2, marginTop:20}}>
<Text style={{color:'#FFFFFF', fontSize:25, textAlign: 'center',marginTop:10, fontStyle:'SourceSansPro-Bold'}}>Submit</Text>
</View>
</TouchableHighlight>
</View>
</View>
</Modal>
</View>
);
}
}
const styles = StyleSheet.create({
modalViewStyle:{
flex: 1, flexDirection:'column' , marginTop:200, marginBottom:200, marginLeft:80, marginRight:80, height:220, backgroundColor:'#FFFFFF'
},
submitButtonStyle: {
width:200, height:50, backgroundColor: '#ff9933', marginLeft:120, borderRadius:2, marginTop:20
},
})
Now when the modal opens up, the screen looks like this:
Can someone please help me with this issue.

Related

React Native animation transition opacity from 0 to 1 does not work

I am using expo with Android Virtual Device .I am trying to mimic this animation behavior from this example, https://codepen.io/borntofrappe/pen/qwqPwq,
Here is what it looks like right now:
I use flag array to represent which button is clicked, if the certain button is clicked, I will call handleSpeedBtn function to change its corresponding flag, when the flag is true, it will provide buttonTextLayer style to this button. Right now,I am having trouble displaying the buttonTextLayer style in animation style.It applies buttonTextLayer style to the button without any animation, besides, I do not have any errors when I run the code. Just change the opacity from 0 to 1 probably would not make my app looks like the example I found on codepen, but I just want to see the animation at least. Thanks for help!
import React, { useState } from "react";
import {
Text,
StyleSheet,
View,
TouchableOpacity,
Animated,
} from "react-native";
import { MaterialCommunityIcons } from "#expo/vector-icons";
const SortTitle = ({ callBack, title }) => {
const [flag, setFlag] = useState([false, true, false]);
const opacity = useState(new Animated.Value(0))[0];
const handleSpeedBtn = (index) => {
let ary = [false, false, false];
ary[index] = ary[index] == true ? false : true;
setFlag(ary);
Animated.timing(opacity, {
toValue: 1,
duration: 2000,
useNativeDriver: true,
}).start();
};
return (
<View>
<View style={styles.titleContainer}>
<Text style={styles.titleText}>{title}</Text>
</View>
<View style={styles.btnGroupContainer}>
<View style={styles.btnContainer}>
<TouchableOpacity onPress={() => handleSpeedBtn(0)}>
<Animated.View
style={[flag[0] ? styles.buttonTextLayer : {}, opacity]}>
<MaterialCommunityIcons
name="speedometer-slow"
size={46}
color="white"
style={[flag[0] ? styles.icon : {}]}
/>
<Text style={[styles.buttonText, flag[0] ? {} : styles.hidden]}>
Slow
</Text>
</Animated.View>
</TouchableOpacity>
</View>
<View style={styles.btnContainer}>
<TouchableOpacity onPress={() => handleSpeedBtn(1)}>
<Animated.View
style={[flag[1] ? styles.buttonTextLayer : {}, opacity]}>
<MaterialCommunityIcons
name="speedometer-medium"
size={46}
color="white"
style={[flag[1] ? styles.icon : {}]}
/>
<Text style={[styles.buttonText, flag[1] ? {} : styles.hidden]}>
Medium
</Text>
</Animated.View>
</TouchableOpacity>
</View>
<View style={styles.btnContainer}>
<TouchableOpacity onPress={() => handleSpeedBtn(2)}>
<Animated.View
style={[flag[2] ? styles.buttonTextLayer : {}, opacity]}>
<MaterialCommunityIcons
name="speedometer"
size={46}
color="white"
style={[flag[2] ? styles.icon : {}]}
/>
<Text style={[styles.buttonText, flag[2] ? {} : styles.hidden]}>
Fast
</Text>
</Animated.View>
</TouchableOpacity>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
titleText: {
fontSize: 25,
color: "#000000",
fontWeight: "bold",
marginLeft: 10,
marginVertical: 5,
},
titleContainer: {
borderBottomColor: "#e3e3e3",
borderBottomWidth: 2,
},
icon: {
marginLeft: 10,
},
textDiv: {},
btnGroupContainer: {
height: 80,
flex: 1,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-around",
backgroundColor: "#889bf2",
},
btnContainer: {
paddingVertical: 10,
justifyContent: "space-around",
},
buttonText: {
textAlign: "center",
color: "#ffffff",
fontSize: 15,
alignSelf: "center",
flex: 1,
},
buttonTextLayer: {
width: 130,
backgroundColor: "#5c69a4",
borderRadius: 50,
flexDirection: "row",
},
hidden: {
width: 0,
height: 0,
},
});
export default SortTitle;
Working example
Link: ----> https://snack.expo.io/#msbot01/aa6537
import React, { Component } from 'react';
import { Text, View, StyleSheet, Image } from 'react-native';
import Constants from 'expo-constants';
import Icon from 'react-native-vector-icons/FontAwesome';
// You can import from local files
import AssetExample from './components/AssetExample';
import AwesomeIcon from 'react-native-vector-icons/FontAwesome';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
import Ripple from 'react-native-material-ripple';
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
tabSelected:1
};
}
onClick(e){
this.setState({
tabSelected:e
})
}
render() {
return (
<View style={{ flex: 1 }}>
<View style={{position:"absolute", bottom:0, height:50,backgroundColor:'white', width:'100%', alignItems:'center', flexDirection:'row', justifyContent:'space-around'}}>
<Ripple style={{height:'100%', width:100, justifyContent:'center', alignItems:'center'}} onPress={()=>{this.onClick(0)}}>
{this.state.tabSelected==0?
<View style={{flexDirection:'row', padding:10, borderRadius:20, alignItems:'center', backgroundColor:'#bffab6', width:'80%', justifyContent:"center", height:'70%'}}>
<Icon name="user" size={15} color="#1fdb02"/>
<Text style={{fontSize:15, paddingLeft:5, color:'#1fdb02'}}>user</Text>
</View>
:
<Icon name="user" size={15} color="#1fdb02"/>
}
</Ripple>
<Ripple style={{height:'100%', width:100, justifyContent:'center', alignItems:'center'}} onPress={()=>{this.onClick(1)}}>
{this.state.tabSelected==1?
<View style={{flexDirection:'row', padding:10, borderRadius:20, alignItems:'center', backgroundColor:'#fce29a', width:'80%', justifyContent:"center", height:'70%'}}>
<Icon name="search" size={15} color="#e6ac02"/>
<Text style={{fontSize:15, paddingLeft:5, color:'#e6ac02'}}>search</Text>
</View>
:
<Icon name="search" size={15} color="#e6ac02"/>
}
</Ripple>
<Ripple style={{height:'100%', width:100, justifyContent:'center', alignItems:'center'}} onPress={()=>{this.onClick(2)}}>
{this.state.tabSelected==2?
<View style={{flexDirection:'row', padding:10, borderRadius:20, alignItems:'center', backgroundColor:'#b6e9fa', width:'80%', justifyContent:"center", height:'70%'}}>
<Icon name="heart" size={15} color="#048dba"/>
<Text style={{fontSize:15, paddingLeft:5, color:'#048dba'}}>like</Text>
</View>
:
<Icon name="heart" size={15} color="#048dba"/>
}
</Ripple>
<Ripple style={{height:'100%', width:100, justifyContent:'center', alignItems:'center'}} onPress={()=>{this.onClick(3)}}>
{this.state.tabSelected==3?
<View style={{flexDirection:'row',padding:10, borderRadius:20, alignItems:'center', backgroundColor:'#f3b8ff', width:'80%', justifyContent:"center", height:'70%'}}>
<Icon name="share" size={15} color="#9c04ba"/>
<Text style={{fontSize:15, paddingLeft:5, color:'#9c04ba'}}>share</Text>
</View>
:
<Icon name="share" size={15} color="#9c04ba"/>
}
</Ripple>
</View>
</View>
);
}
}

react-native position element at the bottom

I am trying to move a react native component called "forum" to the bottom of the screen, I tried position: fixed, bottom:0 but it didn't work
I also tried 'flex-end' and still didn't work
any idea what's wrong?
here is the expo code:
import React from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { DrawerNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold', marginTop: 20 }}>Home</Text>
</View>
);
}
}
class Enquiry extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold', marginTop: 20 }}>Enquiry</Text>
</View>
);
}
}
class Batches extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold', marginTop: 20 }}>Batches</Text>
</View>
);
}
}
class Forum extends React.Component {
render() {
return (
<View style={{ flex:1,justifyContent:'center',alignItems: 'center',position:'absolute',bottom:0}}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DrawerOpen')}>
<Text>Open Drawer</Text>
</TouchableOpacity>
<Text style={{ fontWeight: 'bold',marginBottom:36}}>Forum</Text>
</View>
);
}
}
const MyDrawerNavigator = new DrawerNavigator(
{
Home: HomeScreen,
Batches:Batches,
Enquiry:Enquiry,
Forum:Forum,
},
{
drawerBackgroundColor: 'rgba(255,255,255,.9)',
contentOptions: {
activeTintColor: '#fff',
activeBackgroundColor: '#6b52ae',
},
}
);
export default MyDrawerNavigator;
I am not allowed to share images but click the link to see
enter image description here
The valid position option in react native is relative or absolute. The default value is relative.
If you want scroll content and fix position of Forum in your screen, you have to separate your view hierarchy like the following and use absolute position.
<View>
<ScrollView>
...anything content
</ScrollView>
<Forum style={{position:'absolute', bottom: 0}}/>
</View>
<...>
<MyDrawerNavigator .../>
<Forum style={{position:'absolute', bottom: 0}} .../>
<.../>

React Native error: Super expression must either be null or a function

I get the error when i trie to run this app on my Android Emulator. I changed "Component" to "React.Component" but then i get other Problems.
My versions of React, Node and JS are the newest.
The Problem is that im new and have this Code from a Viedo and he didnt got thet Mistake.
Without React.Component:
With React.Component:
import React from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
StatusBar,
Component,
} from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<StatusBar backgroundColor="#1e90ff" barStyle="light-content" />,
<Text style={styles.login}>Login</Text>,
<TextInput style={styles.input} placeholder="Username" />,
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn}>
<text style={styles.btnText}>Login</text>
</TouchableOpacity>
<TouchableOpacity style={styles.userBtn}>
<text style={styles.btnText}>Text</text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#1e90ff',
},
login: {
textAlign: 'center',
fontSize: 35,
margin: 10,
color: '#fff',
},
input: {
width: '80%',
backgroundColor: '#fff',
padding: 10,
marginBottom: 10,
height: 30,
},
btnContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
width: '90%',
},
userBtn: {
backgroundColor: '#fff',
padding: 15,
width: '40%',
margin: 10,
},
btnText: {
fontSize: 25,
textAlign: 'center',
color: '#1e90ff',
},
});
Can someone help me?
1. TypeError: Super expression must either be null or a function
To fix this
import React, { Component } from 'react';
Then you can use
export default class App extends Component
2. Invariant Violation: Text strings must be rendered within a component
To fix this remove , & change
<text style={styles.btnText}>Login</text>
to
<Text style={styles.btnText}>Login</Text>
EDIT
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<StatusBar backgroundColor="#1e90ff" barStyle="light-content" />
<Text style={styles.login}>Login</Text>
<TextInput style={styles.input} placeholder="Username" />
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn}>
<Text style={styles.btnText}>Login</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.userBtn}>
<Text style={styles.btnText}>Text</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
Hope this helps you. Feel free for doubts.

How to open a facebook, instagram.. (social network) profile from my app

I'm creating an application using react native and I need to allow user to open all the available social networks of another user.
I saw that question and this one, but they doesn't works for me.
can anyone help
EDIT
I know how to create icons and call social networks' website, however, what I want is to open a user profile in a social networks app
I remarked that for instagram, the user profile url, opens the app, howover for Fb, it opens the website,
This following is used in my project. Its the contact US page of my react native app.
Works fine for me.
import React, { Component } from 'react';
import { StyleSheet, Text, Dimensions, View, TouchableNativeFeedback, TouchableOpacity, Image, Linking, ScrollView, Platform } from 'react-native';
import { Icon, Card, CardItem } from 'native-base';
import Colors from '../config/Colors';
import Dimens from '../config/Dimens';
import { RNToasty } from 'react-native-toasty';
import OneSignal from 'react-native-onesignal';
import { getStatusBarHeight } from 'react-native-status-bar-height';
import { colors } from 'react-native-elements';
import { Header } from 'react-navigation';
import HeaderBackground from '../components/HeaderBackground';
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;
class SocialMedia extends Component {
constructor(props) {
super(props);
}
static navigationOptions = ({ navigation }) => {
return {
header: (props) => <HeaderBackground {...props} />,
headerStyle: {
backgroundColor: Colors.transparent,
paddingTop: Platform.OS === 'ios' ? 0 : getStatusBarHeight(),
height: Header.HEIGHT + (Platform.OS === 'ios' ? 0 : getStatusBarHeight()),
},
title: 'Social Media',
headerTintColor: Colors.white,
headerTitleStyle: {
fontWeight: 'bold',
padding: 5,
paddingTop: 10
},
headerMode: 'float',
headerLeft: <Icon
onPress={() => navigation.goBack()}
name="arrow-back"
type='MaterialIcons'
style={{ color: 'white', marginLeft: 10, padding: 5, paddingTop: 10 }}
/>,
}
}
render() {
return (
<View style={styles.container}>
<View style={styles.cardContainer}>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://www.facebook.com/max/') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_Facebook.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>Facebook</Text>
</CardItem>
</Card>
</TouchableOpacity>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://www.instagram.com/max/') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_Insta.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>Instagram</Text>
</CardItem>
</Card>
</TouchableOpacity>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://www.youtube.com/channel/UCnQoipGmBRC1XTOUY8c1UdA') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_YT.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>YouTube</Text>
</CardItem>
</Card>
</TouchableOpacity>
<TouchableOpacity background={TouchableNativeFeedback.Ripple(Colors.secondaryColor, false)} onPress={() => { Linking.openURL('https://max.com/') }}>
<Card style={styles.card}>
<CardItem style={styles.cardBody}>
<Image source={require('../assets/icons/Contact_web.jpg')} style={styles.icon} resizeMode='contain' />
<Text style={styles.iconText}>Website</Text>
</CardItem>
</Card>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 8
},
contentContainer: {
paddingBottom: 20
},
cardContainer: {
flex: 1,
padding: 5,
width: '100%',
},
card: {
padding: 5,
height: height * .20,
width: '100%',
backgroundColor: '#fff',
flexDirection: 'column',
//alignItems: 'center',
//justifyContent: 'center',
shadowColor: '#1A9EAEFF',
shadowOffset: { width: 3, height: 3 },
shadowOpacity: 3,
shadowRadius: 2,
elevation: 10,
borderRadius: 5,
overflow: 'hidden'
},
cardBody: {
flex: 1,
flexDirection: 'row',
},
iconText: {
flex: 1,
fontWeight: 'bold',
alignItems: 'center',
justifyContent: 'center',
fontSize: 18,
color: '#1A9EAEFF'
},
icon: {
flex: 1,
width: '100%',
height: width * .18,
},
});
export default SocialMedia;
Hope this helps..
You're good to go!!
For instagram this is working for me,
Linking.openURL('https://www.instagram.com/profile_username/');
for facebook its just opening the facebook app.
Linking.openURL('fb://profile_username/');

child component overflow from parent component

import React, {Component} from 'react';
import {Modal, Text, TouchableHighlight, View, Alert} from 'react-native';
export default class AlertModal extends Component {
constructor(props){
super(props)
this.state={
check:'234',
primaryColor:'#dcdcdc',
secondaryColor:'#ff1493',
fontFamily:'sans-serif',
one:'Alert',
two:'sample text'
}
}
state = {
modalVisible: false,
};
setModalVisible(visible) {
this.setState({modalVisible: visible});
}
render() {
return (
<Modal
animationType="slide"
transparent={false}
visible={this.state.modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
<View
style={{
top:'39%',
backgroundColor:this.state.primaryColor,
height:'25%',
width:'70%',
alignSelf:'center'
}}>
<Text
style={{
fontWeight:'500',
fontFamily:this.state.fontFamily,
alignSelf:'center',
fontSize:30,
color:this.state.secondaryColor
}}>
{this.state.one}
</Text>
<View
style={{
borderBottomColor: 'black',
borderBottomWidth: 1,
top:'3%'
}}
/>
<Text
style={{
fontFamily:this.state.fontFamily,
alignSelf:'center',
color:this.state.secondaryColor,
top:'100%'
}}>
{this.state.two}
</Text>
</View>
</Modal>
);
}
}
I am trying to create a new Modal, when I try position last text element 'sample two' in modal component within View, I am failing. 'sample two' is displayed outside of view. I will post the screenshot of what I am getting
but I the need the sample text to be within the end of the box, I don't know why it is displayed outside of the box.
Just wrap it inside another view as shown below.
render() {
return (
<Modal
animationType="slide"
transparent={false}
visible={!this.state.modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
<View
style={{
top: '39%',
backgroundColor: this.state.primaryColor,
height: '25%',
width: '70%',
alignSelf: 'center',
borderWidth: 1,
borderColor: 'red',
}}>
<Text
style={{
fontWeight: '500',
fontFamily: this.state.fontFamily,
alignSelf: 'center',
fontSize: 30,
color: this.state.secondaryColor,
}}>
{this.state.one}
</Text>
<View
style={{
borderBottomColor: 'black',
borderBottomWidth: 1,
top: '3%',
}}
/>
<View>
<Text
style={{
fontFamily: this.state.fontFamily,
alignSelf: 'center',
color: this.state.secondaryColor,
top: '100%',
}}>
{this.state.two}
</Text>
</View>
</View>
</Modal>
);
}
top: '100%', is moving the Text out, change it to 50%
<Text
style={{
fontFamily: this.state.fontFamily,
alignSelf: 'center',
color: this.state.secondaryColor,
top: '50%',
}}>
{this.state.two}
</Text>