I am loading some HTML, Java script code into my iOS application. Its working fine, but, according to device height, I should have to change the animation size (width), I tried following code, but, I am very new to javascript calling into iOS.
my html page code of java script is
var $ios9 = document.getElementById('container-ios9');
var SW9 = new Wave9({
width: 800,
height: 40,
container: $ios9,
});
</script>
and I am calling into native code as
if (self.view.frame.size.width <= 400) {
[_animationWebView stringByEvaluatingJavaScriptFromString:#"document.getElementById('container-ios9').width = 500"];
}
else {
[_animationWebView stringByEvaluatingJavaScriptFromString:#"document.getElementById('container-ios9').width = 700"];
}
The above code is not changing the width, So,
Can anyone suggest me, how to fix this. Thanks!
After lot of R & D, I fixed the issue by myself. I am posting this answer here, It will help someone future.
In HTML file, Java script code,
if (window.screen.width <= 400) {
var $ios9 = document.getElementById('container-ios9');
var SW9 = new Wave9({
width: 800,
height: 40,
container: $ios9,
});
} else {
//other devices
</script>
Related
I was using Highchart 6.0.7 version and Updated it to 8.0.4. I am using generate an image using phantom js with Highchart Converte JS. Previously it was working after upgrading the newer version facing image cutting issue.
Image width is cutting. I am passing both values Exportorting and chart height width.
I had the same problem when I switched from Highcharts Version 7.0.2 to 8.0.4. The right side of the images were clipped. I solved the problem by patching highcharts-convert.js to always set the viewportSize instead of only adjusting the viewportSize for PDFs.
In highcharts-convert.js this was the original code
if (outType === 'pdf') {
// redefine the viewport
page.viewportSize = { width: clipwidth, height: clipheight };
// simulate zooming to get the right zoomFactor. Using page.zoomFactor doesn't work anymore, see issue here https://github.com/ariya/phantomjs/issues/12685
page.evaluate(function (zoom) {
document.getElementsByTagName('body')[0].style.zoom = zoom;
}, page.zoomFactor);
page.paperSize = { width: clipwidth * dpiCorrection, height: clipheight * dpiCorrection };
}
I changed the code to this
// redefine the viewport
page.viewportSize = { width: clipwidth, height: clipheight };
if (outType === 'pdf') {
//// redefine the viewport
//page.viewportSize = { width: clipwidth, height: clipheight};
// simulate zooming to get the right zoomFactor. Using page.zoomFactor doesn't work anymore, see issue here https://github.com/ariya/phantomjs/issues/12685
page.evaluate(function (zoom) {
document.getElementsByTagName('body')[0].style.zoom = zoom;
}, page.zoomFactor);
page.paperSize = { width: clipwidth * dpiCorrection, height: clipheight * dpiCorrection };
}
I hope this works as well for everyone else as it did for me.
I have spend hours on this and I got no where.
Here is the best combination I have got to.
https://jsfiddle.net/zardaloop/bztoju90/21/
However I can't understand why it is not printing correctly.
Does anyone know what I am doing wrong or knows any good solution to this?
window.takeScreenShot = function() {
html2canvas(document.getElementById("calendar"), {
onrendered: function (canvas) {
var doc = new jsPDF({ orientation: 'portrait',format: 'a4' });
var imgData = canvas.toDataURL("image/jpeg");
doc.addImage(imgData, 'JPEG', 0, 0, canvas.width, canvas.height);
doc.save("Print");
},
width:800,
height:600
});
}
Adding the background color to the generated image is enabling the printed pdf with readable content, Still figuring out the rest of the size issue which persists even after changing the orientation: 'landscape'
\\html2canvas(document.getElementById("calendar"), {
background: '#FFFFFF', \\Added option
\\ onrendered: function (canvas) {
Update:
Modifying the format and orientation is the way I see to debug this.
Please keep on trying with the same, for now the below line of code serves your purpose pretty well I believe.
var doc = new jsPDF({ orientation: 'landscape',format: 'a2' });
I am using angular-chart.js in my project to draw chart-doughnut with ionic. What I am doing here is setting chart height from controller code. The height I am setting is based on screen size. It is working perfectly fine on Android and Web but on iOS it is not working. Below is my code:
HTML code:
<canvas class="chart chart-doughnut" chart-data="data" height="{{height_chart}}" chart-colors="colors" chart-series="series" chart-options="options"></canvas>
Javascript code:
if (window.innerWidth < 600) {
$scope.height_chart = window.innerHeight * 0.5;
}
$scope.colors = ['#3973ac', '#d9e6f2'];
$scope.options = {
cutoutPercentage: 80,
tooltips: {
enabled: false
},
hover: {
mode: null
},
elements: {
arc: {
borderWidth: 0
}
}
};
I am not able to figure out the problem. Any pointer will be highly appreciable. Thanks
I don't know the exact reason why it happened but it is working fine on iOS real device. Issue can be reproduce only on simulator. Maybe there is some rendering issue in simulator.
I have developed a native module which requires me to pass a view while opening the module controller. The module is basically a PDF Reader and I need to put a custom sharing button which I need to pass from Titanium code. This button view was visible and working perfectly fine with Classic Titanium apps and also working fine when I programmatically create the button. The only problem is now using Alloy, I created a separate control for the button and now it stopped working.
Below I have pasted snippet for demo code.
Here is my code which was working fine when used programmatic control:
App.js:
var shareBase = Ti.UI.createView({
width: 40,
height: 40,
top: 0,
left: 0,
backgroundColor: 'green'
});
var shareview = Ti.UI.createView({
backgroundImage: 'shareview.png',
width: 40,
height: 40,
});
shareBase.add(shareView);
...
...
...
// Below is the code how I am passing the view for the module
var PDF_READER = require('com.investis.docreader');
var document = PDF_READER.createPDFDocument(reportFile.nativePath.trim());
...
document.setCustomView(shareBase); // Share view is being passed
document.setTitle(report.title);
document.display();
Controller in the module which accepts the view passed from Titanium code:
controller.m
- (void)setCustomView: (id)args {
TiUIViewProxy *_argVw = args;
if (!args) {
NSLog(#"View Proxy nil", nil);
}
[_pdfViewController setCustomView: _argVw.view ]; // _argVw.view gets UIView from ViewProxy
NSLog(#"View assigned here", nil);
NSLog([_argVw description], nil);
NSLog([_argVw.view description], nil);
}
pdfViewController.m - The controller from where original PDF Reader is called, so I need to pass the view to this controller which loads the view into Toolbar
...
_customButton = [[UIBarButtonItem alloc] initWithCustomView: _customView]; // _customView is the view which is passed from controller.m
...
// Now display button items into toolbar
toolbarItems = [NSArray arrayWithObjects:... _customButton, fixedSpace, ..., nil];
The above code was working fine. But when I implemented the code as Alloy controller, the custom view is stopped being loaded from the controller.
App.js
var pdfshare = Alloy.createController("SocialShare", {});
...
document.setCustomView(pdfshare.getView()); // Passing custom view from the controller, other code in the file remain same
...
Here is the code how SocialShare is created.
SocialShare.xml
<Alloy>
<View id="container" class="container">
<View id="shareIt" onSingletap="shareIt" platform="ios"/>
<View id="shareIt" onSingletap="shareItAndroid" platform="android" />
</View>
</Alloy>
SocialShare.tss
".container":{
backgroundColor: 'yellow',
borderWidth: 2,
borderColor: 'black',
right: 0,
bottom: 0
},
".container[formFactor=tablet]":{
height: 43,
width: 43
},
".container[formFactor=handheld]":{
height: 40,
width: 40
}
SocialShare.js
var args = arguments[0] || {};
...
// Here nothing extra ordinary UI related tasks are performed. Only event handlers for shareIt
The same code at Module side but still it stopped working. If I pass view generated programmatically then it works fine. Let me know if we need to treat Alloy views differently or not. I have searched a lot over Google and read through docs but unable to find any proper solution.
Details:-
Titanium SDK: 3.2.3.GA
Alloy: 1.3.0
iPhone Simulator: 7.1
Let me know if there is any solution around this or any patch.
I'm currently developing a Chrome Packaged App and I'm using webviews, however I'm not having success at hidding the scroll bar on said webviews. I've tried using the overflow tag with no success.
Any help would be appretiated.
Try this:
var appWin = null;
chrome.app.runtime.onLaunched.addListener(function(launchData) {
chrome.app.window.create(
'main.html',
{bounds: {width: 800, height: 400}},
function(win) {
appWin = win;
win.onBoundsChanged.addListener(onBoundsChanged);
onBoundsChanged();
}
);
}
function onBoundsChanged() {
var bounds = chrome.app.window.current.getBounds();
var webview = appWin.contentWindow.document.getElementById("#my_webview");
webview.style.height = bounds.height + 'px';
webview.style.width = bounds.width + 'px';
}
Obviously, if your window is fixed size (resizable: false), you don't need to define an onBoundsChanged handler: you can adjust your webview size directly in the chrome.app.window.create() callback using the hardcoded dimensions you've specified for your window.
This is what I did to remove the webview's scrollbar when embedded inside Packaged Chrome App:
<html lang="en" style="overflow:hidden">
Edit: This code lives inside the page that the webview references - not the code inside your packaged chrome app.