javascript - Modifying widgets in an alloy project -


I have a widget that is a photo gallery. This basic functionality means that it only allows users to click on the thumbnails. And then extends expansion / extension on an onclick event.

I need to expand the widget so that there is a button that lets the user change their profile picture accordingly (if they select that photo).

Here's how widget looks in widget.js by default:

  var topView = Ti.UI. CreateView ({width: Ti.UI.FILL, height: Ti. UIFill, Xindex: 1200, view: wrong}); // This image gets, it combines the top view var imgView = Ti.UI.createImageView ({image: url, width: Ti.UI.SIZE, height: Ti.UI.SIZE}); // add it to topView.add (imgView);  

To add a button now, I can add the following widget.js:

  var button = titanium.u.create button ({title: 'Use picture, top: 10, width: 100, height: 50}); button. AddEventListener ('click', function (e) {Alloy.Global.Image = url;}); TopView.add (button);  

This will close the popup and return the URL of the image inside a global variable. Then I can use it and call my picture in new controller and I can turn it into new one.

The question is what is the best way to expand the widget.js code and using global variables? What is the best way to do this?

What I often do with custom widgets is adding a callback, so that you return the value directly Able to

widget.xml

  & lt; Alloys & gt; & Lt; Button title = "click me!" OnTouchend = "Button Tweet" /> & Lt; / Alloy & gt;  

widget.js

  // Click this on our callback clickback; // button clicked, call callback function button clicked (e) {ifof (onClickCallback) === 'function') {onClickCallback ({type: 'clicked!'}); }}} // Click on our callback function (callback) {onClickCallback = callback; } // export the onclick function public. OnClick = onClick;  

index.xml

& lt; Alloys & gt; & Lt; Window & gt; & Lt; Widget id = "myWidget" src = "myWidget" /> & Lt; / Window & gt; & Lt; / Alloy & gt;

index.js

  // Now we can stop clicks under the widget and the values ​​passed from $ You can use .myWidget.onClick (function (e) {warning (e.type);});  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -