Need help in react native in text section - html

'My question is about react native'
'I am trying to changing the color and fontsize Hello, world and Hello but its not changing,the code running fine.'
'''
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<Text style={[styles.Red,styles.One]}>Praveen</Text>
<Text Style={[styles.White,styles.Two]}>
Hello, World
</Text>
<Text H1>Hello</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FFFFFF',
alignItems: 'center',
justifyContent: 'center',
},
Red: {
color: '#F44336'
},
One: {
fontSize : 80
},
White: {
color : '#F44336'
},
Two: {
fontSize : 80
},
});
'''

You wrote Style with a capital s instead of style, props are case sensitive so make sure that you're using the right naming
Code should look like this:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<Text style={[styles.Red,styles.One]}>Praveen</Text>
<Text style={[styles.White,styles.Two]}>
Hello, World
</Text>
<Text H1>Hello</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FFFFFF',
alignItems: 'center',
justifyContent: 'center',
},
Red: {
color: '#F44336'
},
One: {
fontSize : 80
},
White: {
color : '#F44336'
},
Two: {
fontSize : 80
},
});

Related

How to mute remote user in Agora UI kit?

I am using AgoraUIKit from "agora-react-uikit". it is supposed to have the option to mute remote users as per their documentation, but it is not there as they showed in their demo example.
Here is the github link for controls panal which is supposed to be there by default.
https://github.com/AgoraIO-Community/VideoUIKit-Web-React/wiki/Guide#controls
Here is a code of the App.tsx file
import React, { CSSProperties, useState } from 'react'
import AgoraUIKit, { layout, VideoPlaceholderProps, BtnTemplate } from 'agora-react-uikit'
import 'agora-react-uikit/dist/index.css'
const PageComponent: React.FunctionComponent<VideoPlaceholderProps> = ({isShown=true, showButtons=true, showSwap=false}) => {
return (
<>
{showButtons}{isShown}{showSwap}
{BtnTemplate}
</>
);
};
const App: React.FunctionComponent = () => {
const [videocall, setVideocall] = useState(false)
const [isHost, setHost] = useState(true)
const [isPinned, setPinned] = useState(false)
const [username, setUsername] = useState('')
return (
<div style={styles.container}>
<div style={styles.videoContainer}>
{videocall ? (
<>
<div style={styles.nav2}>
<h3 style={styles.heading}>Online Video Call</h3>
<p style={styles.btn} onClick={() => setPinned(!isPinned)}>
Change Layout
</p>
</div>
<AgoraUIKit
rtcProps={{
appId: 'appid',
channel: 'channel name',
uid: 0,
token: 'token', // add your token if using app in secured mode
role: isHost ? 'host' : 'audience',
layout: isPinned ? layout.pin : layout.grid,
activeSpeaker: true,
disableRtm: false,
enableScreensharing: true,
CustomVideoPlaceholder: PageComponent,
}}
rtmProps={{
username: username || 'user',
displayUsername: true,
showPopUpBeforeRemoteMute: true
}}
callbacks={{
EndCall: () => setVideocall(false)
}}
styleProps={{
localBtnContainer: { backgroundColor: 'white', justifyContent: 'center', gap: "20px" },
> BtnTemplateStyles: { borderColor: 'rgb(107 107 107)' },
}}
/>
</>
) : (
<div style={styles.nav}>
<input
style={styles.input}
placeholder='nickname'
type='text'
value={username}
onChange={(e) => {
setUsername(e.target.value)
}}
/>
<h3 style={styles.btn} onClick={() => setVideocall(true)}>
Start Call
</h3>
</div>
)}
</div>
</div>
)
}
const styles = {
container: {
maxWidth: '1100px',
margin: "0 auto",
height: '100vh',
display: 'flex',
flex: 1,
},
container2: {
padding: "2px 16px"
},
heading: { textAlign: 'center' as const, marginBottom: 0 },
videoContainer: {
display: 'flex',
flexDirection: 'column',
flex: 1
} as CSSProperties,
nav: { display: 'flex', justifyContent: 'space-between' },
nav2: { display: 'flex', justifyContent: 'space-between', borderBottom: "1px solid black" },
card: {
// position:"absolute",
// left:"0",
// bottom:"0",
// transform:"translate(155px, -82px)",
// boxShadow: '0 4px 8px 0 rgba(0,0,0,0.2)',
// transition: '0.3s',
// display: 'flex',
// width:"80vw",
// height:"80vh",
// flexDirection: "column",
// justifyContent: "space-between"
} as CSSProperties,
btn: {
backgroundColor: '#007bff',
cursor: 'pointer',
borderRadius: 5,
padding: '4px 8px',
color: '#ffffff',
fontSize: 20
},
input: { display: 'flex', height: 24, alignSelf: 'center' } as CSSProperties
}
export default Apptype here

