GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: ability to embed into platform host projects by vmutafov · Pull Request #1799 · NativeScript/android

feat: ability to embed into platform host projects #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vmutafov wants to merge 6 commits into NativeScript:main
base: main
Loading
Loading
from vmutafov:embed
+740 −66
Open

feat: ability to embed into platform host projects #1799

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
496fcbb
feat: support android embedding
vmutafov Jan 2, 2024
5015a54
fix: remove NativeScriptActivity and NativeScriptApplication from git…
vmutafov Jan 7, 2024
62427bc
fix: use TestNativeScriptActivity and TestNativeScriptApplication whe…
vmutafov Jan 7, 2024
1cf7105
chore: re-add the runtime dependencies
edusperoni Jul 8, 2024
34eaae5
feat: remove deprecations and update error activity layout
edusperoni Jul 8, 2024
be29f1e
fix: fix missing colors
edusperoni Jul 9, 2024
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 3 additions & 1 deletion 4 .gitignore
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ thumbs.db
android-runtime.iml
test-app/build-tools/*.log
test-app/analytics/build-statistics.json
package-lock.json
package-lock.json
test-app/build-tools/jsparser/tests/cases/*/internal/livesync.js
test-app/build-tools/*.jar
7 changes: 7 additions & 0 deletions 7 build-artifacts/project-template-gradle/settings.gradle
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenLocal()
}
}

rootProject.name = "__PROJECT_NAME__"
include ':app'//, ':runtime', ':runtime-binding-generator'

Expand Down
12 changes: 10 additions & 2 deletions 12 build.gradle
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ task copyFilesToProjectTemeplate {
copy {
from "$TEST_APP_PATH/app/src/main/java/com/tns/"
include "*.java"
exclude "NativeScriptApplication.java"
exclude "NativeScriptActivity.java"
exclude "TestNativeScriptApplication.java"
exclude "TestNativeScriptActivity.java"
into "$DIST_FRAMEWORK_PATH/app/src/main/java/com/tns"
}
copy {
from "$TEST_APP_PATH/app/src/main/java/com/tns/internal"
into "$DIST_FRAMEWORK_PATH/app/src/main/java/com/tns/internal"
}
copy {
from "$TEST_APP_PATH/app/src/main/java/com/tns/embedding"
into "$DIST_FRAMEWORK_PATH/app/src/main/java/com/tns/embedding"
}
copy {
from "$BUILD_TOOLS_PATH/static-binding-generator/build/libs/static-binding-generator.jar"
into "$DIST_FRAMEWORK_PATH/build-tools"
Expand Down Expand Up @@ -295,6 +299,10 @@ task copyFilesToProjectTemeplate {
from "$TEST_APP_PATH/app/build.gradle"
into "$DIST_FRAMEWORK_PATH/app"
}
copy {
from "$TEST_APP_PATH/app/nativescript.gradle"
into "$DIST_FRAMEWORK_PATH/app"
}
copy {
from "$TEST_APP_PATH/build.gradle"
into "$DIST_FRAMEWORK_PATH"
Expand Down
2 changes: 0 additions & 2 deletions 2 test-app/.gitignore
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ app/app.iml
treeNodeStream.dat
treeStringsStream.dat
treeValueStream.dat
NativeScriptActivity.java
NativeScriptApplication.java
**/com/tns/gen
4 changes: 2 additions & 2 deletions 4 test-app/app/src/main/AndroidManifest.xml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

<application
android:requestLegacyExternalStorage="true"
android:name="com.tns.NativeScriptApplication"
android:name="com.tns.TestNativeScriptApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.tns.NativeScriptActivity" android:exported="true">
<activity android:name="com.tns.TestNativeScriptActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
4 changes: 2 additions & 2 deletions 4 test-app/app/src/main/assets/app/MyActivity.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
}

@JavaProxy("com.tns.NativeScriptActivity")
@JavaProxy("com.tns.TestNativeScriptActivity")
class MyActivity extends android.app.Activity
{
onCreate(bundle: android.os.Bundle)
Expand Down Expand Up @@ -62,7 +62,7 @@ var MyActivity = (function (_super) {

};
MyActivity = __decorate([
JavaProxy("com.tns.NativeScriptActivity")
JavaProxy("com.tns.TestNativeScriptActivity")
], MyActivity);
return MyActivity;
})(android.app.Activity);
2 changes: 1 addition & 1 deletion 2 test-app/app/src/main/assets/app/MyApp.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// demonstrates how to extend class in JavaScript with prebuilt Java proxy
var MyApp = android.app.Application.extend("com.tns.NativeScriptApplication",
var MyApp = android.app.Application.extend("com.tns.TestNativeScriptApplication",
{
onCreate: function()
{
Expand Down
2 changes: 1 addition & 1 deletion 2 test-app/app/src/main/java/com/tns/tests/StringConversionTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void callback(String str) {
private String readString() throws Exception {
String str = null;

Context context = com.tns.NativeScriptApplication.getInstance();
Context context = com.tns.TestNativeScriptApplication.getInstance();

InputStream inputStream = null;
try {
Expand Down
6 changes: 6 additions & 0 deletions 6 test-app/app/src/main/res/layout/main.xml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>
45 changes: 44 additions & 1 deletion 45 .../static-binding-generator/src/main/java/org/nativescript/staticbindinggenerator/Main.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.nativescript.staticbindinggenerator;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -11,8 +12,10 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -112,6 +115,10 @@ private static void validateInput() throws IOException {

List<DataRow> inputFile = Generator.getRows(SBG_INPUT_FILE);
inputDir = new File(inputFile.get(0).getRow());
Path assetsInternalDirPath = inputDir.getParentFile().toPath().resolve("internal");
extractResource(assetsInternalDirPath.resolve("ts_helpers.js"), "ts_helpers.js");
extractResource(assetsInternalDirPath.resolve("livesync.js"), "livesync.js");

webpackWorkersExcludePath = Paths.get(inputDir.getAbsolutePath(), "__worker-chunks.json").toString();

if (!inputDir.exists() || !inputDir.isDirectory()) {
Expand All @@ -132,7 +139,9 @@ private static void validateInput() throws IOException {
* This output file should contain all the information needed to generate java counterparts to the traversed js classes.
* */
private static void runJsParser() {
String parserPath = Paths.get(System.getProperty("user.dir"), "jsparser", "js_parser.js").toString();
Path jsParserPath = Paths.get(System.getProperty("user.dir"), "jsparser", "js_parser.js");
extractResource(jsParserPath, "js_parser.js");
String parserPath = jsParserPath.toString();
NodeJSProcess nodeJSProcess = new NodeJSProcessImpl(new ProcessExecutorImpl(), new EnvironmentVariablesReaderImpl());
int exitCode = nodeJSProcess.runScript(parserPath);

Expand All @@ -141,6 +150,40 @@ private static void runJsParser() {
}
}

private static void extractResource(Path savePath, String resourceName) {
File jsParserFile = savePath.toFile();
if (!jsParserFile.exists()) {
try {
jsParserFile.getParentFile().mkdirs();
jsParserFile.createNewFile();
InputStream source = Main.class.getResourceAsStream("/" + resourceName);
if (source == null) {
throw new RuntimeException(resourceName + " not found in resources");
}
FileUtils.copyInputStreamToFile(source, jsParserFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

private static void maybeExtractJsParserSource(Path jsParserPath) {
File jsParserFile = jsParserPath.toFile();
if (!jsParserFile.exists()) {
try {
jsParserFile.getParentFile().mkdirs();
jsParserFile.createNewFile();
InputStream source = Main.class.getResourceAsStream("/js_parser.js");
if (source == null) {
throw new RuntimeException("js_parser.js not found in resources");
}
FileUtils.copyInputStreamToFile(source, jsParserFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

private static Boolean rootTraversed = false;

private static void traverseDirectory(File currentDir, boolean traverseExplicitly) throws IOException, JSONException {
Expand Down
1 change: 1 addition & 0 deletions 1 test-app/build-tools/static-binding-generator/src/main/resources/js_parser.js
Show comments
View file
Open in desktop

Large diffs are not rendered by default.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

3 changes: 3 additions & 0 deletions 3 test-app/build-tools/static-binding-generator/src/main/resources/livesync.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (global.__onLiveSync) {
global.__onLiveSync();
}
175 changes: 175 additions & 0 deletions 175 test-app/build-tools/static-binding-generator/src/main/resources/ts_helpers.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
(function () {

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length;
var r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

if (typeof global.Reflect === "object" && typeof global.Reflect.decorate === "function") {
r = global.Reflect.decorate(decorators, target, key, desc);
}
else {
for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) {
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
}
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
};

// For backward compatibility.
var __native = function (thiz) {
// we are setting the __container__ property to the base class when the super method is called
// if the constructor returns the __native(this) call we will use the old implementation
// copying all the properties to the result
// otherwise if we are using the result from the super() method call we won't need such logic
// as thiz already contains the parent properties
// this way we now support both implementations in typescript generated constructors:
// 1: super(); return __native(this);
// 2: return super() || this;
if (thiz.__container__) {
var result = thiz.__proto__;

for (var prop in thiz) {
if (thiz.hasOwnProperty(prop)) {
thiz.__proto__[prop] = thiz[prop];
delete thiz[prop];
}
}

thiz.constructor = undefined;
thiz.__proto__ = undefined;
Object.freeze(thiz);
Object.preventExtensions(thiz);
return result;
} else {
return thiz;
}
};

var __extends = function (Child, Parent) {
var extendNativeClass = !!Parent.extend && (Parent.extend.toString().indexOf("[native code]") > -1);
if (!extendNativeClass) {
__extends_ts(Child, Parent);
return;
}
if (Parent.__isPrototypeImplementationObject) {
throw new Error("Can not extend an already extended native object.");
}

function extend(thiz) {
var child = thiz.__proto__.__child;
if (!child.__extended) {
var parent = thiz.__proto__.__parent;
child.__extended = parent.extend(child.name, child.prototype, true);
// This will deal with "i instanceof child"
child[Symbol.hasInstance] = function (instance) {
return instance instanceof this.__extended;
}
}
return child.__extended;
};

Parent.__activityExtend = function (parent, name, implementationObject) {
__log("__activityExtend called");
return parent.extend(name, implementationObject);
};

Parent.call = function (thiz) {
var Extended = extend(thiz);
thiz.__container__ = true;
if (arguments.length > 1) {
thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(Array.prototype.slice.call(arguments, 1))));
}
else {
thiz.__proto__ = new Extended()
}
return thiz.__proto__;
};

Parent.apply = function (thiz, args) {
var Extended = extend(thiz);
thiz.__container__ = true;
if (args && args.length > 0) {
thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(args)));
}
else {
thiz.__proto__ = new Extended();
}
return thiz.__proto__;
};
__extends_ns(Child, Parent);
Child.__isPrototypeImplementationObject = true;
Child.__proto__ = Parent;
Child.prototype.__parent = Parent;
Child.prototype.__child = Child;
}

var __extends_ts = function (child, parent) {
extendStaticFunctions(child, parent);
assignPrototypeFromParentToChild(parent, child);
};

var __extends_ns = function (child, parent) {
if (!parent.extend) {
assignPropertiesFromParentToChild(parent, child);
}

assignPrototypeFromParentToChild(parent, child);
};

var extendStaticFunctions =
Object.setPrototypeOf
|| (hasInternalProtoProperty() && function (child, parent) { child.__proto__ = parent; })
|| assignPropertiesFromParentToChild;

function hasInternalProtoProperty() {
return { __proto__: [] } instanceof Array;
}

function assignPropertiesFromParentToChild(parent, child) {
for (var property in parent) {
if (parent.hasOwnProperty(property)) {
child[property] = parent[property];
}
}
}

function assignPrototypeFromParentToChild(parent, child) {
function __() {
this.constructor = child;
}

if (parent === null) {
child.prototype = Object.create(null);
} else {
__.prototype = parent.prototype;
child.prototype = new __();
}
}


function JavaProxy(className) {
return function (target) {
var extended = target.extend(className, target.prototype)
extended.name = className;
return extended;
};
}

function Interfaces(interfacesArr) {
return function (target) {
if (interfacesArr instanceof Array) {
// attach interfaces: [] to the object
target.prototype.interfaces = interfacesArr;
}
}
}

Object.defineProperty(global, "__native", { value: __native });
Object.defineProperty(global, "__extends", { value: __extends });
Object.defineProperty(global, "__decorate", { value: __decorate });

global.JavaProxy = JavaProxy;
global.Interfaces = Interfaces;
})()
2 changes: 1 addition & 1 deletion 2 ...ing-generator/src/test/java/org/nativescript/staticbindinggenerator/test/DataRowTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testParseNamedExtend() throws IOException {
Assert.assertEquals(row.getColumn(), "");
Assert.assertEquals(row.getNewClassName(), "");
Assert.assertEquals(row.getMethods()[0], "toString");
Assert.assertEquals(row.getFilename(), "com.tns.NativeScriptActivity");
Assert.assertEquals(row.getFilename(), "com.tns.TestNativeScriptActivity");
Assert.assertEquals(row.getJsFilename(), "MyActivity.js");
Assert.assertEquals(row.getInterfaces()[0], "");
}
Expand Down
2 changes: 1 addition & 1 deletion 2 .../src/test/resources/org/nativescript/staticbindinggenerator/test/datarow-named-extend.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java.lang.Object*****toString*com.tns.NativeScriptActivity*MyActivity.js*
java.lang.Object*****toString*com.tns.TestNativeScriptActivity*MyActivity.js*
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.