1
1
import appModule = require( "./application-common" ) ;
2
- import dts = require( "application" ) ;
2
+ import definition = require( "application" ) ;
3
3
import frame = require( "ui/frame" ) ;
4
4
import observable = require( "data/observable" ) ;
5
5
import * as typesModule from "utils/types" ;
6
6
import * as fileResolverModule from "file-system/file-name-resolver" ;
7
7
8
8
global . moduleMerge ( appModule , exports ) ;
9
+ var typedExports : typeof definition = exports ;
9
10
10
11
// We are using the exports object for the common events since we merge the appModule with this module's exports, which is what users will receive when require("application") is called;
11
12
// TODO: This is kind of hacky and is "pure JS in TypeScript"
12
13
13
14
var initEvents = function ( ) {
14
- var androidApp : dts . AndroidApplication = exports . android ;
15
15
// TODO: Verify whether the logic for triggerring application-wide events based on Activity callbacks is working properly
16
16
var lifecycleCallbacks = new android . app . Application . ActivityLifecycleCallbacks ( {
17
17
onActivityCreated : function ( activity : any , bundle : any ) {
@@ -22,7 +22,7 @@ var initEvents = function () {
22
22
if ( ! androidApp . startActivity ) {
23
23
androidApp . startActivity = activity ;
24
24
25
- androidApp . notify ( < dts . AndroidActivityBundleEventData > { eventName : "activityCreated" , object : androidApp , activity : activity , bundle : bundle } ) ;
25
+ androidApp . notify ( < definition . AndroidActivityBundleEventData > { eventName : "activityCreated" , object : androidApp , activity : activity , bundle : bundle } ) ;
26
26
27
27
if ( androidApp . onActivityCreated ) {
28
28
androidApp . onActivityCreated ( activity , bundle ) ;
@@ -47,16 +47,16 @@ var initEvents = function () {
47
47
}
48
48
49
49
if ( activity === androidApp . startActivity ) {
50
- if ( exports . onExit ) {
51
- exports . onExit ( ) ;
50
+ if ( typedExports . onExit ) {
51
+ typedExports . onExit ( ) ;
52
52
}
53
53
54
- exports . notify ( < dts . ApplicationEventData > { eventName : dts . exitEvent , object : androidApp , android : activity } ) ;
54
+ typedExports . notify ( < definition . ApplicationEventData > { eventName : typedExports . exitEvent , object : androidApp , android : activity } ) ;
55
55
56
56
androidApp . startActivity = undefined ;
57
57
}
58
58
59
- androidApp . notify ( < dts . AndroidActivityEventData > { eventName : "activityDestroyed" , object : androidApp , activity : activity } ) ;
59
+ androidApp . notify ( < definition . AndroidActivityEventData > { eventName : "activityDestroyed" , object : androidApp , activity : activity } ) ;
60
60
61
61
if ( androidApp . onActivityDestroyed ) {
62
62
androidApp . onActivityDestroyed ( activity ) ;
@@ -71,17 +71,17 @@ var initEvents = function () {
71
71
return ;
72
72
}
73
73
74
- ( < any > androidApp ) . paused = true ;
74
+ androidApp . paused = true ;
75
75
76
76
if ( activity === androidApp . foregroundActivity ) {
77
- if ( exports . onSuspend ) {
78
- exports . onSuspend ( ) ;
77
+ if ( typedExports . onSuspend ) {
78
+ typedExports . onSuspend ( ) ;
79
79
}
80
80
81
- exports . notify ( < dts . ApplicationEventData > { eventName : dts . suspendEvent , object : androidApp , android : activity } ) ;
81
+ typedExports . notify ( < definition . ApplicationEventData > { eventName : typedExports . suspendEvent , object : androidApp , android : activity } ) ;
82
82
}
83
83
84
- androidApp . notify ( < dts . AndroidActivityEventData > { eventName : "activityPaused" , object : androidApp , activity : activity } ) ;
84
+ androidApp . notify ( < definition . AndroidActivityEventData > { eventName : "activityPaused" , object : androidApp , activity : activity } ) ;
85
85
86
86
if ( androidApp . onActivityPaused ) {
87
87
androidApp . onActivityPaused ( activity ) ;
@@ -93,17 +93,17 @@ var initEvents = function () {
93
93
return ;
94
94
}
95
95
96
- ( < any > androidApp ) . paused = false ;
96
+ androidApp . paused = false ;
97
97
98
98
if ( activity === androidApp . foregroundActivity ) {
99
- if ( exports . onResume ) {
100
- exports . onResume ( ) ;
99
+ if ( typedExports . onResume ) {
100
+ typedExports . onResume ( ) ;
101
101
}
102
102
103
- exports . notify ( < dts . ApplicationEventData > { eventName : dts . resumeEvent , object : androidApp , android : activity } ) ;
103
+ typedExports . notify ( < definition . ApplicationEventData > { eventName : typedExports . resumeEvent , object : androidApp , android : activity } ) ;
104
104
}
105
105
106
- androidApp . notify ( < dts . AndroidActivityEventData > { eventName : "activityResumed" , object : androidApp , activity : activity } ) ;
106
+ androidApp . notify ( < definition . AndroidActivityEventData > { eventName : "activityResumed" , object : androidApp , activity : activity } ) ;
107
107
108
108
if ( androidApp . onActivityResumed ) {
109
109
androidApp . onActivityResumed ( activity ) ;
@@ -115,7 +115,7 @@ var initEvents = function () {
115
115
return ;
116
116
}
117
117
118
- androidApp . notify ( < dts . AndroidActivityBundleEventData > { eventName : "saveActivityState" , object : androidApp , activity : activity , bundle : bundle } ) ;
118
+ androidApp . notify ( < definition . AndroidActivityBundleEventData > { eventName : "saveActivityState" , object : androidApp , activity : activity , bundle : bundle } ) ;
119
119
120
120
if ( androidApp . onSaveActivityState ) {
121
121
androidApp . onSaveActivityState ( activity , bundle ) ;
@@ -129,7 +129,7 @@ var initEvents = function () {
129
129
130
130
androidApp . foregroundActivity = activity ;
131
131
132
- androidApp . notify ( < dts . AndroidActivityEventData > { eventName : "activityStarted" , object : androidApp , activity : activity } ) ;
132
+ androidApp . notify ( < definition . AndroidActivityEventData > { eventName : "activityStarted" , object : androidApp , activity : activity } ) ;
133
133
134
134
if ( androidApp . onActivityStarted ) {
135
135
androidApp . onActivityStarted ( activity ) ;
@@ -141,7 +141,7 @@ var initEvents = function () {
141
141
return ;
142
142
}
143
143
144
- androidApp . notify ( < dts . AndroidActivityEventData > { eventName : "activityStopped" , object : androidApp , activity : activity } ) ;
144
+ androidApp . notify ( < definition . AndroidActivityEventData > { eventName : "activityStopped" , object : androidApp , activity : activity } ) ;
145
145
146
146
if ( androidApp . onActivityStopped ) {
147
147
androidApp . onActivityStopped ( activity ) ;
@@ -155,15 +155,15 @@ var initEvents = function () {
155
155
app . init ( {
156
156
getActivity : function ( activity : android . app . Activity ) {
157
157
var intent = activity . getIntent ( )
158
- return exports . android . getActivity ( intent ) ;
158
+ return androidApp . getActivity ( intent ) ;
159
159
} ,
160
160
161
161
onCreate : function ( ) {
162
- exports . android . init ( this ) ;
162
+ androidApp . init ( this ) ;
163
163
}
164
164
} ) ;
165
165
166
- export class AndroidApplication extends observable . Observable implements dts . AndroidApplication {
166
+ export class AndroidApplication extends observable . Observable implements definition . AndroidApplication {
167
167
public static activityCreatedEvent = "activityCreated" ;
168
168
public static activityDestroyedEvent = "activityDestroyed" ;
169
169
public static activityStartedEvent = "activityStarted" ;
@@ -174,6 +174,7 @@ export class AndroidApplication extends observable.Observable implements dts.And
174
174
public static activityResultEvent = "activityResult" ;
175
175
public static activityBackPressedEvent = "activityBackPressed" ;
176
176
177
+ public paused : boolean ;
177
178
public nativeApp : android . app . Application ;
178
179
public context : android . content . Context ;
179
180
public currentContext : android . content . Context ;
@@ -203,11 +204,11 @@ export class AndroidApplication extends observable.Observable implements dts.And
203
204
public getActivity ( intent : android . content . Intent ) : Object {
204
205
if ( intent && intent . getAction ( ) === android . content . Intent . ACTION_MAIN ) {
205
206
// application's main activity
206
- if ( exports . onLaunch ) {
207
- exports . onLaunch ( intent ) ;
207
+ if ( typedExports . onLaunch ) {
208
+ typedExports . onLaunch ( intent ) ;
208
209
}
209
210
210
- exports . notify ( { eventName : dts . launchEvent , object : this , android : intent } ) ;
211
+ typedExports . notify ( { eventName : typedExports . launchEvent , object : this , android : intent } ) ;
211
212
212
213
setupOrientationListener ( this ) ;
213
214
@@ -221,9 +222,9 @@ export class AndroidApplication extends observable.Observable implements dts.And
221
222
var topFrame = frame . topmost ( ) ;
222
223
if ( ! topFrame ) {
223
224
// try to navigate to the mainEntry/Module (if specified)
224
- var navParam = dts . mainEntry ;
225
+ var navParam = typedExports . mainEntry ;
225
226
if ( ! navParam ) {
226
- navParam = dts . mainModule ;
227
+ navParam = typedExports . mainModule ;
227
228
}
228
229
229
230
if ( navParam ) {
@@ -304,25 +305,31 @@ class BroadcastReceiver extends android.content.BroadcastReceiver {
304
305
}
305
306
}
306
307
307
- global . __onUncaughtError = function ( error : Error ) {
308
+ global . __onUncaughtError = function ( error : definition . NativeScriptError ) {
308
309
var types : typeof typesModule = require ( "utils/types" ) ;
309
310
310
311
// TODO: Obsolete this
311
- if ( types . isFunction ( exports . onUncaughtError ) ) {
312
- exports . onUncaughtError ( error ) ;
312
+ if ( types . isFunction ( typedExports . onUncaughtError ) ) {
313
+ typedExports . onUncaughtError ( error ) ;
313
314
}
314
315
315
- exports . notify ( { eventName : dts . uncaughtErrorEvent , object : appModule . android , android : error } ) ;
316
+ typedExports . notify ( { eventName : typedExports . uncaughtErrorEvent , object : appModule . android , android : error } ) ;
316
317
}
317
318
318
- exports . start = function ( entry ?: frame . NavigationEntry ) {
319
- if ( entry ) {
320
- dts . mainEntry = entry ;
319
+ function loadCss ( ) {
320
+ typedExports . cssSelectorsCache = typedExports . loadCss ( typedExports . cssFile ) ;
321
+ }
322
+
323
+ export function start ( entry ?: frame . NavigationEntry ) {
324
+ if ( entry ) {
325
+ typedExports . mainEntry = entry ;
321
326
}
322
- dts . loadCss ( ) ;
327
+ loadCss ( ) ;
323
328
}
324
329
325
- exports . android = new AndroidApplication ( ) ;
330
+ var androidApp = new AndroidApplication ( ) ;
331
+ // use the exports object instead of 'export var' due to global namespace collision
332
+ typedExports . android = androidApp ;
326
333
327
334
var currentOrientation : number ;
328
335
function setupOrientationListener ( androidApp : AndroidApplication ) {
@@ -350,17 +357,17 @@ function onConfigurationChanged(context: android.content.Context, intent: androi
350
357
break ;
351
358
}
352
359
353
- exports . notify ( < dts . OrientationChangedEventData > {
354
- eventName : dts . orientationChangedEvent ,
360
+ typedExports . notify ( < definition . OrientationChangedEventData > {
361
+ eventName : typedExports . orientationChangedEvent ,
355
362
android : context ,
356
363
newValue : newValue ,
357
- object : exports . android ,
364
+ object : typedExports . android ,
358
365
} ) ;
359
366
}
360
367
}
361
368
362
369
global . __onLiveSync = function ( ) {
363
- if ( exports . android && exports . android . paused ) {
370
+ if ( typedExports . android && typedExports . android . paused ) {
364
371
return ;
365
372
}
366
373
@@ -370,7 +377,7 @@ global.__onLiveSync = function () {
370
377
fileResolver . clearCache ( ) ;
371
378
372
379
// Reload app.css in case it was changed.
373
- appModule . loadCss ( ) ;
380
+ loadCss ( ) ;
374
381
375
382
// Reload current page.
376
383
frame . reloadPage ( ) ;
0 commit comments