Skip to content

Commit 9ad2744

Browse files
committed
Bug fix js doubled after orientation change
1 parent bdc1800 commit 9ad2744

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

anychart/src/main/java/com/anychart/AnyChartView.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public AnyChartView(Context context, @Nullable AttributeSet attrs, int defStyleA
7171
public Parcelable onSaveInstanceState() {
7272
Bundle bundle = new Bundle();
7373
bundle.putParcelable("superState", super.onSaveInstanceState());
74-
bundle.putString("js", this.js.toString());
74+
bundle.putString("js", js.toString());
7575

7676
return bundle;
7777
}
@@ -80,7 +80,7 @@ public Parcelable onSaveInstanceState() {
8080
public void onRestoreInstanceState(Parcelable state) {
8181
if (state instanceof Bundle) {
8282
Bundle bundle = (Bundle) state;
83-
this.js.append(bundle.getString("js"));
83+
js.append(bundle.getString("js"));
8484
state = bundle.getParcelable("superState");
8585
}
8686
isRestored = true;
@@ -128,6 +128,9 @@ public void onJsLineAdd(final String jsLine) {
128128
webView.post(new Runnable() {
129129
@Override
130130
public void run() {
131+
if (isRestored) {
132+
return;
133+
}
131134
if (isRendered) {
132135
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
133136
webView.evaluateJavascript(jsLine, null);
@@ -149,14 +152,6 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
149152
}
150153

151154
public void onPageFinished(WebView view, String url) {
152-
if (chart != null) {
153-
if (!isRestored) { //!isRendered &&
154-
// js.append(chart.generateJs());
155-
}
156-
} else {
157-
throw new NullPointerException();
158-
}
159-
160155
String resultJs = (isRestored)
161156
? js.toString()
162157
: js.append(chart.getJsBase()).append(".container(\"container\");")
@@ -178,20 +173,8 @@ public void onReceiveValue(String value) {
178173
}
179174
});
180175

176+
isRestored = false;
181177
isRendered = true;
182-
183-
// chart.setOnChangeListener(new Chart.OnChange() {
184-
// @Override
185-
// public void onChange(final String jsChange) {
186-
// js.append(jsChange);
187-
// webView.post(new Runnable() {
188-
// @Override
189-
// public void run() {
190-
// webView.evaluateJavascript(jsChange, null);
191-
// }
192-
// });
193-
// }
194-
// });
195178
}
196179
});
197180
webView.addJavascriptInterface(ListenersInterface.getInstance(), "android");
@@ -260,7 +243,6 @@ public void clear() {
260243
}
261244

262245
public void setChart(Chart chart) {
263-
js.setLength(0);
264246
isRestored = false;
265247
this.chart = chart;
266248
loadHtml();

0 commit comments

Comments
 (0)