import React from 'react'
import { View, StyleSheet, Text, TouchableOpacity, Modal } from 'react-native'
const ModalContent = ({ visiblity, toggleModal }) => {
return (
<Modal animationType='slide' transparent={true} visible={visiblity} onRequestClose={() => {
toggleModal()
}} >
<View style={styles.container}>
<TouchableOpacity>
<Text style={styles.textButton}>Edit</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.textButton}>Invite</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.textButton}>Delete</Text>
</TouchableOpacity>
</View>
</Modal>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
borderTopRightRadius: 25,
borderTopLeftRadius: 25,
height: 150,
alignItems: 'center',
elevation: 10,
alignItems: 'flex-start',
justifyContent: 'space-around',
paddingLeft: 20,
marginTop: 420
},
textButton: {
fontSize: 13,
color: 'black',
}
})
export default ModalContent
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
import React from 'react'
import { View, StyleSheet, Text, TouchableOpacity, Modal } from 'react-native'
const ModalContent = ({ visiblity, toggleModal }) => {
return (
<Modal animationType='slide' transparent={true} visible={visiblity} onRequestClose={() => {
toggleModal()
}} >
<View style={styles.container}>
<TouchableOpacity>
<Text style={styles.textButton}>Edit</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.textButton}>Invite</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.textButton}>Delete</Text>
</TouchableOpacity>
</View>
</Modal>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
borderTopRightRadius: 25,
borderTopLeftRadius: 25,
height: 150,
alignItems: 'center',
elevation: 10,
alignItems: 'flex-start',
justifyContent: 'space-around',
paddingLeft: 20,
marginTop: 420
},
textButton: {
fontSize: 13,
color: 'black',
}
})
export default ModalContent
just simply adding backgroundcolor with opacity>>>>
backgroundColor: rgba(255, 0, 0, 0.2);
because in modal there is view contains view so if you give background color to that conatining view it will added blacky effect
In case you are using expo use
import { BlurView } from 'expo-blur';
When I added a blurView to my project, I browsed around for some third party libs and ended up with adding react-native-unimodules.
https://www.npmjs.com/package/#react-native-community/blur
you can use blurview so you can trigger blur when the bottomsheet opens or else make it normal
.
.
.
.
const [opensheet,setopensheet]=useState(false)
const [blur,setblur]=useState(0)
const ViewRef=useRef()
useEffect(
()=>
{
const changeBlur=()=>
{
if(opensheet)
setblur(25)
else
setblur(0)
}
changeBlur()
},
[opensheet]
)
.
.
.
return
(
<BlurView
ref={ViewRef}
blurAmount={blur}
>
.
.
.
)
--here opensheet is state of your modal which is defined by bool open/true and close/false
you have multiple way to solve this
one is using this library
https://github.com/Kureev/react-native-blur
one is with image with opacity blurradius
<Image
style={{opacity:0.8}
resizeMode='cover'
source={path}
blurRadius={1}
/>
another approach would to drop shadow with transparent background
i would go with first option becuase i already tried it
Related
I am trying to acheive a styling as shown in the image attached below
See how here the fingerprint icon happens to be inside the border of the Textinput field but instead I am getting the output as shown below
PS:- ignore the left and right side black color borders it happens to be the simulator body just focus on the UI.
Here's my code :-
import { View, Text, TextInput, StyleSheet } from 'react-native'
import React from 'react'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
const TestAtom = () => {
return (
<View style={styles.searchSection}>
<TextInput style={styles.input} placeholder='User' onChangeText={(searchString) => {this.setState({searchString})}}
underlineColorAndroid="transparent"/>
<Icon style={styles.searchIcon} name='fingerprint' size={20} color= '#000' />
</View>
)
}
const styles = StyleSheet.create({
searchSection: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
searchIcon: {
// padding: 10
paddingRight: 10
},
input: {
flex: 1,
paddingTop: 10,
paddingRight: 10,
paddingBottom: 10,
paddingLeft: 0,
backgroundColor: '#fff',
color: '#424242',
borderBottomColor: '#000',
borderBottomWidth: 1
}
});
export default TestAtom
Can anyone help me with it.
You should make a View and place the Text Input and Fingerprint icon inside.
A small example of how it will look like.
<View style={{
borderWidth:1,
flex:1,
flexDirection:'row',
alignItems:'center'
}}>
<TextInput/>
<FingerIcon/>
</View>
Have the Textinput and the fingerprint icon as two components in the same view styled as flex-direction:row. Have the bottom ruler part as a separate item which draws under the View of Textinput and the Icon.
import { View, StyleSheet,SafeAreaView,TextInput } from 'react-native'
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
function UIComponent(){
<View style={styles.container}>
<View style={styles.componentWrapper}>
<View style={styles.passwordFieldWrapper}>
<TextInput style={styles.textInput} placeholder='umana Password'>
</TextInput>
<MaterialCommunityIcons name="fingerprint" color='green' size={24} />
</View>
<View style={styles.bottomPart}>
</View>
</View>
</View>
}
export default UIComponent
const styles = StyleSheet.create({
container:{
backgroundColor:'#ffffff',
flex:1
},
componentWrapper:{
alignItems:'center',
justifyContent:'center'
},
passwordFieldWrapper:{
flexDirection:'row'
},
textInput:{
width:'50%'
},
bottomPart:{
marginTop:3,
borderBottomColor:'gray',
borderBottomWidth:1,
width:'60%'
}
})
I am using the React Native Modal, I want the background of the Modal
to be transparent and I want the Modal display to behalf of the
screen
How to achieve the same requirement, where I am going wrong?
Below is the code for the same, please have a look at this:
import React, { Component } from 'react'
import { Modal, View, Text, Dimensions, Platform, TouchableOpacity, Alert, StyleSheet, Button } from 'react-native'
import Icon from 'react-native-vector-icons/Entypo'
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
export class MyComponent extends Component {
render = () => {
const message = 'Do you want to upload the video now or wait until you are connected to wi-fi?'
return (
<Modal
animationType='slide'
transparent={true}
style={{backgroundColor: 'black'}}
>
<View style={styles.content}>
<View style={styles.closeBtn}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('PreInspection_VideoPlayer')} style={styles.closeBtn}>
<Icon name="cross" color="#000" size={26} />
</TouchableOpacity>
</View>
<Text style={{
fontSize: 18,
fontFamily: 'Montserrat-Bold',
paddingTop: Platform.OS === 'android' ? 40 : 20,
paddingVertical: 10
}}>Warning! 🚨</Text>
<View style={{ paddingHorizontal: 40 }}>
<Text style={{ fontSize: 18, justifyContent: 'center', alignItems: 'center', textAlign: 'center' }}>{message}</Text>
</View>
<Button
title='Upload My Video'
style={styles.bigButtons}
onPress={() => { Alert.alert('Uploading Video') }}
/>
<Button
title='Upload Video Later'
style={styles.bigButtons}
onPress={() => { Alert.alert('Uploading Video Later') }}
/>
</View>
</Modal>
)
}
}
const styles = StyleSheet.create({
closeBtn: {
padding: 10
},
bigButtons: {
width: 240,
marginTop: 20
},
content: {
backgroundColor: 'red',
width: windowWidth * 0.8,
height: windowHeight * 0.7,
alignSelf: 'center',
top: windowHeight * 0.15,
borderRadius: windowHeight * 0.03,
alignItems: 'center',
justifyContent: 'center'
},
})
Any help would be appreciated. Thanks in advance :)
You can achieve this easily with React Native Community Modal
Here is an example:
import React, { useState } from "react";
import { Text, View, Dimensions } from "react-native";
import Modal from "react-native-modal";
const { width: ScreenWidth, height: ScreenHeight } = Dimensions.get("window");
const ModalExample = props => {
const [visibility, setVisibility] = useState(true);
return (
<View>
<Modal
backdropColor="transparent"
isVisible={visibility}
style={{
alignItems: "center",
justifyContent: "center"
}}
onBackdropPress={() => setVisibility(false)}
>
<View
style={{
borderRadius: 16,
alignItems: "center",
justifyContent: "center",
width: ScreenWidth * 0.7,
backgroundColor: "#fdfdfd",
height: ScreenHeight * 0.5
}}
>
<Text>I am the modal content!</Text>
</View>
</Modal>
</View>
);
};
export default ModalExample;
I'm currently doing an example of a Model View with a label and a ScrollView below it. However, in the ScrollView's style when I set with no flex it goes over the parent element.
https://i.imgur.com/VGZ6vll.png
While if I set flex: 1 to the ScrollView style, the content does not show on the screen.
https://i.imgur.com/9e00ydF.png
Here is my code:
App.js:
import React, { Component } from "react";
import { Text, TouchableOpacity, View } from "react-native";
import Modal from "react-native-modal";
import ModalContent from './src/ModalContent';
export default class ModalTester extends Component {
state = {
isModalVisible: false
};
_toggleModal = () =>
this.setState({ isModalVisible: !this.state.isModalVisible });
render() {
return (
<View style={{ flex: 1 }}>
<TouchableOpacity onPress={this._toggleModal}>
<Text>Show Modal</Text>
</TouchableOpacity>
<Modal
isVisible={this.state.isModalVisible}
onBackdropPress={() => this.setState({ isModalVisible: false })}
>
<View style={styles.modalStyle}>
<ModalContent />
</View>
</Modal>
</View>
);
}
}
const styles = {
modalStyle: {
flex: 1,
marginTop: 20,
marginBottom: 20,
marginLeft: 10,
marginRight: 10,
backgroundColor: "#fff",
}
}
ModalContent.js:
import React from 'react';
import { View, Text, ScrollView } from 'react-native';
import InfoBox from './InfoBox'
export default () => {
return (
<View styles={styles.containerStyle}>
<Text style={styles.headerStyle}>TRIP INFO</Text>
<ScrollView style={styles.scrollViewStyle}>
<InfoBox boxHeight={100} />
<InfoBox boxHeight={200} />
<InfoBox boxHeight={400} />
</ScrollView>
</View>
);
}
const styles = {
containerStyle: {
flex: 1,
marginTop: 20,
marginBottom: 20,
marginLeft: 10,
marginRight: 10,
backgroundColor: "#fff",
},
headerStyle: {
fontSize: 35,
fontFamily: 'OpenSans',
fontWeight: 'bold',
color: '#be5bc2',
marginTop: 10,
marginLeft: 10,
},
scrollViewStyle: {
marginTop: 10,
}
}
InfoBox.js:
import React from 'react';
import { View, Text } from 'react-native';
export default ({boxHeight}) => {
setContainerStyle = function(setHeight) {
return ({
borderWidth: 1,
borderRadius: 4,
borderColor: "#000",
height: setHeight,
marginTop: 25,
marginLeft: 20,
marginRight: 20,
});
}
return (
<View style={this.setContainerStyle(boxHeight)}>
<Text>Hello</Text>
</View>
);
};
I have the same issue and change style for contentContainerStyle in ScrollView and works for me.
It would look like this:
<ScrollView contentContainerStyle={{ marginTop: 10 }} />
How to show two views per rows in scollview in React native?
It is difficult to change the large framework since I made a view by pulling the json with module.
I would like to show views in the scrollview in the form shown below.
enter image description here <-- image link
I’d be glad if you could help me.
** If it have no idea in current method, you can give me a new idea.
this is code (const styles skipped)
import React, { Component } from 'react';
import { StyleSheet, View, Text, Image, StatusBar, FlatList, ScrollView, TouchableOpacity, Button, Dimensions } from 'react-native';
import logoImg from '../../images/logo.png';
import SearchInput, { createFilter } from 'react-native-search-filter';
import Icon from 'react-native-vector-icons/FontAwesome';
import Icon2 from 'react-native-vector-icons/Feather';
import promotion_list from '../../data/market_list.js';
const KEYS_TO_FILTERS = ['name', 'subject'];
const myIcon = (<Icon name="times" size={25} color='#949494' />)
export default class Market extends React.Component {
constructor(props) {
super(props);
this.state = {
searchTerm: ''
}
}
searchUpdated(term) {
this.setState({ searchTerm: term })
}
render() {
const filteredlists = promotion_list.filter(createFilter(this.state.searchTerm, KEYS_TO_FILTERS))
return (
<View style={styles.SearchList}>
<View style={{ flexDirection: 'row', margin: 10, padding: 10, height: 40, borderRadius: 100, backgroundColor: '#f5f5f5' }}>
<Icon name="search" size={20} color='#949494' style={{ flex: 0, marginRight: 10 }} />
<SearchInput
clearIcon={myIcon}
clearIconViewStyles={{ position: 'absolute', right: 6 }}
onChangeText={(term) => { this.searchUpdated(term) }}
placeholder="Search"
inputViewStyles={{ flex: 1 }}
/>
</View>
<View style={{justifyContent: 'center', alignItems: 'center'}}>
<Image style={{width:390, height:180}} source={require("../../images/market/topview.png")} />
</View>
<View>
<Text style={{marginLeft:15, marginTop:10, marginBottom:10, fontWeight:'bold', fontSize:20, color: '#494a51'}}>Your Partners</Text>
</View>
<ScrollView style={styles.ScrollView}>
{filteredlists.map(plist => {
function getImage(img_name) {
switch (img_name) {
case "1.png": return require("../../images/par_logo/1.png");
case "2.png": return require("../../images/par_logo/2.png");
case "3.png": return require("../../images/par_logo/3.png");
case "4.png": return require("../../images/par_logo/4.png");
case "5.png": return require("../../images/par_logo/5.png");
case "6.png": return require("../../images/par_logo/6.png");
case "7.png": return require("../../images/par_logo/7.png");
case "p1.png": return require("../../images/promotion_feed/1.png");
case "p2.png": return require("../../images/promotion_feed/2.png");
case "p3.png": return require("../../images/promotion_feed/3.png");
case "p4.png": return require("../../images/promotion_feed/4.png");
case "p5.png": return require("../../images/promotion_feed/5.png");
}
}
return (
<TouchableOpacity activeOpacity={1} key={plist.id} style={styles.ListItem}>
<View style={{ paddingRight: 10, paddingLeft: 10, height: 50, flexDirection: 'row', alignItems: 'center' }}>
<Image style={{ marginRight: 10, width: 30, height: 30, resizeMode: Image.resizeMode.contain }} source={getImage(plist.src1)} />
<Text style={{ fontWeight: 'bold' }}>{plist.name}</Text>
</View>
<View style={{margin:0}}>
<TouchableOpacity onPress={() => { alert("you clicked me") }}>
<Image style={{}} source={getImage(plist.src2)} />
</TouchableOpacity>
</View>
</TouchableOpacity>
)
})}
</ScrollView>
</View>
)
}
}
One possible solution is to use a FlatList which is inherited from ScrollView and use the numColumns prop. FlatList
I'm pretty new to ReactNative world. Im struggling to find an api or a library that shows the Progress Dialog as below in React Native. I believe ActivityIndicator can be used, but it does not show as overlay. Can anyone help me how can I show as an overlay using styles or if there is good library to make this.
Thanks
Here is the code to Open Prgressbar:
import React from 'react';
import { Modal, View, Text, ActivityIndicator, Button } from 'react-native';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = { isProgress: false }
}
openProgressbar = () => {
this.setState({ isProgress: true })
}
render() {
return (
this.state.isProgress ?
<CustomProgressBar />
:
<View style={{ flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center' }}>
<Button title="Please click here to Open ProgressBar" onPress={this.openProgressbar} />
</View>
);
}
}
const CustomProgressBar = ({ visible }) => (
<Modal onRequestClose={() => null} visible={visible}>
<View style={{ flex: 1, backgroundColor: '#dcdcdc', alignItems: 'center', justifyContent: 'center' }}>
<View style={{ borderRadius: 10, backgroundColor: 'white', padding: 25 }}>
<Text style={{ fontSize: 20, fontWeight: '200' }}>Loading</Text>
<ActivityIndicator size="large" />
</View>
</View>
</Modal>
);
Expo url for live demo
https://snack.expo.io/#jitendra.mca13/progress-bar-demo
I would approach this by using the React Native Modal component with two Views.
This solution is a React solution and not native, so you will need to style your Modal accordingly for each platform.
import React from 'react';
import {
Modal,
View,
StyleSheet,
Text,
ActivityIndicator
} from 'react-native';
const ProgressDialog = ({ visible }) => (
<Modal
visible={visible}
>
<View style={styles.container}>
<View style={styles.content}>
<Text style={styles.title}>Please Wait</Text>
<View style={styles.loading}>
<View style={styles.loader}>
<ActivityIndicator size="large" />
</View>
<View style={styles.loadingContent}>
<Text>Loading</Text>
</View>
</View>
</View>
</View>
</Modal>
);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, .5)',
alignItems: 'center',
justifyContent: 'center',
},
content: {
padding: 35,
backgroundColor: 'white'
},
title: {
fontSize: 18,
fontWeight: 'bold',
},
loading: {
flexDirection: 'row',
alignItems: 'center',
},
loader: {
flex: 1,
},
loadingContent: {
flex: 3,
fontSize: 16,
paddingHorizontal: 10,
}
})
export default ProgressDialog;
Here's a demo on Expo, of course you will probably want to tweak the CSS.
Android & iOS solution
Create a directory called ProgressDialog
Create index.ios.js and index.android.js
Paste the above code into both index.ios.js and index.android.js
Make CSS changes for iOS
You can use the below npm package which is a very easy and attractive loader with many options.
https://github.com/maxs15/react-native-spinkit
import React from 'react';
import { StyleSheet, View } from "react-native";
import Spinner from "react-native-spinkit";
export default LoadingCmpBig = props => {
return (
<View style={styles.container}>
<StatusBar barStyle="default" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
//backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
}
});
You can use this component and use it where you want to show the Progress. You just have to maintain the state for visible the loading or not in your render function of the component.