Last active
November 17, 2016 18:00
-
-
Save mishuagopian/97244fb17ff146182294cdd33a9bf2ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { Platform, View, WebView } from 'react-native'; | |
import HeatmapUtils from '../../utils/HeatmapUtils'; | |
export default class Heatmap extends Component { | |
componentDidMount() { | |
setTimeout( | |
() => { | |
// https://github.com/facebook/react-native/issues/953 | |
this.refs.heatmap.measure((ox, oy, width, height) => { | |
const radius = Math.round(width * 0.05); | |
const processedPoints = HeatmapUtils.processPoints(this.props.firstPoint, | |
this.props.secondPoint, | |
this.props.thirdPoint, | |
this.props.points, | |
width, height, radius); | |
this.setState({ processedPoints, radius }); | |
}); | |
} | |
); | |
} | |
render() { | |
let webview = null; | |
if (this.state.processedPoints) { | |
const uri = Platform.OS === 'ios' ? 'heatmap.html' : 'file:///android_asset/heatmap.html'; | |
const maxValue = Math.max(...this.state.processedPoints.map((p) => p.value)); | |
const script = heatmapInputGenerator(this.state.processedPoints, this.state.radius, maxValue); | |
webview = <WebView | |
source={{ uri: uri }} | |
scrollEnabled={false} | |
injectedJavaScript={script} | |
javaScriptEnabled | |
/>; | |
} | |
return ( | |
<View style={{ alignItems: 'center', flex: 1, justifyContent: 'center'}} > | |
<View | |
style={{ backgroundColor: 'white', height: 100, width: 300 }} | |
ref='heatmap' | |
> | |
{ webview } | |
</View> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment