Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

docs: Update extended activity related code #705

Merged
merged 11 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions demo/AngularApp/app/activity.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame";

@JavaProxy("org.myApp.MainActivity")
class Activity extends android.support.v7.app.AppCompatActivity {
public isNativeScriptActivity: boolean;
private _callbacks: AndroidActivityCallbacks;

protected onCreate(savedInstanceState: any): void { // android.os.Bundle
// Set isNativeScriptActivity in onCreate (as done in the original NativeScript activity code).
// The JS constructor might not be called because the activity is created from Android.
this.isNativeScriptActivity = true;

if (!this._callbacks) {
setActivityCallbacks(this);
}
Expand Down
4 changes: 4 additions & 0 deletions demo/JavaScriptApp/app/activity.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const frame = require("ui/frame");
const superProto = android.support.v7.app.AppCompatActivity.prototype;
android.support.v7.app.AppCompatActivity.extend("org.myApp.MainActivity", {
onCreate: function(savedInstanceState) {
// Set isNativeScriptActivity in onCreate.
// The JS constructor might not be called because the activity is created from Android.
this.isNativeScriptActivity = true;

if(!this._callbacks) {
frame.setActivityCallbacks(this);
}
Expand Down
6 changes: 3 additions & 3 deletions demo/JavaScriptApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": "next"
},
"tns-android": {
"version": "next"
"version": "5.0.0-2018-11-05-171453-02"
}
},
"dependencies": {
Expand All @@ -29,11 +29,11 @@
"mocha-multi": "^0.11.0",
"nativescript-dev-appium": "next",
"nativescript-dev-sass": "next",
"nativescript-dev-webpack": "next",
"nativescript-dev-webpack": "^0.18.0-2018-11-05-214332-01",
"node-sass": "^4.7.1"
},
"scripts": {
"setup": "npm pack ../../ && npm i -D nativescript-dev-webpack*.tgz",
"e2e": "mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json"
}
}
}
31 changes: 28 additions & 3 deletions demo/JavaScriptApp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ module.exports = env => {
uglify, // --env.uglify
report, // --env.report
sourceMap, // --env.sourceMap
hmr, // --env.hmr,
} = env;
const externals = (env.externals || []).map((e) => { // --env.externals
return new RegExp(e + ".*");
});

const appFullPath = resolve(projectRoot, appPath);
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
Expand All @@ -52,6 +56,7 @@ module.exports = env => {
const config = {
mode: uglify ? "production" : "development",
context: appFullPath,
externals,
watchOptions: {
ignored: [
appResourcesFullPath,
Expand Down Expand Up @@ -116,9 +121,9 @@ module.exports = env => {
minimize: !!uglify,
minimizer: [
new UglifyJsPlugin({
parallel: true,
cache: true,
uglifyOptions: {
parallel: true,
cache: true,
output: {
comments: false,
},
Expand Down Expand Up @@ -152,6 +157,21 @@ module.exports = env => {
].filter(loader => !!loader)
},

{
test: /-page\.js$/,
use: "nativescript-dev-webpack/script-hot-loader"
},

{
test: /\.(css|scss)$/,
use: "nativescript-dev-webpack/style-hot-loader"
},

{
test: /\.(html|xml)$/,
use: "nativescript-dev-webpack/markup-hot-loader"
},

{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"},

{
Expand All @@ -165,7 +185,7 @@ module.exports = env => {
{ loader: "css-loader", options: { minimize: false, url: false } },
"sass-loader"
]
}
},
]
},
plugins: [
Expand Down Expand Up @@ -229,5 +249,10 @@ module.exports = env => {
}));
}

if (hmr) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}


return config;
};
7 changes: 6 additions & 1 deletion demo/TypeScriptApp/app/activity.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame";

@JavaProxy("org.myApp.MainActivity")
class Activity extends android.support.v7.app.AppCompatActivity {
public isNativeScriptActivity: boolean;
private _callbacks: AndroidActivityCallbacks;

protected onCreate(savedInstanceState: any): void { // android.os.Bundle
// Set isNativeScriptActivity in onCreate (as done in the original NativeScript activity code).
// The JS constructor might not be called because the activity is created from Android.
this.isNativeScriptActivity = true;

if (!this._callbacks) {
setActivityCallbacks(this);
}
Expand Down