You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IMPORTANT: it's not a good idea to support this scenario, because if a JavaProxy() is provided but no extend, the java.lang.Object class will be inherited implicitly.
Why analyze ES5?
Faster loading time.
To generate java proxies, which can't be created at runtime, because it's too late. An example would be a class that implements Android Application or Android Activity
Why generate java proxies at build-time?
What are java proxies? Android classes specialized to serve NativeScript.
Why do we need them? To have a way to "callback" Javascript and handle native events from Android among other things.
Two types of java proxies:
Common - General purpose java proxy. It can be created either at build-time or run-time.
Custom - Used to create custom class extends. These proxies can be generated only at build time and can be declared in the AndroidManifest.xml.
As you can see the two kinds of proxies are more or less the same for the exception of the decorator: @com.tns.JavaScriptImplementation(javaScriptFile = "app/myactivity.js") which is only necessary for the custom java proxy.
IMPORTANT: JavaProxy() decorator on the Javascript side and @com.tns.JavaScriptImplementation() anotaion on the Java side are necessary when dealing with custom proxies because otherwise the runtime won't be able to link the instances correctly.
Generates a java proxy named ClasName.java in com.my namespace.
IMPORTANT: Extend naming is important, because it dictates where the class will be created and therefore how will it be accessed through Javascript.
Common extended classes
Common extend classes with pure ES5
var MyButton = android.widget.Button.extend("TestClass", {
onClick1: function () {
},
onClick2: function () {
}
})
Common extend classes ES5 parsed from Typescript
var TestClass = (function (_super) {
__extends(ZZZZZ, _super);
function TestClass() {
_super.apply(this, arguments);
}
TestClass.prototype.TestClassMethod1 = function () {
};
TestClass.prototype.TestClassMethod2 = function () {
};
return TestClass;
})(passed.extend.Present);
Custom extend classes
Custom extend classes with pure ES5
var MyButton = android.widget.Button.extend("my.custom.TestClass", {
onClick1: function () {
},
onClick2: function () {
}
});
Custom extend classes with ES5 parsed from Typescript
var TestClass = (function (_super) {
__extends(TestClass, _super);
function TestClass() {
_super.apply(this, arguments);
}
TestClass.prototype.TestClassMethod1 = function () {
};
TestClass.prototype.TestClassMethod2 = function () {
};
TestClass = __decorate([
JavaProxy("javaProxy.path.Present")
], TestClass);
return TestClass;
})(passed.extend.Present);
Interfaces
var lifecycleCallbacks = new android.app.Application.ActivityLifecycleCallbacks({
onActivityCreated: function (activity, bundle) {},
onActivityDestroyed: function (activity) {},
onActivityPaused: function (activity) {},
onActivityResumed: function (activity) {},
onActivitySaveInstanceState: function (activity, bundle) {},
onActivityStarted: function (activity) {},
onActivityStopped: function (activity) {}
});
Not a good idea to support:
No extend with custom java proxy:
var TestClass = (function () {
function TestClass() {
}
TestClass.prototype.TestClassMethod1 = function () {
};
TestClass.prototype.TestClassMethod2 = function () {
};
TestClass = __decorate([
JavaProxy("javaProxy.path.Present")
], TestClass);
return TestClass;
})();
Java proxy examples
Common proxy example
package com.tns.gen.android.view;
public class ViewGroup extends android.view.ViewGroup {
private boolean __initialized;
protected void onLayout(boolean param_0, int param_1) {
if (!__initialized) {
__initialized = true;
com.tns.Platform.initInstance(this);
}
java.lang.Object[] params = new Object[2];
params[0] = param_0;
params[1] = param_1;
com.tns.Platform.callJSMethod(this, "onLayout", void.class, params);
}
}
Custom proxy example
// com/example/MyActivity.java
package com.example;
@com.tns.JavaScriptImplementation(javaScriptFile = "app/myactivity.js")
public class MyActivity extends android.app.Activity {
public MyActivity() {
com.tns.Platform.initInstance(this);
}
public void onCreate(android.os.Bundle param_0) {
Object[] args = new Object[1];
args[0] = param_0;
com.tns.Platform.callJSMethod(this, "onCreate", void.class, args);
}
}
The text was updated successfully, but these errors were encountered:
What we want to do:
To comlete proposal implementation:
JavaProxy("com.my.ClassName")
decorator)bcel
library when creating custom/common java proxies.Analyze ES5
Analyze ES5 and extract all information concerning NativeScript. The information we need from the static analysis is:
What syntax should we support?
What syntax we shouldn't support?
Why analyze ES5?
Why generate java proxies at build-time?
What are java proxies? Android classes specialized to serve NativeScript.
Why do we need them? To have a way to "callback" Javascript and handle native events from Android among other things.
Two types of java proxies:
As you can see the two kinds of proxies are more or less the same for the exception of the decorator:
@com.tns.JavaScriptImplementation(javaScriptFile = "app/myactivity.js")
which is only necessary for the custom java proxy.Extend name specification
Common proxy
Typescript
ES5
Generates a java proxy named
ClasName.java
incom.tns.gen.android.widget
namespace.Custom proxy
Typescript
ES5
Generates a java proxy named
ClasName.java
incom.my
namespace.Common extended classes
Common extend classes with pure ES5
Common extend classes ES5 parsed from Typescript
Custom extend classes
Custom extend classes with pure ES5
Custom extend classes with ES5 parsed from Typescript
Interfaces
Not a good idea to support:
No extend with custom java proxy:
Java proxy examples
Common proxy example
Custom proxy example
The text was updated successfully, but these errors were encountered: