Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for React Native 0.63.4 (with ios) #203

Merged
merged 5 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
## How to start - Android

1. Setup the development environment. [React Native Docs](https://reactnative.dev/docs/environment-setup)
1. Run "npm install" in the project root folder. Wait until the installation completes.
2. Open android/app/src/main/assets.
2. Run "npm install" in the project root folder. Wait until the installation completes.
3. Open android/app/src/main/assets.
4. Copy all files from https://github.com/tradingview/charting_library/. The earliest supported version of the Charting Library is 1.12. If you get 404 then you need to [request an access to this repository](https://www.tradingview.com/HTML5-stock-forex-bitcoin-charting-library/).
2. Run "npx react-native run-android" to start installing the application to a device.
5. Run "npx react-native run-android" to start installing the application to a device.

## How to start - iOS

Currently unavailable.
1. Setup the development environment. [React Native Docs](https://reactnative.dev/docs/environment-setup)
2. Run "npm install" in the project root folder. Wait until the installation completes.
3. Open Example.xcodeproj in Xcode.
4. Right click on Example and select "Add Files to "Example"".
5. Copy all files from https://github.com/tradingview/charting_library/. The earliest supported version of the Charting Library is 1.12. If you get 404 then you need to [request an access to this repository](https://www.tradingview.com/HTML5-stock-forex-bitcoin-charting-library/).
6. Run "npx react-native run-ios" to start installing the application to a device.

## What is Charting Library

Expand Down
30 changes: 15 additions & 15 deletions react-native/app/android.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { WebView } from 'react-native-webview';
class AndroidChart extends Component {

jsToInject = `
tvWidget.onChartReady(function() {
tvWidget.chart().onIntervalChanged().subscribe(
null,
function(interval) {
window.ReactNativeWebView.postMessage({
type: "onIntervalChanged",
interval: interval
});
}
);
});
true; // note: this is required, or you'll sometimes get silent failures
// (https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md)
tvWidget.onChartReady(function() {
tvWidget.chart().onIntervalChanged().subscribe(
null,
function(interval) {
const response = { type: "onIntervalChanged", interval: interval }
//window.ReactNativeWebView.postMessage accepts one argument, data,
//which will be available on the event object, event.nativeEvent.data. data must be a string.
window.ReactNativeWebView.postMessage(JSON.stringify(response));
}
);
});
true; // note: this is required, or you'll sometimes get silent failures
// (https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md)
`;

render() {
Expand All @@ -34,9 +34,9 @@ class AndroidChart extends Component {
onShouldStartLoadWithRequest={() => false}
injectedJavaScript={this.jsToInject}
onMessage={(event) => {
const data = event.nativeEvent.data
const data = JSON.parse(event.nativeEvent.data)
if (data.type == "onIntervalChanged") {
ToastAndroid.show("Interval = " + event.nativeEvent.data, ToastAndroid.SHORT);
ToastAndroid.show("Interval = " + data.interval, ToastAndroid.SHORT);
}
}}
/>
Expand Down
65 changes: 52 additions & 13 deletions react-native/app/ios.app.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,59 @@
import React from 'react';
import { SafeAreaView } from 'react-native';
import React, { Component } from 'react';
import { SafeAreaView, Alert } from 'react-native';
import { WebView } from 'react-native-webview';


class IOsChart extends Component {

jsToInject = `
tvWidget.onChartReady(function() {
tvWidget.chart().onIntervalChanged().subscribe(
null,
function(interval) {
const response = { type: "onIntervalChanged", interval: interval }
//window.ReactNativeWebView.postMessage accepts one argument, data,
//which will be available on the event object, event.nativeEvent.data. data must be a string.
window.ReactNativeWebView.postMessage(JSON.stringify(response));
}
);
});
true; // note: this is required, or you'll sometimes get silent failures
// (https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md)
`;

render() {
return (
<SafeAreaView
style={{flex: 1}}
>
<WebView
style={{flex: 1}}
source={{ uri: 'index.html' }}
allowFileAccessFromFileURLs={true}
originWhitelist={["*"]}
injectedJavaScript={this.jsToInject}
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 }
);
}
}}
/>
</SafeAreaView>
);
}
}

const IOsApp = () => {
return (
<SafeAreaView
style={{flex:1}}
>
<WebView
style={{flex: 1}}
source={{ uri: 'index.html' }}
allowFileAccessFromFileURLs={true}
originWhitelist={["*"]}
allowingReadAccessToURL={"*"}
/>
</SafeAreaView>
<IOsChart />
);
};
module.exports = IOsApp
Loading