Material-UI NextJS Button Styling Issue

i am having a problem getting the styling right on a couple of buttons in JS, it seems when i add a styling class via className that on first render the formatting works, but on subsequent refreshes it loses its styling. It is only happening on the two individual buttons i have. After troubleshooting for ages, i have found that everything works when i use SX instead of classNames, so if i do this then the refresh works. So in code below one button styles and remains styles, but the second one, refreshing my button class does not? Stumped at this point, i ran through forums and see a lot about NextJs needing some extra config in _document and _app to make it work, but i ran this in from the NextJs Material UI boiler plate from Git so dont think it could be that causing it.
Code:
import React from 'react'
import { AppBar, Toolbar, alpha } from "#mui/material";
import Button from '#mui/material/Button'
import ButtonBase from '#mui/material/ButtonBase';
import { styled } from '#mui/material/styles';
import Typography from '#mui/material/Typography';
import InputBase from '#mui/material/InputBase';
import SearchIcon from '#mui/icons-material/Search';
import AddIcon from '#mui/icons-material/Add';
import { makeStyles } from '#mui/styles'
const useStyles = makeStyles(theme => ({
button: {
...theme.typography.mainmenu,
borderRadius: "40px",
width: "230px",
height: "130px",
marginLeft: "30px",
alignItem: "center",
"&:hover": {
backgroundColor: theme.palette.secondary
},
[theme.breakpoints.down("sm")]: {
width: '100% !important', // Overrides inline-style
height: 100
},
},
}))
/*Image Button Styling Begins*/
const images = [
{
url: '/assets/breakfastMenu.jpg',
title: 'Breakfast',
width: '20%',
},
{
url: '/assets/steak.jpg',
title: 'Mains',
width: '20%',
},
{
url: '/assets/desserts.jpg',
title: 'Desserts',
width: '20%',
},
];
const Image = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
color: theme.palette.common.primary,
}));
const ImageButton = styled(ButtonBase)(({ theme }) => ({
position: 'relative',
height: 150,
[theme.breakpoints.down('sm')]: {
width: '100% !important', // Overrides inline-style
height: 100,
},
'&:hover, &.Mui-focusVisible': {
zIndex: 1,
'& .MuiImageBackdrop-root': {
opacity: 0.15,
},
'& .MuiImageMarked-root': {
opacity: 0,
},
'& .MuiTypography-root': {
border: '4px solid currentColor',
},
},
}));
const ImageSrc = styled('span')({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundSize: 'cover',
backgroundPosition: 'center 40%',
});
const ImageBackdrop = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: theme.palette.common.black,
opacity: 0.4,
transition: theme.transitions.create('opacity'),
}));
const ImageMarked = styled('span')(({ theme }) => ({
height: 3,
width: 18,
backgroundColor: theme.palette.common.white,
position: 'absolute',
bottom: -2,
left: 'calc(50% - 9px)',
transition: theme.transitions.create('opacity'),
}));
/*Image Button Styling Ends*/
const Search = styled('div')(({ theme }) => ({
position: 'relative',
borderRadius: theme.shape.borderRadius,
backgroundColor: alpha(theme.palette.common.white, 0.15),
'&:hover': {
backgroundColor: alpha(theme.palette.common.white, 0.25),
},
marginLeft: 0,
width: '100%',
[theme.breakpoints.up('sm')]: {
marginLeft: theme.spacing(1),
width: 'auto',
},
}));
const SearchIconWrapper = styled('div')(({ theme }) => ({
padding: theme.spacing(0, 2),
height: '100%',
position: 'absolute',
pointerEvents: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}));
const StyledInputBase = styled(InputBase)(({ theme }) => ({
color: 'inherit',
'& .MuiInputBase-input': {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
transition: theme.transitions.create('width'),
width: '100%',
[theme.breakpoints.up('sm')]: {
width: '12ch',
'&:focus': {
width: '20ch',
},
},
},
}));
const Header = () => {
const classes = useStyles();
return (<React.Fragment>
<AppBar position="sticky" className={classes.appBar}>
<Toolbar disableGutters>
{images.map((image) => (
<ImageButton
focusRipple
key={image.title}
style={{
width: image.width,
}}
>
<ImageSrc style={{
backgroundImage: `url(${image.url})`
}} />
<ImageBackdrop className="MuiImageBackdrop-root" />
<Image>
<Typography
component="span"
variant="subtitle1"
color="white"
fontWeight="bold"
sx={{
position: 'relative',
p: "7em",
pt: "2em",
pb: (theme) => `calc(${theme.spacing(1)} + 6px)`,
}}
>
{image.title}
<ImageMarked className="MuiImageMarked-root" />
</Typography>
</Image>
</ImageButton>
))}
<Button size="large" variant="contained" color="secondary"
startIcon={<AddIcon />}
sx={{
borderRadius: "40px", borderRadius: "40px",
width: "230px",
height: "130px",
marginLeft: "30px",
alignItem: "center",
}} >Add A recipe</Button>
<Button size="large" variant="contained" color="secondary" className={classes.button}>Meals for the Week</Button>
<Search>
<SearchIconWrapper>
<SearchIcon />
</SearchIconWrapper>
<StyledInputBase
placeholder="Search…"
inputProps={{ 'aria-label': 'search' }}
/>
</Search>
</Toolbar>
</AppBar>
</React.Fragment >
)
}
export default Header
Exactly, you need to add some configuration to the _document.tsx in order to make the styles work properly with the NextJS server side rendering feature. The reason behind this is that you need that some styles are injected in the DOM for you.
As you can see in the MUI docs, you can use the ServerStyleSheets to handle the server side rendering properly.
This is the code I have in my _document.tsx
import React from 'react';
import Document, { Html, Main, NextScript } from 'next/document';
import { ServerStyleSheets } from '#mui/styles';
export default class MyDocument extends Document {
render() {
return (
<Html>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
MyDocument.getInitialProps = async (ctx) => {
// Render app and page and get the context of the page with collected side effects.
const sheets = new ServerStyleSheets();
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => sheets.collect(<App {...props} />)
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
// Styles fragment is rendered after the app and page rendering finish.
styles: [...React.Children.toArray(initialProps.styles), sheets.getStyleElement()]
};
};
You can read more information about this in these Server rendering - MUI docs

How to change the map If location Pickup and DrofOff given in textinputs (React Native)

I am creating a simple car booking app where I have implemented react native MapView in a container and above I have also given 2 TextInputs where user can input the Pickup location and the drop off location.
Screenshot of MapView and TextInputs
If a user inputs the pickup location and a drop-off location I want TextInputs to show some suggestions in a ListView about the location which user inputs and when both inputs are given I want the below map to change with 2 markets from pickup to drop off location.
SearchScreen.js
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, TextInput } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import EntypoIcon from 'react-native-vector-icons/Entypo';
import MapView from 'react-native-maps';
const LATITUDE = 24.860735;
const LONGITUDE = 67.001137;
const LATITUDE_DELTA = 1;
const LONGITUDE_DELTA = 1;
export default class SearchRoutes extends React.Component {
constructor(props) {
super(props);
this.state = {
region: {
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}
}
}
static navigationOptions = {
headerTitle: 'Search Routes',
headerTintColor: '#fff',
headerRight: (<TouchableOpacity />),
headerTitleStyle: {
flex: 1,
padding: 0,
color: '#fff',
alignItems: 'center',
textAlign: 'center',
fontWeight: 'normal',
},
headerStyle: {
backgroundColor: '#b5259e',
},
}
render() {
return (
<View style={styles.container}>
<View style={styles.inputContainer} >
<View style={{ flexDirection: 'row' }}>
<EntypoIcon name="dots-three-vertical" size={30} color='#fff' style={{ paddingTop: 12 }} />
<TextInput style={styles.pickUpInput} underlineColorAndroid="transparent" placeholder='Enter Your pickup location' />
</View>
<View style={{ flexDirection: 'row' }}>
<EntypoIcon name="dots-three-vertical" size={30} color='#fff' style={{ paddingTop: 12 }} />
<TextInput style={styles.pickUpInput} underlineColorAndroid="transparent" placeholder='Enter Your dropoff location' />
</View>
</View>
<View>
<MapView
style={styles.maps}
showsUserLocation={true}
region={this.state.region}>
<MapView.Marker coordinate={this.state.region} />
</MapView>
</View>
<View style={styles.footer} />
<TouchableOpacity style={styles.btnFooter} onPress={() => { this.props.navigation.navigate('RoutesStack') }}>
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'center', }}>
<Icon style={styles.iconFooter} name="search" />
<Text style={styles.footerText}>SEARCH</Text>
</View>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
inputContainer: {
height: 130,
flexDirection: 'column',
width: '100%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#b5259e',
},
pickUpInput: {
padding: 8,
width: '80%',
margin: 4,
backgroundColor: '#d27cc4',
borderRadius: 4,
},
maps: {
width: '100%',
height: '100%',
},
footer: {
flex: 3,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
},
btnFooter: {
backgroundColor: '#b5259e',
padding: 15,
alignItems: 'center',
justifyContent: 'center',
width: '100%',
},
footerText: {
fontSize: 14,
fontWeight: 'normal',
color: 'white',
},
iconFooter: {
display: 'flex',
fontSize: 20,
marginRight: 10,
color: 'white',
alignItems: 'center',
justifyContent: "center",
},
});
Can anyone please help me with that, I am stuck with this from last couple of days I have also tried doing like this ( https://github.com/FaridSafi/react-native-google-places-autocomplete ) but failed. Thanks.

ReactNativeDisplay Json file in another format

rookie in RN, thanks in advance! I want to display a json file on a page.
This is the format of the json:
{
"prediction": [
{ "name":"egg", "value":"0.95" },
{ "name":"apple", "value":"0.02" },
{ "name":"peach", "value":"0.01" },
{ "name":"orange", "value":"0.01" },
{ "name":"fish", "value":"0.01" }
]
}
Assuming the Name of the json will be " /app/prediction.json ".
And the text input method I had on this page will be :
import { Tile, List, ListItem, Button } from 'react-native-elements';
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Dimensions,
View
} from 'react-native';
export default class ProjectOne extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.text}> Analysis </Text>
<Text> The object has " 95% possibility to be an egg, 40% to be an apple "</Text>
</View>
);
}
}
const styles = StyleSheet.create({
text: {
fontSize: 20,
fontWeight: 'bold',
},
container: {
height: 275,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
height: Dimensions.get('window').height,
width: Dimensions.get('window').width
},
capture: {
flex: 0,
backgroundColor: 'black',
borderRadius: 5,
color: '#ffffff',
padding: 10,
margin: 40
}
});
AppRegistry.registerComponent('ProjectOne', () => ProjectOne);
Is there any way that I can fetch the json file, and then, display the json content into that text field on this page?
You can do it by using require('./app/prediction.json') then convert it to string or format if needed

