I tried to display MathML equation in my react native app using MathJax, but it is not showing. In the code below, the equation is not displayed, only "Helloworld".
import React, {Component} from 'react';
import {Text, View} from 'react-native';
import MathJax from 'react-native-mathjax'
export default class TipsAndTricksScreen extends Component {
static navigationOptions = {
title: 'Tips And Tricks',
};
render() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<MathJax math={String.raw`<math xmlns="http://www.w3.org/1998/Math/MathML"><msqrt><mn>2</mn><mfrac bevelled="true"><mn>7</mn><mn>7</mn></mfrac></msqrt><mo>+</mo><mfrac><mn>5</mn><mn>8</mn></mfrac></math>this is just a string`} />
<Text>Helloworld</Text>
</View>
);
}
}
It seems quite straight forward to implement the dependency. Looking at the source code of the dependency it looks like it is just a wrapper around a Webview, so just be aware that it will probably only work if you are online.
The dependency has some default options already set for MathJax and you can pass further options using the mathJaxOptions prop. So if we pass
{
jax: ['input/MathML']
}
then it should tell MathJax that you are passing MathML as a input.
So here is a simple component that uses react-native-mathjax
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import MathJax from 'react-native-mathjax';
const mmlOptions = {
jax: ['input/MathML'],
};
class MathView extends Component {
render () {
return (
<View style={{flex:1}}>
<MathJax
mathJaxOptions={mmlOptions}
html={'<math xmlns="http://www.w3.org/1998/Math/MathML"><msqrt><mn>2</mn><mfrac bevelled="true"><mn>4</mn><mn>7</mn></mfrac></msqrt><mo>+</mo><mfrac><mn>5</mn><mn>8</mn></mfrac></math> this is just a string'}
/>
</View>
);
}
}
export default MathView;
This would give you something like this
That should be enough to get you started. You can pass additional options via the mathJaxOptions prop. You just need to look at the MathJax documentation for all the different things that you can pass.
Caveat
On Android it doesn't look like the Android WebView can render MathML, there maybe a configuration that will make it work but I don't know it, however the Android WebView does render LaTex, so perhaps converting your MathML to LaTex could be a fallback option for you.
If you want to render MathML in React Native, you'll need some extensions and of course input and output method. After some research, I found this solution particular for MML to HTML:
<MathJax
html={`<math xmlns="http://www.w3.org/1998/Math/MathML"><msqrt><mn>2</mn><mfrac bevelled="true"><mn>7</mn><mn>7</mn></mfrac></msqrt><mo>+</mo><mfrac><mn>5</mn><mn>8</mn></mfrac></math>this is just a string`}
mathJaxOptions={{messageStyle: 'none',
extensions:
['mml2jax.js','MathMenu.js','MathZoom.js','AssistiveMML.js','a11y/accessibility-
menu.js',],
jax: ['input/MathML', 'output/CommonHTML'],
tex2jax: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$', '$$'], ['\\[', '\\]']],
processEscapes: true,},
TeX: {extensions:['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'],},}} />
Related
I just finished coding a website with a Virtual Tour made on Unity, i've exported it as WEBGL with compression format disabled, and decompression fallback off(Unity). Then added this to my code on React
import React from "react";
import Unity, { UnityContext } from "react-unity-webgl";
const unityContext = new UnityContext({
loaderUrl: "../Build/unity341.loader.js",
dataUrl: "../Build/unity341.data",
frameworkUrl: "../Build/unity.framework.js",
codeUrl: "../Build/unity341.wasm",
});
function Game() {
return <Unity unityContext={unityContext} />;
}
export default Game;
then imported the game on the page
import React, {Component} from 'react';
import Game from './game.jsx';
import {Container} from 'react-bootstrap';
class GamePage extends Component {
render() {
return (
<div>
<Game/>
<Container>
//text and stuff inside the container
</Container>
</div>
);
}
}
export default GamePage;
But when i render it on my localhost i dont get the Unity viewer, and when inspecting on Chrome the only thing i see where the game should be is the following tag
<canvas class>
Thanks for your help guys !
Put generated WebGL files from Build folder to public folder in react. See picture. Those files must be in public folder because react server is hosting static files in this folder. For example i have put them to public\build folder. See picture.
Code in react:
const unityContext = new UnityContext({
loaderUrl: 'build/<AppName>.loader.js',
dataUrl: 'build/<AppName>.data',
frameworkUrl: 'build/<AppName>.framework.js',
codeUrl: 'build/<AppName>.wasm',
});
<Unity unityContext={unityContext} style={{ width: '100%', height: '100%' }} />
I've fletched a list of items and rendered it into my app.
Its the first page of the app.
The thing that I want to do is:
Make each of the items "touchable", and when you touch it, you open a component filled with objects from a second fetch requisition.
I am new to react native, do you know if I have to use a lib or something to do it?
I'll try to answer your questions one by one.
Make each of the items "touchable"
Wrap your components with TouchableOpacity which you can import from react native like this import {TouchableOpacity} from "react-native";
when you touch it, you open a component filled with objects
You need to implement onPress method there and also react navigation to load other components.
<TouchableOpacity onPress={() => this.props.navigation.navigate("newScreenName")}>
<MyCustomComponent>
...
</MyCustomComponent>
</TouchableOpacity>
and creating screen will be like this :
import { createStackNavigator } from "react-navigation";
import Screen1 from "./Screen1";
import Screen2 from "./Screen2";
...
const customStackNavigator = createStackNavigator(
{
newScreenName: {
screen: Screen1
},
newScreenName1: {
screen: Screen2
}
},
{}
);
check API & Docs here
Also, Please check this example for more details
Is there any way that able to get updated/modified image object using ReactComponent?
Currently, PESDK React version only supports UI customization.
After edit image in PhotoEditor, can I get exported object using ReactComponent so as to integrate it into existing react component?
I couldn't find any solution in PESDK documentation.
If anyone knows the solution, please let me know
Or PESDK is on progressing development yet?
Thanks
Something like this should work:
import React from 'react'
import ReactDOM from 'react-dom'
window.React = React
window.ReactDOM = ReactDOM
import PhotoEditorUI from 'photoeditorsdk/desktop-ui'
// import PhotoEditorUI from 'photoeditorsdk/react-ui'
class ApplicationComponent extends React.Component {
// Call this when you want to export the editor image
export () {
this.editor.ui.export()
.then(image => {
// Image code here
})
}
render () {
const { ReactComponent } = PhotoEditorUI
return (<ReactComponent
license='PUT YOUR LICENSE KEY HERE' // e.h. '{"owner":"Imgly Inc.","version":"2.1", ...}'
ref={c => this.editor = c}
assets={{
baseUrl: '/node_modules/photoeditorsdk/assets'
}}
editor={{image: this.props.image }}
style={{
width: 1024,
height: 576
}} />)
}
}
I'm using React Native which ships with React 16 alpha release which supports portals. While in browser and having access to DOM we can use id or classes to access element from anywhere in component/file hierarchy like this:
const modalRoot = document.getElementById('modal-root');
and pass it to createPortal(child, container) container arg. React docs clearly says than container should be DOM element:
The second argument (container) is a DOM element.
This function is also a method of ReactDOM which doesn't exist in React Native.
Is there a way to achieve the similar functionality in React Native?
Use case:
I want to render an animated overlay in the root of my application but pass the Animated values props to it from a parent deep in the tree hierarchy (can't use Redux actions for such things).
I had similar problem where I wanted to render overlay on top of everything from deeply nested child component. I solved my problem with React Native's Modal
It renders its content on top of everything :) Easy to use and no need for extra dependencies
I don't think react-native provides this functionality in its own API.
But there is a library available which provides the similar functionality. react-gateway
As per the docs of react-gateway,
It also works in universal (isomorphic) React applications without any additional setup and in React Native applications.
React Gateway does not directly depend on react-dom, so it works fine with React Native under one condition:
You must pass React Native component like View or similar to component prop of .
import React from 'react';
import { Text, View } from 'react-native';
import {
Gateway,
GatewayDest,
GatewayProvider
} from 'react-gateway';
export default class Application extends React.Component {
render() {
return (
<GatewayProvider>
<View>
<Text>React Gateway Native Example</Text>
<View>
<Gateway into="one">
<Text>Text rendered elsewhere</Text>
</Gateway>
</View>
<GatewayDest name="one" component={View} />
</View>
</GatewayProvider>
);
}
}
The above example is taken from the repo itself. react native example
One way to render the items above the screen can be done using react-native-paper library.
import * as React from 'react';
import { Text } from 'react-native';
import { Portal } from 'react-native-paper';
const MyComponent = () => (
<Portal.Host>
<Text>Content of the app</Text>
</Portal.Host>
);
export default MyComponent;
Portal host renders all of its children Portal elements. For example, you can wrap a screen in Portal.Host to render items above the screen.
Here is the link which describes its usage:
https://callstack.github.io/react-native-paper/portal-host.html
I want to use a Font for all place or full app.
I don't want to call it too much time.
It should be call one time SO is it Possible ??
AS Like:
body {
font-family: 'Open Sans';
}
I all ready get some Type Answer Like that's..
BY Calling Costume Components
and By calling Global Style like...
<Text style={{styles.text}}> Demo </ Text>
const style= {
style: {
fontFamily: yourFont
}
}
But I don't want too use it like this way ..
Please give me any Update Answer or News...
Which help me to solve it BY Call one time..
NB: I all ready Complete my App 80%... It's have lot off View SO How can I get a Fonts everywhere by call one time anywhere.
What I think you are seeking is not directly possible as it is antithetical to React principles of isolated components. IMO the best approach is to create a custom component and use it to "replace" the Text component in your app. It's even possible to use Text as name for that component, and just change imports accordingly.
export default class Text extends Component {
constructor(props) {
super(props);
}
render() {
return (
<Text style={styles.defaultText}>{this.props.children}</Text>
);
}
}
const styles = StyleSheet.create({
defaultText: {
fontFamily: 'System'
}
});
Then simply change imports in the components you want to use this font, from
import { Text } from 'react-native';
to
import Text from './Text.js';