Skip to content

Commit 0ba0e9c

Browse files
committed
Extend activity
1 parent d02e285 commit 0ba0e9c

File tree

7 files changed

+60
-3
lines changed

7 files changed

+60
-3
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ hooks
22
node_modules
33
platforms
44

5+
*.js
56
package-lock.json

Diff for: app/App_Resources/Android/app.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
android {
99
defaultConfig {
1010
generatedDensities = []
11-
applicationId = "__PACKAGE__"
11+
applicationId = "org.nativescript.androidextendng"
1212
}
1313
aaptOptions {
1414
additionalParameters "--no-version-vectors"

Diff for: app/App_Resources/Android/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
android:theme="@style/AppTheme">
2727

2828
<activity
29-
android:name="com.tns.NativeScriptActivity"
29+
android:name="org.myApp.MainActivity"
3030
android:label="@string/title_activity_kimera"
3131
android:configChanges="keyboardHidden|orientation|screenSize"
3232
android:theme="@style/LaunchScreenTheme">

Diff for: app/activity.android.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame";
2+
3+
@JavaProxy("org.myApp.MainActivity")
4+
class Activity extends android.app.Activity {
5+
private _callbacks: AndroidActivityCallbacks;
6+
7+
protected onCreate(savedInstanceState: android.os.Bundle): void {
8+
if (!this._callbacks) {
9+
setActivityCallbacks(this);
10+
}
11+
12+
this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
13+
}
14+
15+
protected onSaveInstanceState(outState: android.os.Bundle): void {
16+
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
17+
}
18+
19+
protected onStart(): void {
20+
this._callbacks.onStart(this, super.onStart);
21+
}
22+
23+
protected onStop(): void {
24+
this._callbacks.onStop(this, super.onStop);
25+
}
26+
27+
protected onDestroy(): void {
28+
this._callbacks.onDestroy(this, super.onDestroy);
29+
}
30+
31+
public onBackPressed(): void {
32+
this._callbacks.onBackPressed(this, super.onBackPressed);
33+
}
34+
35+
public onRequestPermissionsResult(requestCode: number, permissions: Array<String>, grantResults: Array<number>): void {
36+
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
37+
}
38+
39+
protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
40+
this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
41+
}
42+
}

Diff for: package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"readme": "NativeScript Application",
55
"repository": "<fill-your-repository-here>",
66
"nativescript": {
7-
"id": "org.nativescript.androidextendng"
7+
"id": "org.nativescript.androidextendng",
8+
"tns-android": {
9+
"version": "4.1.2"
10+
},
11+
"tns-ios": {
12+
"version": "4.1.0"
13+
}
814
},
915
"dependencies": {
1016
"@angular/animations": "~6.0.0",
@@ -27,15 +33,20 @@
2733
"@angular-devkit/core": "~0.6.3",
2834
"@angular/compiler-cli": "~6.0.0",
2935
"@ngtools/webpack": "~6.0.3",
36+
"babel-traverse": "6.26.0",
37+
"babel-types": "6.26.0",
38+
"babylon": "6.18.0",
3039
"clean-webpack-plugin": "~0.1.19",
3140
"copy-webpack-plugin": "~4.5.1",
3241
"css-loader": "~0.28.11",
3342
"extract-text-webpack-plugin": "~3.0.2",
43+
"lazy": "1.0.11",
3444
"nativescript-dev-typescript": "~0.7.0",
3545
"nativescript-dev-webpack": "^0.12.0",
3646
"nativescript-worker-loader": "~0.9.0",
3747
"raw-loader": "~0.5.1",
3848
"resolve-url-loader": "~2.3.0",
49+
"tns-platform-declarations": "^4.1.0",
3950
"typescript": "~2.7.2",
4051
"uglifyjs-webpack-plugin": "~1.2.5",
4152
"webpack": "~4.6.0",

Diff for: references.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
2+
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

Diff for: webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = env => {
1414
const appComponents = [
1515
"tns-core-modules/ui/frame",
1616
"tns-core-modules/ui/frame/activity",
17+
resolve(__dirname, "app/activity.android.ts"),
1718
];
1819

1920
const platform = env && (env.android && "android" || env.ios && "ios");

0 commit comments

Comments
 (0)