imports improved

This commit is contained in:
Vladimir Enchev
2015-12-14 17:08:24 +02:00
parent cbf69e60e8
commit 074ac89871
90 changed files with 529 additions and 266 deletions

View File

@@ -1,9 +1,9 @@
require("globals");
import definition = require("application");
import fs = require("file-system");
import styleScope = require("ui/styling/style-scope");
import observable = require("data/observable");
import frame = require("ui/frame");
import * as fileSystemModule from "file-system";
import * as styleScopeModule from "ui/styling/style-scope";
var events = new observable.Observable();
global.moduleMerge(events, exports);
@@ -41,6 +41,9 @@ export var ios = undefined;
export function loadCss() {
if (definition.cssFile) {
var fs: typeof fileSystemModule = require("file-system");
var styleScope: typeof styleScopeModule = require("ui/styling/style-scope");
var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, definition.cssFile);
if (fs.File.exists(cssFileName)) {
var file = fs.File.fromPath(cssFileName);

View File

@@ -1,10 +1,9 @@
import appModule = require("./application-common");
import dts = require("application");
import frame = require("ui/frame");
import types = require("utils/types");
import observable = require("data/observable");
import enums = require("ui/enums");
import fileResolverModule = require("file-system/file-name-resolver");
import * as typesModule from "utils/types";
import * as fileResolverModule from "file-system/file-name-resolver";
global.moduleMerge(appModule, exports);
@@ -306,6 +305,8 @@ class BroadcastReceiver extends android.content.BroadcastReceiver {
}
global.__onUncaughtError = function (error: Error) {
var types: typeof typesModule = require("utils/types");
// TODO: Obsolete this
if (types.isFunction(exports.onUncaughtError)) {
exports.onUncaughtError(error);
@@ -331,6 +332,8 @@ function onConfigurationChanged(context: android.content.Context, intent: androi
if (currentOrientation !== orientation) {
currentOrientation = orientation;
var enums = require("ui/enums");
var newValue;
switch (orientation) {
case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
@@ -344,7 +347,7 @@ function onConfigurationChanged(context: android.content.Context, intent: androi
break;
}
exports.notify(<dts.OrientationChangedEventData> {
exports.notify(<dts.OrientationChangedEventData>{
eventName: dts.orientationChangedEvent,
android: context,
newValue: newValue,
@@ -358,8 +361,10 @@ global.__onLiveSync = function () {
return;
}
var fileResolver: typeof fileResolverModule = require("file-system/file-name-resolver");
// Clear file resolver cache to respect newly added files.
fileResolverModule.clearCache();
fileResolver.clearCache();
// Reload app.css in case it was changed.
appModule.loadCss();

View File

@@ -1,13 +1,12 @@
import appModule = require("./application-common");
import common = require("./application-common");
import frame = require("ui/frame");
import types = require("utils/types");
import view = require("ui/core/view");
import definition = require("application");
import enums = require("ui/enums");
import uiUtils = require("ui/utils");
import fileResolverModule = require("file-system/file-name-resolver");
import * as uiUtilsModule from "ui/utils";
import * as typesModule from "utils/types";
import * as fileResolverModule from "file-system/file-name-resolver";
import * as enumsModule from "ui/enums";
global.moduleMerge(appModule, exports);
global.moduleMerge(common, exports);
class Responder extends UIResponder {
//
@@ -15,7 +14,7 @@ class Responder extends UIResponder {
class Window extends UIWindow {
private _content: view.View;
private _content;
initWithFrame(frame: CGRect): UIWindow {
var window = super.initWithFrame(frame);
@@ -25,14 +24,16 @@ class Window extends UIWindow {
return window;
}
public get content(): view.View {
public get content() {
return this._content;
}
public set content(value: view.View) {
public set content(value) {
this._content = value;
}
public layoutSubviews(): void {
var uiUtils: typeof uiUtilsModule = require("ui/utils");
uiUtils.ios._layoutRootView(this._content, UIScreen.mainScreen().bounds);
}
}
@@ -113,7 +114,7 @@ class IOSApplication implements definition.iOSApplication {
}
exports.notify({
eventName: definition.launchEvent,
eventName: exports.launchEvent,
object: this,
ios: notification.userInfo && notification.userInfo.objectForKey("UIApplicationLaunchOptionsLocalNotificationKey") || null
});
@@ -121,9 +122,9 @@ class IOSApplication implements definition.iOSApplication {
var topFrame = frame.topmost();
if (!topFrame) {
// try to navigate to the mainEntry/Module (if specified)
var navParam = definition.mainEntry;
var navParam = exports.mainEntry;
if (!navParam) {
navParam = definition.mainModule;
navParam = exports.mainModule;
}
if (navParam) {
@@ -147,7 +148,7 @@ class IOSApplication implements definition.iOSApplication {
exports.onResume();
}
exports.notify({ eventName: definition.resumeEvent, object: this, ios: UIApplication.sharedApplication() });
exports.notify({ eventName: exports.resumeEvent, object: this, ios: UIApplication.sharedApplication() });
}
private didEnterBackground(notification: NSNotification) {
@@ -155,7 +156,7 @@ class IOSApplication implements definition.iOSApplication {
exports.onSuspend();
}
exports.notify({ eventName: definition.suspendEvent, object: this, ios: UIApplication.sharedApplication() });
exports.notify({ eventName: exports.suspendEvent, object: this, ios: UIApplication.sharedApplication() });
}
private willTerminate(notification: NSNotification) {
@@ -163,7 +164,7 @@ class IOSApplication implements definition.iOSApplication {
exports.onExit();
}
exports.notify({ eventName: definition.exitEvent, object: this, ios: UIApplication.sharedApplication() });
exports.notify({ eventName: exports.exitEvent, object: this, ios: UIApplication.sharedApplication() });
}
private didReceiveMemoryWarning(notification: NSNotification) {
@@ -171,7 +172,7 @@ class IOSApplication implements definition.iOSApplication {
exports.onLowMemory();
}
exports.notify({ eventName: definition.lowMemoryEvent, object: this, android: undefined, ios: UIApplication.sharedApplication() });
exports.notify({ eventName: exports.lowMemoryEvent, object: this, android: undefined, ios: UIApplication.sharedApplication() });
}
private orientationDidChange(notification: NSNotification) {
@@ -180,6 +181,8 @@ class IOSApplication implements definition.iOSApplication {
if (this._currentOrientation !== orientation) {
this._currentOrientation = orientation;
var enums: typeof enumsModule = require("ui/enums");
var newValue;
switch (orientation) {
case UIDeviceOrientation.UIDeviceOrientationLandscapeRight:
@@ -196,7 +199,7 @@ class IOSApplication implements definition.iOSApplication {
}
exports.notify(<definition.OrientationChangedEventData>{
eventName: definition.orientationChangedEvent,
eventName: exports.orientationChangedEvent,
ios: this,
newValue: newValue,
object: this
@@ -210,19 +213,21 @@ var iosApp = new IOSApplication();
exports.ios = iosApp;
global.__onUncaughtError = function (error: Error) {
var types: typeof typesModule = require("utils/types");
// TODO: This should be obsoleted
if (types.isFunction(exports.onUncaughtError)) {
exports.onUncaughtError(error);
}
definition.notify({ eventName: definition.uncaughtErrorEvent, object: <any>definition.ios, ios: error });
exports.notify({ eventName: exports.uncaughtErrorEvent, object: <any>exports.ios, ios: error });
}
var started: boolean = false;
exports.start = function () {
if (!started) {
started = true;
appModule.loadCss();
exports.loadCss();
UIApplicationMain(0, null, null, exports.ios && exports.ios.delegate ? NSStringFromClass(exports.ios.delegate) : NSStringFromClass(Responder));
} else {
throw new Error("iOS Application already started!");
@@ -234,11 +239,13 @@ global.__onLiveSync = function () {
return;
}
var fileResolver: typeof fileResolverModule = require("file-system/file-name-resolver");
// Clear file resolver cache to respect newly added files.
fileResolverModule.clearCache();
fileResolver.clearCache();
// Reload app.css in case it was changed.
appModule.loadCss();
exports.loadCss();
// Reload current page.
frame.reloadPage();