Use view from custom module inside Titanium ListViewItem
On 24 April 2014 in TechMost example I found on how to create view inside ListViewItem are using Titanium views itself (those from Ti.UI namespace). This post shows how to use views from other modules. For example, I’m using canvas view module, TiAndroidCanvas (Android) and ti.canvas (iOS)
Updated:
In order for ListView to use the custom module, listview.js need to be able to access the JS variable pointing to the module, and invoke the create* method to create the view instance. So, instead of using try-and-error method as shown previously, just assign your require()-ed module to global scope
Android example:
global.CanvasModule = require('com.wwl.canvas'); // template { type: 'CanvasModule.CanvasView' }
(therefore, listview.js will invoke CanvasModule.createCanvasView()
to create the view instance)
iOS example:
global.CanvasModule = require('ti.canvas'); // template { type: 'CanvasModule.View' }
(therefore, listview.js will invoke CanvasModule.createView()
to create the view instance)
Android
Include the module into global variable, then in ListItemTemplate, assign using the view’s class name (in Java source code, the class that inherits TiViewProxy, without -Proxy suffix)
var Canvas = require('com.wwl.canvas'); // in template { type: 'Canvas.CanvasView', properties: {}, events: {} }
iOS
No need to include the module, but in ListItemTemplate, assign using the actual view proxy class name in Objective-C code.
// in template { type: 'TiCanvasView', properties: {}, events: {} }
Related posts:
-
Add project as library – Titanium module (Android)
-
Enable x86 libs in production build Titanium app
-
Creating [object] in a different context than the calling function.
-
Titanium app hex color value with alpha channel
-
Android Progress Notification module
-
Android Popup Menu module for Titanium
-
Object oriented Javascript with CommonJS in Titanium app
-
Flurry Android 3.2.0 SDK for Titanium module
-
Titanium Studio mark occurences
-
Efficient code
Filed under Tech with tags ListView, Titanium Mobile, Titanium Module
Hi, my developer center question is thar
http://developer.appcelerator.com/question/176076/using-module-with-listview-template
I haven’t found any solution about that. Could you help me please?
Thank you in advance.
So, this could/should work with e.g. Styled Label?
I see you share interesting content here, you can earn some
additional cash, your blog has huge potential, for the monetizing
method, just type in google – K2 advices how to monetize a website
Does this work in Alloy to? I tried to use this method with a module of my own but not really sure where to put the ‘global.* = *’ part.
global.Mocean = require(‘nl.g23.mocean’);
No matter where I put this code it gives me an error that global is undefined.