forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.d.ts
More file actions
425 lines (358 loc) · 15.6 KB
/
view.d.ts
File metadata and controls
425 lines (358 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
declare module "ui/core/view" {
import style = require("ui/styling");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
import gestures = require("ui/gestures");
/**
* Gets a child view by id.
* @param view - The parent (container) view of the view to look for.
* @param id - The id of the view to look for.
* Returns an instance of a view (if found), otherwise undefined.
*/
export function getViewById(view: View, id: string): View;
/**
* Iterates through all child views (via visual tree) and executes a function.
* @param view - Starting view (parent container).
* @param callback - A function to execute on every child. If function returns false it breaks the iteration.
*/
export function eachDescendant(view: View, callback: (child: View) => boolean);
/**
* Gets an ancestor from a given type.
* @param view - Starting view (child view).
* @param typeName - The type name of the parent container which is looking for.
* Returns an instance of a view (if found), otherwise undefined.
*/
export function getAncestor(view: View, typeName: string): View;
/**
* Defines an enum with events for view class.
*/
module knownEvents {
/**
* Raised when the view is added to visual tree and loaded (shown).
*/
export var loaded: string;
/**
* Raised when the view is unloaded.
*/
export var unloaded: string;
}
/**
* Defines interface for an optional parameter used to create a view.
*/
export interface Options {
/**
* Gets or sets the desired width of the view.
*/
width?: number;
/**
* Gets or sets the desired height of the view.
*/
height?: number;
/**
* Gets or sets the minimum width the view may grow to.
*/
minWidth?: number;
/**
* Gets or sets the minimum height the view may grow to.
*/
minHeight?: number;
/**
* Gets or sets the alignment of this view within its parent along the Horizontal axis.
*/
horizontalAlignment?: string;
/**
* Gets or sets the alignment of this view within its parent along the Vertical axis.
*/
verticalAlignment?: string;
/**
* Specifies extra space on the left side of this view.
*/
marginLeft: number;
/**
* Specifies extra space on the top side of this view.
*/
marginTop: number;
/**
* Specifies extra space on the right side of this view.
*/
marginRight: number;
/**
* Specifies extra space on the bottom side of this view.
*/
marginBottom: number;
/**
* Gets or sets the visibility of this view.
*/
visibility?: string;
/**
* Gets or sets the CSS class of this view.
*/
cssClass?: string;
/**
* Gets or sets the id of this view.
*/
id?: string;
}
/**
* This class is the base class for all UI components.
* A View occupies a rectangular area on the screen and is responsible for drawing and layouting of all UI components within.
*/
export class View extends proxy.ProxyObject implements ApplyXmlAttributes {
/**
* Represents the observable property backing the id property of each View.
*/
public static idProperty: dependencyObservable.Property;
/**
* Represents the observable property backing the cssClass property of each View.
*/
public static cssClassProperty: dependencyObservable.Property;
public static isEnabledProperty: dependencyObservable.Property;
public static isUserInteractionEnabledProperty: dependencyObservable.Property;
constructor(options?: Options);
/**
* Gets or sets the desired width of the view.
*/
width: number;
/**
* Gets or sets the desired height of the view.
*/
height: number;
/**
* Gets or sets the minimum width the view may grow to.
*/
minWidth: number;
/**
* Gets or sets the minimum height the view may grow to.
*/
minHeight: number;
/**
* Gets or sets the alignment of this view within its parent along the Horizontal axis.
*/
horizontalAlignment: string;
/**
* Gets or sets the alignment of this view within its parent along the Vertical axis.
*/
verticalAlignment: string;
/**
* Specifies extra space on the left side of this view.
*/
marginLeft: number;
/**
* Specifies extra space on the top side of this view.
*/
marginTop: number;
/**
* Specifies extra space on the right side of this view.
*/
marginRight: number;
/**
* Specifies extra space on the bottom side of this view.
*/
marginBottom: number;
/**
* Gets or sets the visibility of the view.
*/
visibility: string;
/**
* Gets or sets a value indicating whether the the view is enabled. This affects the appearance of the view.
*/
isEnabled: boolean;
/**
* Gets or sets a value indicating whether the user can interact with the view. This does not affect the appearance of the view.
*/
isUserInteractionEnabled: boolean;
/**
* Gets or sets the id for this view.
*/
id: string;
/**
* Gets or sets the CSS class for this view.
*/
cssClass: string;
/**
* Gets the style object associated to this view.
*/
style: style.Style;
/**
* Gets the View instance that parents this view. This property is read-only.
*/
parent: View;
/**
* Gets is layout is valid. This is read-only property.
*/
isLayoutValid: boolean;
cssType: string;
visualState: string;
/**
* This is called to find out how big a view should be. The parent supplies constraint information in the width and height parameters.
* The actual measurement work of a view is performed in onMeasure(int, int), called by this method. Therefore, only onMeasure(int, int) can and must be overridden by subclasses.
* @param widthMeasureSpec Horizontal space requirements as imposed by the parent
* @param heightMeasureSpec Vertical space requirements as imposed by the parent
*/
public measure(widthMeasureSpec: number, heightMeasureSpec: number): void;
/**
* Assign a size and position to a view and all of its descendants
* This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().
* Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children.
* @param l Left position, relative to parent
* @param t Top position, relative to parent
* @param r Right position, relative to parent
* @param b Bottom position, relative to parent
*/
public layout(left: number, top: number, right: number, bottom: number): void;
/**
* Returns the raw width component.
*/
public getMeasuredWidth(): number;
/**
* Returns the raw height component.
*/
public getMeasuredHeight(): number;
/**
* Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree.
*/
public requestLayout(): void;
/**
* Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.
* When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an exception, thrown by measure(int, int).
* @param widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
* @param heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
*/
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;
/**
* Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
* @param left Left position, relative to parent
* @param top Top position, relative to parent
* @param right Right position, relative to parent
* @param bottom Bottom position, relative to parent
*/
public onLayout(left: number, top: number, right: number, bottom: number): void;
/**
* This method must be called by onMeasure(int, int) to store the measured width and measured height. Failing to do so will trigger an exception at measurement time.
* @param measuredWidth The measured width of this view. May be a complex bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.
* @param measuredHeight The measured height of this view. May be a complex bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.
*/
public setMeasuredDimension(measuredWidth: number, measuredHeight: number): void;
public layoutNativeView(left: number, top: number, right: number, bottom: number): void;
public static measureChild(parent: View, child: View, widthMeasureSpec: number, heightMeasureSpec: number): { measuredWidth: number; measuredHeight: number };
public static layoutChild(parent: View, child: View, left: number, top: number, right: number, bottom: number): void;
/**
* Utility to reconcile a desired size and state, with constraints imposed
* by a MeasureSpec. Will take the desired size, unless a different size
* is imposed by the constraints. The returned value is a compound integer,
* with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and
* optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting
* size is smaller than the size the view wants to be.
*/
public static resolveSizeAndState(size: number, specSize: number, specMode: number, childMeasuredState: number): number;
/**
* Returns the child view with the specified id.
*/
getViewById<T extends View>(id: string): T;
/**
* Tries to focus the view.
* Returns a value indicating whether this view or one of its descendants actually took focus.
*/
public focus(): boolean;
observe(type: number, callback: (args: gestures.GestureEventData) => void): gestures.GesturesObserver;
// Lifecycle events
onLoaded(): void;
onUnloaded(): void;
isLoaded: boolean;
/**
* Called for every attribute in xml declaration. <... fontAttributes="bold" ../>
* @param attributeName - the name of the attribute (fontAttributes)
* @param attrValue - the value of the attribute (bold)
* Should return true if this attribute is handled and there is no need default handler to process it.
*/
applyXmlAttribute(attributeName: string, attrValue: any): boolean;
// TODO: Implement logic for stripping these lines out
//@private
_domId: number;
_cssClasses: Array<string>;
_isAddedToNativeVisualTree: boolean;
_addView(view: View);
_removeView(view: View);
/**
* Performs the core logic of adding a child view to the native visual tree. Returns true if the view's native representation has been successfully added, false otherwise.
*/
_addViewToNativeVisualTree(view: View): boolean;
_removeViewFromNativeVisualTree(view: View): void;
_eachChildView(callback: (child: View) => boolean);
_childrenCount: number;
_context: android.content.Context;
_onAttached(context: android.content.Context): void;
_onContextChanged(): void;
_onDetached(force?: boolean): void;
_createUI(): void;
_prepareNativeView(view: UIView);
_checkMetadataOnPropertyChanged(metadata: dependencyObservable.PropertyMetadata);
_updateLayout(): void;
/**
* Called my measure method to cache measureSpecs.
*/
_setCurrentMeasureSpecs(widthMeasureSpec: number, heightMeasureSpec: number): boolean;
/**
* Returns view measureSpecs.
*/
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number };
/**
* Called my layout method to cache view bounds.
*/
_setCurrentLayoutBounds(left: number, top: number, right: number, bottom: number): void;
/**
* Return view bounds.
*/
_getCurrentLayoutBounds(): { left: number; top: number; right: number; bottom: number };
_goToVisualState(state: string);
_nativeView: any;
_isVisible: boolean;
//@endprivate
}
/**
* Base class for all UI components that implements custom layouts.
*/
export class CustomLayoutView extends View {
}
//@private
export class NativeViewGroup extends android.view.ViewGroup {
constructor(context: android.content.Context);
public setOwner(view: View);
}
//@endprivate
/**
* Defines an interface for adding arrays declared in xml.
*/
interface AddArrayFromBuilder {
/**
* A function that is called when an array declaration is found in xml.
* @param name - Name of the array.
* @param value - The actual value of the array.
*/
_addArrayFromBuilder(name: string, value: Array<any>): void;
}
/**
* Defines an interface for adding a child element declared in xml.
*/
interface AddChildFromBuilder {
/**
* Called for every child element declared in xml.
* This function will create an instance of declared child element.
* @param name - Name of the element.
* @param value - Value of the element.
*/
_addChildFromBuilder(name: string, value: any): void;
}
/**
* Defines an interface used to create a member of a class from string representation (used in xml declaration).
*/
interface ApplyXmlAttributes {
/**
* Called for every attribute in xml declaration. <... fontAttributes="bold" ../>
* @param attributeName - the name of the attribute (fontAttributes)
* @param attrValue - the value of the attribute (bold)
* Should return true if this attribute is handled and there is no need default handler to process it.
*/
applyXmlAttribute(attributeName: string, attrValue: any): boolean;
}
}