Skip to content

Commit bb63489

Browse files
committed
feat(docgen): add @types/titanium template
Signed-off-by: Sergey Volkov <[email protected]>
1 parent 641ce10 commit bb63489

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Build
2+
3+
> node bin/docgen.js --format typescript <PATH_TO_TI_SDK/apidoc/>
4+
5+
# Publish
6+
7+
Follow the [instructions](https://github.com/DefinitelyTyped/DefinitelyTyped#how-can-i-contribute)
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
function test_window() {
2+
const window: Titanium.UI.Window = Ti.UI.createWindow({
3+
title: 'Test',
4+
backgroundColor: 'white',
5+
borderRadius: 10
6+
});
7+
8+
window.backgroundColor = 'blue';
9+
window.opacity = 0.92;
10+
11+
const matrix = Ti.UI.create2DMatrix().scale(1.1, 1);
12+
window.transform = matrix;
13+
14+
let label: Titanium.UI.Label;
15+
label = Ti.UI.createLabel({
16+
color: '#900',
17+
text: 'Simple label'
18+
});
19+
label.textAlign = Ti.UI.TEXT_ALIGNMENT_LEFT;
20+
label.width = Ti.UI.SIZE;
21+
label.height = Ti.UI.SIZE;
22+
window.add(label);
23+
window.open();
24+
}
25+
26+
function test_tableview() {
27+
const data: Titanium.UI.TableViewRow[] = [];
28+
for (let i = 0; i < 10; i++) {
29+
const row = Ti.UI.createTableViewRow();
30+
const label = Ti.UI.createLabel({
31+
left: 10,
32+
text: 'Row ' + (i + 1)
33+
});
34+
const image = Ti.UI.createImageView({
35+
image: 'KS_nav_ui.png'
36+
});
37+
const button = Ti.UI.createButton({
38+
right: 10,
39+
height: 30,
40+
width: 80,
41+
title: 'Button example'
42+
});
43+
row.add(label);
44+
row.add(image);
45+
row.add(button);
46+
data.push(row);
47+
}
48+
const table = Ti.UI.createTableView({
49+
data,
50+
style: Ti.UI.iOS.TableViewStyle.PLAIN
51+
});
52+
}
53+
54+
function test_fs() {
55+
let imageDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + 'downloaded_images');
56+
if (!imageDir.exists()) {
57+
imageDir.createDirectory();
58+
}
59+
let data: Titanium.Blob; // tslint:disable-line:prefer-const
60+
let imageFile = Ti.Filesystem.getFile(imageDir.resolve() + 'image.jpg');
61+
if (!imageFile.write(data)) {
62+
Ti.UI.createAlertDialog({
63+
message: 'IO Error'
64+
}).show();
65+
}
66+
imageFile = null;
67+
imageDir = null;
68+
}
69+
70+
function test_network() {
71+
const url = 'https://www.appcelerator.com';
72+
const client = Ti.Network.createHTTPClient({
73+
// function called when the response data is available
74+
onload: (e: SuccessResponse) => {
75+
alert(this.responseText);
76+
},
77+
// function called when an error occurs, including a timeout
78+
onerror: (e: FailureResponse) => {
79+
alert(e.error);
80+
},
81+
timeout: 5000 // in milliseconds
82+
});
83+
// Prepare the connection.
84+
client.open('GET', url);
85+
// Send the request.
86+
client.send();
87+
}
88+
89+
function test_android_r() {
90+
const systemIcon = Ti.Android.R.drawable.icon;
91+
const appIcon = Ti.App.Android.R.drawable.icon;
92+
}
93+
94+
function test_events() {
95+
const view = Ti.UI.createView();
96+
view.addEventListener('click', e => {
97+
console.log(e.x, e.y);
98+
});
99+
view.fireEvent('click');
100+
}
101+
102+
function test_listdataitem() {
103+
const items1: ListDataItem[] = [
104+
{
105+
properties: {
106+
itemId: 'test',
107+
title: 'Jon Doe'
108+
}
109+
}
110+
];
111+
const section1 = Ti.UI.createListSection({
112+
items: items1
113+
});
114+
115+
const template = {
116+
childTemplates: [
117+
{
118+
type: 'Ti.UI.Label',
119+
bindId: 'title',
120+
properties: {
121+
color: 'black'
122+
}
123+
}
124+
]
125+
};
126+
const items2: ListDataItem[] = [
127+
{
128+
template: 'custom',
129+
title: { text: 'Jane Doe' },
130+
properties: {
131+
accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE
132+
}
133+
}
134+
];
135+
const section2 = Ti.UI.createListSection({
136+
items: items2,
137+
});
138+
139+
const list = Ti.UI.createListView({
140+
templates: { custom: template },
141+
sections: [section1]
142+
});
143+
list.replaceSectionAt(0, section2);
144+
}
145+
146+
function test_globals() {
147+
if (OS_ANDROID) {
148+
console.log('Device runs Android');
149+
}
150+
if (ENV_DEVELOPMENT) {
151+
console.log('App was built for development');
152+
}
153+
setTimeout(() => {
154+
console.log(global.L('greeting', 'Localized greeting'));
155+
}, 200);
156+
}
157+
158+
function test_string_extension() {
159+
String.formatCurrency(3.99);
160+
String.formatDate(new Date(), 'long');
161+
String.formatDecimal(12.04, '%d');
162+
String.formatDecimal(12.04, 'en-US', '%d');
163+
String.formatTime(new Date(), 'medium');
164+
}
165+
166+
function test_media() {
167+
Ti.Media.openPhotoGallery({
168+
allowMultiple: true,
169+
success: (result: CameraMediaMultipleItemsType) => {
170+
console.log(`Selected ${result.images.length} photos!`);
171+
}
172+
});
173+
}
174+
175+
async function test_permissions() {
176+
const result: RequestPermissionAccessResult = await Ti.Android.requestPermissions('SOME_PERMISSION');
177+
console.log(result.success);
178+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es5"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": false,
9+
"strictNullChecks": false,
10+
"strictFunctionTypes": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"titanium-tests.ts"
22+
]
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "@definitelytyped/dtslint/dt.json",
3+
"rules": {
4+
"max-line-length": false,
5+
"no-empty-interface": false,
6+
"no-padding": false,
7+
"no-single-declare-module": false,
8+
"no-unnecessary-qualifier": false,
9+
"unified-signatures": false
10+
}
11+
}

0 commit comments

Comments
 (0)