Open Profit-tech opened 2 years ago
That’s the reason why it’s impossible to send the actual data to the trade chart.
Thus I'm looking for any solutions for JS API integration with an ability to send data to a trading chart dynamically.
I don't think that it is impossible because of that. Did you try to implement datafeed so it will request a data from your app rather that requesting it from the network. I think this should work fine.
The question is exactly how to implement datafeed in react-native application.
Let’s follow through the example:
As a result added files will include index.html (it describes in tradingview configuration). It displays via the WebView in my application also (your could find it at the screen above).
So. My base question is how to change the data for datafeed in dynamic (relying on user’s actions) if there is no access to index.html file from my React-native application.
Hi! Please, check the documentation of React Native WebView
In the example you can see Web-to-Native communication.
Inject javascript
injectedJavaScript={this.jsToInject}
jsToInject
tvWidget.onChartReady(function() {
tvWidget.chart().onIntervalChanged().subscribe(
null,
function(interval) {
const response = { type: "onIntervalChanged", interval: interval }
window.ReactNativeWebView.postMessage(JSON.stringify(response));
}
);
});
Write a handler for that action
onMessage={(event) => {
const data = JSON.parse(event.nativeEvent.data)
if (data.type == "onIntervalChanged") {
Alert.alert(
'onIntervalChanged',
"Interval = " + data.interval,
[
{ text: 'OK', onPress: () => console.log('OK Pressed') }
],
{ cancelable: true }
);
}
}}
Now if you want to make Native-to-Web communication you should use injectJavaScript
method
import React, { Component } from 'react';
import { View } from 'react-native';
import { WebView } from 'react-native-webview';
export default class App extends Component {
render() {
const run = document.body.style.backgroundColor = 'blue'; true;
;
setTimeout(() => {
this.webref.injectJavaScript(run);
}, 3000);
return (
<View style={{ flex: 1 }}>
<WebView
ref={(r) => (this.webref = r)}
source={{
uri: 'https://github.com/react-native-webview/react-native-webview',
}}
/>
</View>
);
} }
Did anyone come up with a working solution? Is there anyone who successfully integrated the charts in react native and made it look good on mobile?
Any updates on this? I am stuck in the same position
The same here, don't know what to do...
Same here......