KineticJS doesn't draw android 4.+
I've a problem with kineticjs and Android 4.+ (WebView). I need to draw one image into canvas with kineticjs like my next example, but sometimes it doesn't draw. I say 2 successes against 15 losses.
Some "solutions" that I've tried:
- setTimeout with 50+;
- set all parent's div with overflow: visible;
- change my viewport: scale, minimum, maximum, width, height, etc...
Someone have any idea how do I can to solve this problem? Thanks so much.
var stage, layer, image;
var canvasid = "container-canvas";
window.onload = function{
stage = new Kinetic.Stage({
container: canvasid,
width: 768,
height: 1024
});
layer = new Kinetic.Layer();
image = new Image();
image.onload = function() {
var pageImage = new Kinetic.Image({
image: image,
x: 0,
y: 0,
width: 768,
height: 1024
});
layer.add(pageImage);
stage.add(layer);
};
image.src = "imgs/6.png";
}
Android WebView Settings
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setSupportZoom(false);
webView.setWebChromeClient(new WebChromeClient());
webView.setInitialScale(1);
webView.setScrollBarStyle(WebView.OVER_SCROLL_NEVER);
if(savedInstanceState == null)
webView.loadUrl("file:///android_asset/index.html");
Is it working on usual browser?
Just desktop browser, safari mobile browser (safari webview work too) it work fine. I tried Chrome and default browser in the Android 4.+ and sometimes the canvas is duplicate or it doesn't draw. Of course, it happen with webview android...
Ok. First try to set timeout to 300ms:
var stage = new Kinetic.Stage(conf);
var layer = new Kinetic.Layer();
stage.add(layer);
setTimeout(function(){
// add shapes to the layer and then do layer.draw()
}, 300);
If it is not helpful try second (insert before your code):
var updateCanvas = function(canvas){
canvas.style.opacity = 0.9;
setTimeout(function() {
canvas.style.opacity = 1;
});
};
var oldDraw = Kinetic.Layer.prototype.draw;
Kinetic.Layer.prototype.draw = function(){
updateCanvas(this.canvas._canvas);
oldDraw.apply(this, arguments);
return this;
};
Thanks so much for you help, but, it doesn't work :/ ... I'll try to change the webview settings. Ps: I tried with chrome mobile an default browser android 4.+, and with this examples the canvas draw, but, the duplicate canvas still happening. With android webview doesn't happen the duplicate canvas, but, it's doesn't draw, like I say 2 successes against 15 losses.