Last active
January 30, 2019 13:12
-
-
Save MotiurRahman/7f61081d21cb9131da18596a1281b1c8 to your computer and use it in GitHub Desktop.
Simple commonJS pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // place this file to the lib folder | |
| function alertDialog() { | |
| var win1 = Titanium.UI.createWindow({ | |
| title: 'Tab 1', | |
| backgroundColor: '#ccc', | |
| layout: "vertical" | |
| }); | |
| // Create a Button. | |
| var aButton = Ti.UI.createButton({ | |
| title: 'aButton', | |
| height: Ti.UI.SIZE, | |
| //systemButton: Ti.UI.iOS.SystemButton.CANCEL, | |
| width: Ti.UI.SIZE, | |
| }); | |
| var textField = Ti.UI.createTextField({ | |
| borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, | |
| color: '#336699', | |
| top: 20, | |
| left: 10, | |
| clipMode: Titanium.UI.iOS.CLIP_MODE_ENABLED, | |
| width: 300, | |
| height: 60 | |
| }); | |
| // Listen for click events. | |
| aButton.addEventListener('click', function() { | |
| var alertDialog = Titanium.UI.createAlertDialog({ | |
| message: 'MESSAGE', | |
| buttonNames: ["OK", "Cancel"], | |
| persistent: false, | |
| canceledOnTouchOutside: false, | |
| }); | |
| alertDialog.show(); | |
| }); | |
| // Add to the parent view. | |
| win1.add(aButton); | |
| win1.add(textField); | |
| return win1; | |
| } | |
| module.exports = alertDialog; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var win = Ti.UI.createWindow({ | |
| barColor: "#800000", | |
| layout: "vertical", | |
| }); | |
| // Create a Button. | |
| var btn1 = Ti.UI.createButton({ | |
| title: 'Open Another Win', | |
| height: 100, | |
| width: 100, | |
| top: 50 | |
| }); | |
| btn1.addEventListener('click', function(e) { | |
| var nextPage = require('lib/alertDialog'); | |
| var Next_win = new nextPage(); | |
| Next_win.open(); | |
| }); | |
| var mainPage = require('lib/main'); | |
| mainPage.sayHello(); | |
| mainPage.helloWorld() | |
| Ti.API.info("testResult:"+mainPage.testResult); | |
| win.add(btn1); | |
| win.open(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var defaultMessage = "Hello world"; | |
| // we make objects, variables, functions available to the | |
| // calling context by adding them to the exports object | |
| exports.sayHello = function(msg) { | |
| alert('Hello '+msg); | |
| }; | |
| // we can assign other objects, functions, and variables to | |
| // exports and they will be available to the calling context | |
| exports.helloWorld = function() { | |
| Ti.API.info(defaultMessage); | |
| }; | |
| exports.testResult = "This is for testing"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment