Skip to content

Commit

Permalink
[feature] Support custome events.
Browse files Browse the repository at this point in the history
  • Loading branch information
supervons committed Aug 24, 2022
1 parent a4aa769 commit b035c2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/Echarts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ function Echarts(props, ref) {
setInstanceResult((instanceResult) => tempInstanceResult);
latestResult.current = tempInstanceResult;
latestCount.current = true;
} else {
} else if (echartsData.type === "click") {
props.onPress?.(JSON.parse(event.nativeEvent.data));
} else {
if (props.eventActions && props.eventActions[echartsData.type]) {
props.eventActions[echartsData.type](echartsData);
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/components/Echarts/renderChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ export default function renderChart(props) {
)});
const myChart = echarts.init(eChartsContainer, '${props.themeName}');
let formatterVariable = ${toString(props.formatterVariable || "")};
for(let temp of ${JSON.stringify(props.eventArrays)}){
myChart.on(temp, (params)=>{
const clickParams = {
...params,
type: temp
};
window.ReactNativeWebView.postMessage(JSON.stringify(clickParams));
});
}
myChart.on('click', (params)=>{
const clickParams = {
name: params.name || "",
value: params.value || 0
value: params.value || 0,
type: "click"
};
window.ReactNativeWebView.postMessage(JSON.stringify(clickParams));
});
Expand Down

0 comments on commit b035c2a

Please sign in to comment.