React Native - Element type is invalid: Expected a string

I'm wanting to display a static map inside my app based off some coords.
I am using the following library: react-native-google-static-map
I have done the following:
npm install --save react-native-google-static-map
And added the following into my view:
var GoogleStaticMap = require('react-google-static-map');
And
<GoogleStaticMap
style={styles.map}
latitude={'32.064171'}
longitude={'34.7748068'}
zoom={13}
size={{ width: 300, height: 550 }}
This builds fine. However when I go and into the view, I get the following error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method ofSingle.
Where Single is the class name for my view.
Any ideas to where I am going wrong here?
Full code:
import React, { Component } from 'react'; import { View } from 'react-native';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
TouchableHighlight,
ActivityIndicator,
NavigatorIOS,
ListView,
Image,
WebView,
} from 'react-native';
var GoogleStaticMap = require('react-google-static-map');
class Single extends Component {
render() {
return (
<Image style={styles.container} source={require('../../images/home.jpg')}>
<View style={styles.map}>
<GoogleStaticMap
style={styles.map}
latitude={'32.064171'}
longitude={'34.7748068'}
zoom={13}
size={{ width: 300, height: 550 }} />
<View style={styles.business}>
<Text style={styles.businessName}>{this.props.property.street_address} {this.props.property.postcode}</Text>
</View>
<View style={styles.overview}>
<Text style={styles.heading}>
Overview
</Text>
<Text style={styles.bodyText}>{this.props.property.overview}</Text>
</View>
<View style={styles.overview}>
<Text style={styles.heading}>
Opening Hours
</Text>
<Text style={styles.bodyText}>Monday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
<Text style={styles.bodyText}>Tuesday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
<Text style={styles.bodyText}>Wednesday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
<Text style={styles.bodyText}>Thursday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
<Text style={styles.bodyText}>Friday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
<Text style={styles.bodyText}>Saturday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
<Text style={styles.bodyText}>Sunday {this.props.property.opening_hours.monday_open} - {this.props.property.opening_hours.monday_close}</Text>
</View>
</View>
</Image>
)
}
}
const styles = StyleSheet.create({
business: {
backgroundColor: 'rgba(0,0,0,0.5)',
marginTop: 10,
},
businessName: {
fontSize: 14,
padding:10,
color: '#ffffff'
},
map: {
flex: 1,
marginTop: 30,
width: null,
height:10,
},
overview: {
marginTop: 30,
left:0,
height:null,
backgroundColor: 'rgba(0,0,0,0.5)',
},
bodyText: {
color: '#ffffff',
padding: 10,
},
heading: {
padding:5,
backgroundColor: '#008983',
color: '#ffffff'
},
container: {
flex: 1,
marginTop: 50,
width:null,
height:null,
},
backdropView: {
top:100,
height: 200,
width: 320,
backgroundColor: 'rgba(0,0,0,0.5)',
},
headline: {
fontSize: 20,
textAlign: 'center',
padding:40,
backgroundColor: 'rgba(0,0,0,0)',
color: 'white'
},
backdropViewTitle: {
color: 'white',
textAlign: 'center',
padding:10,
fontSize: 20,
},
search: {
height:50,
fontSize: 15,
borderWidth: 1,
borderColor: '#fff',
borderRadius: 1,
color: '#fff',
width:295,
marginTop:10,
marginLeft:10,
padding:10
},
content:{
backgroundColor:'#ebeef0',
flex:1,
alignItems:'center' //<-----
},
messageBoxTitleText:{
fontWeight:'bold',
color:'#fff',
textAlign:'center',
fontSize:20,
marginBottom:10
},
messageBoxBodyText:{
color:'#fff',
fontSize:16
},
logo: {
top:50,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
flowRight: {
flexDirection: 'row',
alignItems: 'center',
width: 300,
left:60
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
button: {
top:10,
left:10,
height: 40,
width:100,
flexDirection: 'row',
backgroundColor: '#48BBEC',
borderColor: '#48BBEC',
marginBottom: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
searchLocation: {
height: 36,
padding: 4,
marginRight: 5,
flex: 5,
fontSize: 10,
borderWidth: 1,
borderColor: '#48BBEC',
borderRadius: 8,
color: '#48BBEC',
},
searchInput: {
height: 36,
padding: 4,
marginRight: 5,
flex: 4,
fontSize: 10,
borderWidth: 1,
borderColor: '#48BBEC',
borderRadius: 8,
color: '#48BBEC'
},
});
module.exports = Single;
You need to do one of the following.
Import GoogleStaticMap by using either:
var GoogleStaticMap = require('react-native-google-static-map').default;
or
import GoogleStaticMap from 'react-native-google-static-map';