Noodlecode parody of spaghetti code

Use view from custom module inside Titanium ListViewItem

Most 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: {}
}

Categories: Notes

Add project as library – Titanium module (Android) » « Avidemux

4 Comments

  1. 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.

  2. So, this could/should work with e.g. Styled Label?

  3. 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

  4. 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.

Leave a Reply

Your email address will not be published.

*

Copyright © 2017 Noodlecode