Skip to content

Commit 1921712

Browse files
author
Hristo Hristov
committed
Fix android orientation exception. (NativeScript#2278)
Fix android activity destroy/resume. Fix tslint - skipped all from node_modules & platforms
1 parent 55398d6 commit 1921712

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ module.exports = function(grunt) {
166166
"!tns-core-modules/ios.d.ts",
167167
"!tns-core-modules/android17.d.ts",
168168
"!tns-core-modules/libjs.d.ts",
169-
"!tests/node_modules/"
169+
"!tests/node_modules/**",
170+
"!tests/platforms/**"
170171
]);
171172
localCfg.srcTsdFiles = [
172173
"**/*.d.ts",

tns-core-modules/application/application.android.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import definition = require("application");
33
import frame = require("ui/frame");
44
import observable = require("data/observable");
55
import * as typesModule from "utils/types";
6+
import * as enumsModule from "ui/enums";
7+
let enums: typeof enumsModule;
68

79
global.moduleMerge(appModule, exports);
810
var typedExports: typeof definition = exports;
@@ -121,28 +123,30 @@ function initLifecycleCallbacks() {
121123
let currentOrientation: number;
122124
function initComponentCallbacks() {
123125
let componentCallbacks = new android.content.ComponentCallbacks2({
124-
onLowMemory: function() {
126+
onLowMemory: function () {
125127
gc();
126128
java.lang.System.gc();
127129
typedExports.notify(<definition.ApplicationEventData>{ eventName: typedExports.lowMemoryEvent, object: this, android: this });
128130
},
129-
130-
onTrimMemory: function(level: number) {
131+
132+
onTrimMemory: function (level: number) {
131133
// TODO: This is skipped for now, test carefully for OutOfMemory exceptions
132134
},
133-
134-
onConfigurationChanged: function(newConfig: android.content.res.Configuration) {
135+
136+
onConfigurationChanged: function (newConfig: android.content.res.Configuration) {
135137
let newOrientation = newConfig.orientation;
136-
if(newOrientation === currentOrientation) {
138+
if (newOrientation === currentOrientation) {
137139
return;
138140
}
139-
140-
currentOrientation = newOrientation;
141141

142-
let enums = require("ui/enums");
142+
if (!enums) {
143+
enums = require("ui/enums");
144+
}
145+
146+
currentOrientation = newOrientation;
143147
let newValue;
144-
145-
switch (orientation) {
148+
149+
switch (newOrientation) {
146150
case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
147151
newValue = enums.DeviceOrientation.landscape;
148152
break;
@@ -162,7 +166,7 @@ function initComponentCallbacks() {
162166
});
163167
}
164168
});
165-
169+
166170
return componentCallbacks;
167171
}
168172

@@ -204,10 +208,10 @@ export class AndroidApplication extends observable.Observable implements definit
204208
public onActivityResult: (requestCode: number, resultCode: number, data: android.content.Intent) => void;
205209

206210
public init(nativeApp: any) {
207-
if(this.nativeApp) {
211+
if (this.nativeApp) {
208212
throw new Error("application.android already initialized.")
209213
}
210-
214+
211215
this.nativeApp = nativeApp;
212216
this.packageName = nativeApp.getPackageName();
213217
this.context = nativeApp.getApplicationContext();
@@ -216,7 +220,7 @@ export class AndroidApplication extends observable.Observable implements definit
216220
let componentCallbacks = initComponentCallbacks();
217221
this.nativeApp.registerActivityLifecycleCallbacks(lifecycleCallbacks);
218222
this.nativeApp.registerComponentCallbacks(componentCallbacks);
219-
223+
220224
this._registerPendingReceivers();
221225
}
222226

@@ -295,8 +299,8 @@ export function start(entry?: frame.NavigationEntry) {
295299
if (started) {
296300
throw new Error("Application is already started.");
297301
}
298-
299-
if(!androidApp.nativeApp) {
302+
303+
if (!androidApp.nativeApp) {
300304
// we are still not initialized, this is possible if no 'androidApp.init' call has been made
301305
let utils = require("utils/utils");
302306
let nativeApp = utils.ad.getApplication();
@@ -332,7 +336,7 @@ global.__onLiveSync = function () {
332336
if (typedExports.android && typedExports.android.paused) {
333337
return;
334338
}
335-
339+
336340
appModule.__onLiveSync();
337341
}
338342

tns-core-modules/ui/frame/frame.android.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,6 @@ class FragmentClass extends android.app.Fragment {
717717
trace.write(`${this}.onDestroy()`, trace.categories.NativeLifecycle);
718718
}
719719
super.onDestroy();
720-
721-
this.entry.fragmentTag = undefined;
722720
}
723721

724722
public toString(): string {

0 commit comments

Comments
 (0)