Ok, so in our 'innovation lab', there is currently a push to use Ionic, an hybrid app framework built on top of Cordova for native access and angularJS for the ‘web code’.
There are also some projects which are pure mobile web, using Angular + bootstrap for responsive design for example.
The thing is some projects coming up will need to have both a mobile web site and native apps (ionic hybrid). Most features and screens will be the same, sharing back end and most of the UI but there still will be some difference.
So my question is; How to architecture a project so that it can be both an ionic project and a normal angular website with 2 different deployment approaches. Most of the code being reused but some views for the mobile website and some views for the hybrid app (using more native components and conventions), maybe some routing differences as well.
Is that even a good idea?
And in the shared code, is there a simple way to know in which case you are? some IF, some directives inactive outside of their context, etc.
It feels like there is some sort of missing link i may be unaware of.
Thanks in advance.
I'm working on this same problem. The approach I'm taking is to use separate templates, and when possible, key CSS off the device detection classes ionic adds to the body tag.
Desktop version (default)
.your-style
Mobile Version
.platform-webview .your-style {...}
.platform-cordova .your-style {...}
There's a repository on on Github that might offer some guidance.
https://github.com/jonathanwax/jw-ionic-desktop
To quote from of the source code from his project, you would create a folder for each view with the mobile version of the template.
For example your bootstrap desktop version of template.html could look like this:
<div class="container">
<h1 class="text-danger" id="helpHeader">Help Needed?</h1>
<li ng-repeat="help in vm.service.data"> {{ help.title }} - {{ help.content }}</li>
</ul>
<pre dir="ltr">HelpController: {{vm|json}}</pre>
And a ionic mobile version of this same template could be located at mobile/template.html
<ion-view view-title="Help">
<ion-content>
<ion-list>
<ion-item ng-repeat="help in vm.service.data">
{{ help.title }} - {{ help.content }}
</ion-item>
</ion-list>
</ion-content>
You could create a conditional to work with your router to serve the mobile template if you're in a cordova/mobile environment. I feel like maintaining two templates could be development hell. Which is why ionic snubs its nose at developing for the desktop--this is hard work! And prone to bugs. It's pretty much a flytrap ( ya know for bugs :) ).
We could try writing templates with conditionals, but I suspect different files may have less overhead.
A conditional approach to templating:
Test for mobile environment
var isMobile = ionic.Platform.isWebView();
In the template or view html:
<{{isMobile ? 'ion-container' : ' div class="container"'}}>
Or a use an ng-switch:
<div ng-switch="expression">
<div ng-switch-when="isMobile">
CODE FOR MOBILE HERE
</div>
<div ng-switch-default>
CODE FOR DESKTOP HERE
</div>
</div>
Depending on your application, you can get away with using ionic directives for most of your desktop application. You can sprinkle in desktop styling when needed. There's really not a huge amount of code that would actually need to be served by a different mobile/desktop template.
Related
I do not know much about web tech and currently, I am planning my own project implementing web app + hybrid mobile app.
Based on my research, it seems many people use bootstrap, on the other hand for mobile, ionic seems one of the most popular ones.
web: bootstrap +
mobile: ionic
While planning it, I met an issue, i.e. how I can combine bootstrap source with ionic and its difficulty, and would it take many steps to modify code and apply for both sides.
So my question is
1. is it easy to combine bootstrap to ionic?
2. Is there widely used tool that is integrated for web and mobile application development?
Thanks in advance.
Bootstrap is meant to be a CSS library for creating responsive web, be it webapp or mobile. You can easily create a webapp using AngularJS as you mention, and let its responsiveness be driven by Bootstrap.
Ionic 1 is meant to be a mobile app development framework, not mobile web. It has got a lot more than just CSS styles; it creates hybrid native apps for Android, Apple and Windows platforms. Though it does just run fine on mobile screens as a webapp.
Ionic 2 has support for webapps so you can easily write your mobile app that can then be deployed either as a native app or on a web server.
Though on both versions of Ionic, you may choose to use Bootstrap for styling your elements but be aware that this won't replace Ionic's own scss. And it might create some unforeseen issues as you've pointed out.
Bootstrap is primarily for webapps running in browsers.
Ionic is targeted to run the applications in a webview using cordova. So, it contains many platform specific stylesheets, properties etc.
1. is it easy to combine bootstrap to ionic?
There is no point of combining both, as IONIC is providing everything you need from bootstrap. ( Element Stylesheets, Common Functions etc ).
2. Is there widely used tool that is integrated for web and mobile application development?
Angular JS is going to help here. You can reuse most of the angular code is both have the same functionality.
For IONIC 1 : You need Angular 1 and IONIC 2 is based on Angular 2.
I was browsing ionic themes and I found a plugin on their pages which showcase their mobile application based on Ionic.
Script
I was wondering where does this script come from and if there is a possibility to do the same on a website to showcase the demo ?
Actually, you don't need any special script to do this.
Just put www folder to your web server and put <iframe> on your website like this to showcase your app demo:
<iframe src="http://www.example.com/myapp/" width="320" height="568"></iframe>
I have got an angular project generated with yeoman/generator-angular with both mobile and desktop views. The mobile templates heavily rely on mobile-angular-ui and it works just fine in development.
For some reason the modals are not displayed after grunt build. Instead, calling a modal would act as if a transparent component was added on top of the page (I mean, with the highest z-index), stealing the focus in the same way that a modal would do. As a consequence, the modal itself is not displayed and the page does not respond to any click event (assuming the fake modal is locking the focus).
The content of my modals is loaded via ng-include directives and it seems to work (from what I can see in the network tool of Chrome). There are no error message complaining about a missing resource in the console and the only thing I can think of is that the code responsible for toggling the modals visibility in mobile-angular-ui was somehow impacted by the build process. Sounds possible?
Any idea of what could cause this difference of behaviour between dev and production?
I am using mobile-angular-ui 1.2.0-beta.11. Feel free to request more information.
Bingo. The problem actually came from a clash between mobile-angular-ui and bootstrap, as I was using both of them for the mobile and desktop views respectively.
Since I use a very limited subset of bootstrap, I decided to remove all my bootstrap dependencies and only work with mobile-angular-ui which also provides a minimalist support for desktop views (namely col-md-xx etc. for responsive layouts).
I don't know about mobile-angular-ui, but in Angular ui-bootstrap you need to include not only the main code but also the templates:
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
When you don't include the tpls, the development is still working, because it's able to load the files from their location in bower_components.
In production you get a similar result as you describe when using modals, because the templates were not bundled in your dist directory. Maybe it's a similar problem?
I'm using Ionic to build a hybrid app for Android and Windows Phone 8.1.
When scrolling, the below code:
<ion-content padding="true" scroll="true" direction="y" scrollbar-y="false" scrollbar-x="false" has-bouncing="true">
<!-- creating many paragraphs -->
<p ng-repeat="content in contents">{{content}}</p> //many paragraph
</ion-content>
is working smoothly in Android, but very laggy in Windows Phone 8.1
I even used overflow-scroll, but it is still too slow.
Please advise me any fix or workaround for this issue.
Thanks in adnvance!
This may not be relevant to you, but I had a similar issue. When using the wp8 platform (e.g. ionic platform add wp8) the app seemed to be wrapped in Silverlight and was painfully slow. Pretty unusable.
Changing to a Windows universal app (ionic platform add windows) it was much, much better (but still has other problems not relevant to this post).
Use native scrolling.
Native scrolling can be enabled using overflow-scroll=”true” on your ion-content or using the $ionicConfigProvider to set it globally in current versions of Ionic.
Has anybody successfully used any of the KendoUI mobile widgets in a Web Application? I have an site using the Kendo Web library. I would like to use the Switch widget from the mobile library.
I've added code like this:
<div id="mobBody" style="width:50px;height:30px">
<input id="wink-switch" data-role="view" />
</div>
I create the widget as normal:
$("#wink-switch").kendoMobileSwitch();
The widget actually works at this point, the problem is it is not presented at all correctly. In order to get it to presnt correctly I need to do:
var switD = document.getElementById("mobBody");
var app = new kendo.mobile.Application(switD); </script>
However this has many undesirable affects on the remainder of the application.
This currently won't work nicely. The Kendo UI Mobile widgets work only in a Kendo UI Mobile application for now. This behaviour is going to change soon though so you could use the switch widget without a mobile application. This feature will land with the Q1 2014 release which is expected in March 2014.