Yesterday I have started developing my first Metro style App using JavaScript.
I've used one of those templates in Visual Studio 2011. This project template comes with a bunch of generated code which relies heavily on WinJS. The whole structure reminds of the ASP.NET with its Views and corresponding Code Behind files. There is also a navigator.js file which is responsible for the navigation between the Views. The whole data resides in the data.js and can be retrieved using different functions.
I worked with backbone.js and I found its concepts like MVC structure and routing pretty cool. My question is basically if you can implement such a Metro style App using backbone.js?
Can I eliminate WinJS and just start from scratch? Should I try to integrate backbone.js into the current structure? What would it look like then? Are there any restrictions for using third party JavaScript frameworks? Should I leave the generated structure as it is?
What are the best practices and patterns developing Metro Style Apps with JavaScript?
Thanks
You can use any JavaScript framework you like within a Metro-style JavaScript application. See this related question about jQuery:
jQuery and Windows 8 JavaScript Metro Style Apps
The WinJS framework performs a couple of functions, the first is a set of non-UI APIs for managing and manipulating data, making service requests etc ... These are easily replaced with other JavaScript frameworks. The second is the UI layer, here you might struggle a bit. The WinJS UI has been designed to follow the Metro Design Language. If you replace it with your own UI layer (using jQuery UI for example) your application will just not look right.
Personally I would use WinJS for the UI layer and to integrate with the runtime (state persistance, app switching etc...), but use a more standard JavaScript library, such as Backbone or Knockout for the bulk of my code to ensure portability.
I use Knockout js and Require js for MVVM. For visual effects, I use jQuery.
My data-main looks like a bit this:
(function () {
"use strict";
var app = WinJS.Application;
app.onactivated = function (eventObject) {
require(["/scripts/knockout"], function(ko){
// My knockout viewModel and data binding goes here
});
};
app.start();
})();
If you prefer Backbone in stead, I guess the setup would be similar.
Related
Some cross-platform tools (like Xamarin native and RubyMotion) allow the development of two separate views for Android and iOS, while keeping the business logic shared for both of them. Others (like Apache Cordova or Xamarin.Forms) share both UI and business layer, with the option to use platform-specific overrides when necessary.
What is the state of the interpreted JavaScript frameworks (NativeScript, React Native or Appcelerator)? Are they all focused on creating single UI with platform overrides, or do they allow creating two separate views for each platform? For example, is it possible to create a view using Fragments in Android, but a different view on iOS (since Fragments do not exist there)?
Cordova uses WebView, that mean GUI level will be the same for both Android and iOS but different per Device version. In case of Android each client has own Chronium version and it can break UI behaviour. So developers use Crosswalk to set fixed Chronium version. (extra 20M to your application).
BTW Ionic that uses Cordova architecture uses native behaviour per platform. For example for Android Tabs located at the top, on iOS - at the bottom
On other hand Xamarin (C#), React-Native(JS) and NativeScript(JS) call native APIs. They don't use WebView but generate Native code.
For example if you create button - it will look different: on Android - material theme, on iOS - iPhone theme
Anyways, the bottom line is: everything depends on resources and time. If you want to build application fast, with the same view - I would go on Ionic2+ Angular2 + Cordova.
If you you have more time - go on React-Native or NativeScript (Still has poor documentation) or Xamarin (C#).
React-native's slogan is Learn once, write everywhere. So, you can choose what suits your needs, you can:
Share UI between platforms.
Share Only business logic.
So, the answer for react-native is yes. You can create separate UIs or you can share it.
Since you are writing components, one way of separating this logic is to write component.android.js and component.ios.js and the platform loads the appropriate one for you. Note that you can also do that programmatically.
You can see that in action in the official f8 app made by facebook using react-native
I'm new to Appcelerator Titanium, so one of the considerations that popped into my mind was this: how do I create reusable custom controls for use in Alloy? Take for example in Android:
The ColorPicker is a 3rd-party library that allows me to add it as a control to the .xml file so long as I reference the library. I would also be able to create my own controls and either reuse them locally or distribute them as an external library. Is there a similar concept for Titanium, more specifically for Alloy (i.e. the xml and all)?
Yes there is the concept of creating widgets and which can be reused locally in the projects. There are alot of widgets already available.
One of the important widgets for creation of the application Font Awsome Widget.
You can see the source code as well and check its implementation.
I am hesitant to develop a Windows Phone app in the HTML/WinJS Universal App space because of the difficulty of building complex user controls. Before I go the XAML/C# route, I would like to find out if it is possible to use a user control built in XAML/C# inside of an HTML/WinJS view?
My initial feeling is that it is not possible due to XAML parsing not being available in the HTML space, but I am not certain that this is the case. Any thoughts?
Also, I am not interested in 3rd party solutions such as Xamerin. I am really trying to see if this is possible from a native approach.
No. The HTML and Xaml UI stacks in the Windows Runtime are separate and cannot be mixed. You can call non-UI C# or native Windows Runtime Components from JavaScript.
You can include HTML in a Xaml WebView, but there is no reverse hosting.
--Rob
I'm trying out the mobile pattern, and have been trying to crate my own custom pattern that is now supposedly supported in Worklight 6.1.
When I tried creating jquery UI pattern, several issues:
1. The rich page editor for the pattern.html does not display the jquery component correctly on the design page (e.g button is displayed as link).
2. When I added a new page (into a jquery hybrid app) based on the custom UI pattern, it does not create a new page. It only adds the content code into the index.html, and I had to create the page myself.
Is this the correct behaviour?
I'm also having difficulty in creating Dojo UI pattern… as there is no Dojo component available on the palette when I open up the dojo > pattern.html file.
Do I have to add the libraries and code manually (i.e. no Drag-and-Drop)?
Appreciate any pointers on this.
PS: I'm using Eclipse Juno R2
1) For jQuery based patterns you need to append a jQuery core file to the project besides the jQuery mobile ones, for example, append this one: http://code.jquery.com/jquery-1.10.2.js to your project, next to jquery mobile JS file. This is just because "UI Pattern" projects don't have this file available, but they need it to handle a proper preview.
2) For Dojo patterns, there is still no official support (for example Drag and drop), so even you can modify pattern.html to get some "insertable" code, you may still need some additional tuning to get a valid pattern.
Implementation of state handling in windows 8 using mvvmlight
Is there any method avilable in mvvmligt to manage states in WinRT? How I can duplicate the functionality of default Suspensionmanager by using WinRT? And the second one is about managing navigation cycle ie if I navigated from page A - > B. and the go for suspend and shutdown state. When I re start the application in need to open page B. and while presses back key I need to load A. How I can effectively implement this using MVVM light in my WinRT application?
These aren't really MVVM Light functionality. You'll need to do these yourself.
One option would be to create your own navigation service (see example here). The navigation service could use the suspension manager to build/manage a breadcrumb trail for the application. If you added an additional method:
public void GoToMostRecentPage()
{//blah}
You'd be able to call this method in the app start-up and take the user to the appropriate page.
I'd stick with the SuspensionManager. If you want to make it more MVVM friendly you can wrap it in a service that is injected into your viewmodels as required.
You might be interested in the open-source Okra App Framework that you can get from NuGet or the CodePlex site I linked to above. It is designed from the ground up to work great with Windows 8 and the MVVM pattern (and you can still use your MVVM Light base classes).
It has a navigation manager that automatically handles everything you mentioned above - managing the application's navigation stack, persistence of the stack on application suspension/termination and even allows view models to persist their own state via a simple interface (like how the SuspensionManager works for pages).
(disclaimer: I am the lead developer on this project)
I wrote this originally for WP7 and have been updating for Win8 RT. It allows you to attach attributes to properties you want to keep in your view models, then the PersistenceManager dehydrates them (serialized to file) when the app is suspended and rehydrates when it resumes.
There are examples for WP7 and Win8, basic MVVM pattern and MVVM Light
Obelisk