How to link a static HTML file not generated by Docusaurus? - docusaurus

I use docusaurus and I want include static html page generated by an other part of my environement.
Online: https://stackblitz.com/github/facebook/docusaurus/tree/starter
/src/pages/helloReact.js
import React from 'react';
import Layout from '#theme/Layout';
function Hello() {
return (
<Layout title="Hello">
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '50vh',
fontSize: '20px',
}}>
<p>
Edit <code>pages/helloReact.js</code> and save to reload.
</p>
</div>
</Layout>
);
}
export default Hello;
but HTML code is not in other HTML file (static/foo/bar/index.html)

Related

flex:1 makes my view disapear in react-native

i am new to react i m trying to make the background color of my main container cover all the screen but when i use flex 1 everything seems to disappear i've seen many people doing it and it turned fine i can't understand the problem since i m using it on my container .
import React from 'react';
import mainstyles from '../styles/mainstyles';
import {
Button,
Text,
View,
AlertButton,
TouchableOpacity,
} from 'react-native';
const UploadFile = ()=>{
return (
<View style={mainstyles.container}>
<Text style={mainstyles.title}>Ocr Scan</Text>
<Text style={mainstyles.par}>Import a file and start digitizing</Text>
<Button
title="Take picture"
/>
<Button
title="Upload file"
/>
</View>
);
};
export default UploadFile;
import {StyleSheet} from 'react-native'
const mainstyles=StyleSheet.create({
container:{
flex:1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'black',
},
When you use flex on a component A, every component B that nest component A need to use flex.

How to translate mobile app text using language drop-down inside react-native app?

I want to add translate drop-down inside mobile app to translate the app text without using language json file.
I just want to add the select list at the top of app to change the language of text, like this: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_google_translate
Is this possible with react native app?
Here is an example of how you can achieve that.
Working Example: Expo Snack
import React, { useState } from 'react';
import { Text, View, StyleSheet, Picker } from 'react-native';
import Constants from 'expo-constants';
const engToHindi = {
english: 'hello',
hindi: 'नमस्कार',
};
export default function App() {
const [language, setLanguage] = useState('english');
return (
<View style={styles.container}>
<Picker
selectedValue={language}
style={{ height: 50, width: 100 }}
onValueChange={(itemValue) => setLanguage(itemValue)}>
<Picker.Item label="English" value="english" />
<Picker.Item label="हिन्दी" value="hindi" />
</Picker>
<Text>{engToHindi[language]}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});
Online Implementation using Google Translate API would be possible but I don't have the API keys so could not give you the example of that implementation.

React native Responsive layout in Functional component

Below is the basic code for Responsive layout using npm package(react-native-responsive-screen). This is working fine as expected in Class component. But, I want to change the below code to Functional component. I have almost changed everything. Initially no error when i load the app in portrait/landscape mode. Once i change it to landscape/portrait, it will come up with some error.
Here is the link of Original source. https://github.com/marudy/react-native-responsive-screen/blob/master/examples/responsive-screen-orientation-change/README.md
import React, { useEffect, useState } from 'react';
import { StyleSheet, Dimensions } from 'react-native';
import { Container, View, Button, Text} from "native-base";
import {widthPercentageToDP as wp,
heightPercentageToDP as hp,
listenOrientationChange as lor,
removeOrientationListener as rol } from 'react-native-responsive-screen';
const Responsive = () =>
{
useEffect( () =>
{
lor();
return () => rol()
},[])
const styles = StyleSheet.create({
container: { flex: 1, alignItems: 'center', justifyContent:'center' },
title: {
backgroundColor: 'gray',
height: hp('10%'),
width: wp('80%'),
alignItems: 'center',
justifyContent:'center',
marginVertical: wp('10%'),
},
myText: {
textAlign:'center',
color:'white',
fontSize: hp('5%') // End result looks like the provided UI mockup
},
buttonStyle:
{
height: hp('8%'), // 70% of height device screen
width: wp('30%'),
marginHorizontal: wp('10%'),
},
buttonContainer:
{
flexDirection:'row',
marginBottom: wp('10%'),
},
paraContainer:
{
width: wp('80%'),
},
paraText:
{
textAlign:'justify'
}
});
return (
<Container>
<View style={styles.container}>
<View style={styles.title}>
<Text style={styles.myText}>Screen title with 50% width</Text>
</View>
<View style={styles.buttonContainer}>
<Button success style={styles.buttonStyle}><Text>Button 1</Text></Button>
<Button success style={styles.buttonStyle}><Text>Button 2</Text></Button>
</View>
<View style={styles.paraContainer}>
<Text style={styles.paraText}>
As mentioned in "How to Develop Responsive UIs with React Native" article, this solution is
already in production apps and is tested with a set of Android, iOS emulators of different
screen
specs, in order to verify that we always have the same end result.
</Text>
</View>
</View>
</Container>
);
}
export default Responsive;
Thanks in Advance.
It is not due to your code, it is due to library limitation. Current version of library still does not support functional components.
There is an open issue and PR regarding that open
issue: https://github.com/marudy/react-native-responsive-screen/issues/82
PR: https://github.com/marudy/react-native-responsive-screen/pull/70
If you still want to continue with this library, just use the head of that PR in your package.json and it should work.
"react-native-responsive-screen": "marudy/react-native-responsive-screen#70/head",
Make sure to delete node_module and perform yarn or npm install

Is it possible to use <div> tag in React Native tag?

Now I am using firebase JS SDK to use phone authentication. I followed the web method.
Here is my code:
handleClick = () => {
this.state.verify_otp = "flex";
this.state.register = "none";
this.recaptcha = new firebase.auth.RecaptchaVerifier("recaptcha1");
this.number = this.state.phone;
};
.
<View
style={{
alignItems: "center",
justifyContent: "center",
flex: 1,
display: this.state.captcha,
}}
>
<div>
<div id="recaptcha1"></div>
</div>
</View>
Is it possible to use a tag in react-native code?
No, not natively. React Native doesn't support direct HTML, as it is not a web framework.
For rendering HTML in React Native, see Render HTML in React Native
No, it's not possible to use html tags in react-native
edit: list of basic RN components https://reactnative.dev/docs/components-and-apis#basic-components
No, you cannot use the <div> element inside a react native component because React Native does not have a DOM.
Unfortunately its not possible. Div is an HTML element which can be read by Browser. For mobile app, Its View
However you can build your own div
class Div extends Component { //or Class Span extends Component
static propTypes = {
style : PropTypes.obj
onClick : PropTypes.func // ...
}
render (){
return (
<View>
/* whatever is needed to pass everything through ... */
</View>
) }
}
You could use react-native-render-html to achieve like follow.
(if couldn't work have to install react-native-webview)
import * as React from 'react';
import { Text, View, StyleSheet,ScrollView, Dimensions } from 'react-native';
import Constants from 'expo-constants';
import HTML from 'react-native-render-html';
const htmlContent = `
<h1>This HTML snippet is Using react-native-render-html !</h1>
<h2>Trying many tag to render html</h2>
<img src="https://i.imgur.com/fJ71V9b.jpg" />
<div>Here is what you want to add!!!!!<div>`
;
export default function App() {
return (
<View style={styles.container}>
<ScrollView style={{ flex: 1 }}>
<HTML html={htmlContent} imagesMaxWidth={Dimensions.get('window').width} />
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
}
});
Code example on snack

React Native - NativeBase components not taking up full width on iOS

In the iOS version of my react native app built with NativeBase, everything is too skinny, unless a specific width is given. See images below. I have given the header and footer a width of 100% so it is fine, but I haven't done that for the inputs and they are too skinny. The header and footer are that skinny when not given a width too.
code:
import React from 'react'
import {
Container,
Header,
Form,
Item,
Input,
Label,
Content,
Footer,
FooterTab,
Button,
Left,
Right,
Body
} from 'native-base'
import { Text, Image } from 'react-native'
export const Volcalc = () => {
return (
<Container style={styles.container}>
<Header style={styles.header}>
<Left>
<Image resizeMode={Image.resizeMode.contain} style={styles.thumbnail} source={require('./img/logo_red_nowords.png')} />
</Left>
<Body>
</Body>
<Right />
</Header>
<Content>
<Form>
<Item stackedLabel bordered >
<Label>height</Label>
<Input />
</Item>
<Item stackedLabel >
<Label>width</Label>
<Input />
</Item>
</Form>
</Content>
<Footer >
<FooterTab style={styles.footer}>
<Button full>
<Text>Footer 1</Text>
</Button>
</FooterTab>
</Footer>
</Container>
)
}
const $mainColor = '#00d1b2'
const styles = {
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: $mainColor
},
header: {
width: '100%',
backgroundColor: $mainColor
},
footer: {
width: '100%',
backgroundColor: $mainColor
},
thumbnail: {
width: 35,
height: 35
}
}
I'm pretty sure I'm supposed to be able to add inputs and header, without specifying width, and it should take up the full width like Android does when not specifying. What could be wrong with my project that is causing this?
width: '100%' is supported in react native, it will take 100% of its parent width.
I think your problem is the the justifyContent:'center' and alignItems:'center' in the styles.container, they are causing all elements to be in the center of the component. You can try adding a distinctive background color to your Content component to see where it is and how much width it has.
Try adding this style:
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: $mainColor,
flexDirection: 'row' // <--- Add this line
}
Apart from above suggestion, you can use "Toggle Inspector" to get the style attributes. But I also found react native apps during development sometimes gets stuck in previous states. Try to uninstall and reinstall it.
Try using Dimensions.
import { Dimensions } from 'react-native';
var {width} = Dimension.get('window');
then you can use like
<Form style={{width:width}}>