chore: working android build

This commit is contained in:
Nathan Walker
2020-07-26 22:27:39 -07:00
parent b00013f35e
commit 39bcc8a4ca
27 changed files with 427 additions and 421 deletions

View File

@@ -9,111 +9,111 @@ if (global.__snapshot) {
/**
* Option 1: the exact es5 compiled version of what this normally looks like
*/
var NativeScriptActivity = (function (_super) {
__extends(NativeScriptActivity, _super);
function NativeScriptActivity() {
console.log('construct NativeScriptActivity');
var _this = _super.call(this) || this;
return global.__native(_this);
}
NativeScriptActivity.prototype.init = function () {
// return new NativeScriptActivity();
};
NativeScriptActivity.prototype.onCreate = function (savedInstanceState) {
appModule.android.init(this.getApplication());
this.isNativeScriptActivity = true;
if (!this._callbacks) {
setActivityCallbacks(this);
}
this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), _super.prototype.onCreate);
};
NativeScriptActivity.prototype.onNewIntent = function (intent) {
this._callbacks.onNewIntent(this, intent, _super.prototype.setIntent, _super.prototype.onNewIntent);
};
NativeScriptActivity.prototype.onSaveInstanceState = function (outState) {
this._callbacks.onSaveInstanceState(this, outState, _super.prototype.onSaveInstanceState);
};
NativeScriptActivity.prototype.onStart = function () {
this._callbacks.onStart(this, _super.prototype.onStart);
};
NativeScriptActivity.prototype.onStop = function () {
this._callbacks.onStop(this, _super.prototype.onStop);
};
NativeScriptActivity.prototype.onDestroy = function () {
this._callbacks.onDestroy(this, _super.prototype.onDestroy);
};
NativeScriptActivity.prototype.onPostResume = function () {
this._callbacks.onPostResume(this, _super.prototype.onPostResume);
};
NativeScriptActivity.prototype.onBackPressed = function () {
this._callbacks.onBackPressed(this, _super.prototype.onBackPressed);
};
NativeScriptActivity.prototype.onRequestPermissionsResult = function (requestCode, permissions, grantResults) {
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined);
};
NativeScriptActivity.prototype.onActivityResult = function (requestCode, resultCode, data) {
this._callbacks.onActivityResult(this, requestCode, resultCode, data, _super.prototype.onActivityResult);
};
NativeScriptActivity = __decorate([JavaProxy('com.tns.NativeScriptActivity')], NativeScriptActivity);
return NativeScriptActivity;
})(androidx.appcompat.app.AppCompatActivity);
// Option 2: the manual es5 way - results in same as above
// const superProto = androidx.appcompat.app.AppCompatActivity.prototype;
// const NativeScriptActivity = (<any>androidx.appcompat.app.AppCompatActivity).extend('com.tns.NativeScriptActivity', {
// init() {
// // superProto();
// // return global.__native(this);
// },
// onCreate(savedInstanceState: android.os.Bundle): void {
// appModule.android.init(this.getApplication());
// // Set isNativeScriptActivity in onCreate.
// // The JS constructor might not be called because the activity is created from Android.
// var NativeScriptActivity = (function (_super) {
// __extends(NativeScriptActivity, _super);
// function NativeScriptActivity() {
// console.log('construct NativeScriptActivity');
// var _this = _super.call(this) || this;
// return global.__native(_this);
// }
// NativeScriptActivity.prototype.init = function () {
// // return new NativeScriptActivity();
// };
// NativeScriptActivity.prototype.onCreate = function (savedInstanceState) {
// appModule.android.init(this.getApplication());
// this.isNativeScriptActivity = true;
// if (!this._callbacks) {
// setActivityCallbacks(this);
// }
// this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), _super.prototype.onCreate);
// };
// NativeScriptActivity.prototype.onNewIntent = function (intent) {
// this._callbacks.onNewIntent(this, intent, _super.prototype.setIntent, _super.prototype.onNewIntent);
// };
// NativeScriptActivity.prototype.onSaveInstanceState = function (outState) {
// this._callbacks.onSaveInstanceState(this, outState, _super.prototype.onSaveInstanceState);
// };
// NativeScriptActivity.prototype.onStart = function () {
// this._callbacks.onStart(this, _super.prototype.onStart);
// };
// NativeScriptActivity.prototype.onStop = function () {
// this._callbacks.onStop(this, _super.prototype.onStop);
// };
// NativeScriptActivity.prototype.onDestroy = function () {
// this._callbacks.onDestroy(this, _super.prototype.onDestroy);
// };
// NativeScriptActivity.prototype.onPostResume = function () {
// this._callbacks.onPostResume(this, _super.prototype.onPostResume);
// };
// NativeScriptActivity.prototype.onBackPressed = function () {
// this._callbacks.onBackPressed(this, _super.prototype.onBackPressed);
// };
// NativeScriptActivity.prototype.onRequestPermissionsResult = function (requestCode, permissions, grantResults) {
// this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined);
// };
// NativeScriptActivity.prototype.onActivityResult = function (requestCode, resultCode, data) {
// this._callbacks.onActivityResult(this, requestCode, resultCode, data, _super.prototype.onActivityResult);
// };
// NativeScriptActivity = __decorate([JavaProxy('com.tns.NativeScriptActivity')], NativeScriptActivity);
// return NativeScriptActivity;
// })(androidx.appcompat.app.AppCompatActivity);
// this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), superProto.onCreate);
// },
// Option 2: the manual es5 way - results in same as above
const superProto = androidx.appcompat.app.AppCompatActivity.prototype;
const NativeScriptActivity = (<any>androidx.appcompat.app.AppCompatActivity).extend('com.tns.NativeScriptActivity', {
init() {
// superProto();
// return global.__native(this);
},
onCreate(savedInstanceState: android.os.Bundle): void {
appModule.android.init(this.getApplication());
// onNewIntent(intent: android.content.Intent): void {
// this._callbacks.onNewIntent(this, intent, superProto.setIntent, superProto.onNewIntent);
// },
// Set isNativeScriptActivity in onCreate.
// The JS constructor might not be called because the activity is created from Android.
this.isNativeScriptActivity = true;
if (!this._callbacks) {
setActivityCallbacks(this);
}
// onSaveInstanceState(outState: android.os.Bundle): void {
// this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState);
// },
this._callbacks.onCreate(this, savedInstanceState, this.getIntent(), superProto.onCreate);
},
// onStart(): void {
// this._callbacks.onStart(this, superProto.onStart);
// },
onNewIntent(intent: android.content.Intent): void {
this._callbacks.onNewIntent(this, intent, superProto.setIntent, superProto.onNewIntent);
},
// onStop(): void {
// this._callbacks.onStop(this, superProto.onStop);
// },
onSaveInstanceState(outState: android.os.Bundle): void {
this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState);
},
// onDestroy(): void {
// this._callbacks.onDestroy(this, superProto.onDestroy);
// },
onStart(): void {
this._callbacks.onStart(this, superProto.onStart);
},
// onPostResume(): void {
// this._callbacks.onPostResume(this, superProto.onPostResume);
// },
onStop(): void {
this._callbacks.onStop(this, superProto.onStop);
},
// onBackPressed(): void {
// this._callbacks.onBackPressed(this, superProto.onBackPressed);
// },
onDestroy(): void {
this._callbacks.onDestroy(this, superProto.onDestroy);
},
// onRequestPermissionsResult(requestCode: number, permissions: Array<string>, grantResults: Array<number>): void {
// this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
// },
onPostResume(): void {
this._callbacks.onPostResume(this, superProto.onPostResume);
},
// onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
// this._callbacks.onActivityResult(this, requestCode, resultCode, data, superProto.onActivityResult);
// },
// });
onBackPressed(): void {
this._callbacks.onBackPressed(this, superProto.onBackPressed);
},
onRequestPermissionsResult(requestCode: number, permissions: Array<string>, grantResults: Array<number>): void {
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
},
onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
this._callbacks.onActivityResult(this, requestCode, resultCode, data, superProto.onActivityResult);
},
});
/**
* Option 3: The way which worked when using es5 compile target however when targeting es2017, this source code won't work due to the extends from native class so trying options 1 and 2 to achieve same

View File

@@ -1,68 +1,124 @@
import { AndroidFragmentCallbacks, setFragmentCallbacks, setFragmentClass } from '.';
@JavaProxy('com.tns.FragmentClass')
@NativeClass
class FragmentClass extends org.nativescript.widgets.FragmentBase {
// This field is updated in the frame module upon `new` (although hacky this eases the Fragment->callbacks association a lot)
private _callbacks: AndroidFragmentCallbacks;
const superProto = org.nativescript.widgets.FragmentBase.prototype;
const FragmentClass = (<any>org.nativescript.widgets.FragmentBase).extend('com.tns.FragmentClass', {
init() {},
onHiddenChanged(hidden: boolean): void {
this._callbacks.onHiddenChanged(this, hidden, superProto.onHiddenChanged);
},
constructor() {
super();
onCreateAnimator(transit: number, enter: boolean, nextAnim: number): android.animation.Animator {
return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, superProto.onCreateAnimator);
},
return global.__native(this);
}
onStop(): void {
this._callbacks.onStop(this, superProto.onStop);
},
public onHiddenChanged(hidden: boolean): void {
this._callbacks.onHiddenChanged(this, hidden, super.onHiddenChanged);
}
onPause(): void {
this._callbacks.onPause(this, superProto.onStop);
},
public onCreateAnimator(transit: number, enter: boolean, nextAnim: number): android.animation.Animator {
return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator);
}
public onStop(): void {
this._callbacks.onStop(this, super.onStop);
}
public onPause(): void {
this._callbacks.onPause(this, super.onStop);
}
public onCreate(savedInstanceState: android.os.Bundle) {
onCreate(savedInstanceState: android.os.Bundle) {
if (!this._callbacks) {
setFragmentCallbacks(this);
}
this.setHasOptionsMenu(true);
this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
}
this._callbacks.onCreate(this, savedInstanceState, superProto.onCreate);
},
public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle) {
let result = this._callbacks.onCreateView(this, inflater, container, savedInstanceState, super.onCreateView);
onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle) {
let result = this._callbacks.onCreateView(this, inflater, container, savedInstanceState, superProto.onCreateView);
return result;
}
},
public onSaveInstanceState(outState: android.os.Bundle) {
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
}
onSaveInstanceState(outState: android.os.Bundle) {
this._callbacks.onSaveInstanceState(this, outState, superProto.onSaveInstanceState);
},
public onDestroyView() {
this._callbacks.onDestroyView(this, super.onDestroyView);
}
onDestroyView() {
this._callbacks.onDestroyView(this, superProto.onDestroyView);
},
public onDestroy() {
this._callbacks.onDestroy(this, super.onDestroy);
}
onDestroy() {
this._callbacks.onDestroy(this, superProto.onDestroy);
},
public toString(): string {
toString(): string {
const callbacks = this._callbacks;
if (callbacks) {
return callbacks.toStringOverride(this, super.toString);
return callbacks.toStringOverride(this, superProto.toString);
} else {
super.toString();
superProto.toString();
}
}
}
},
});
// @NativeClass
// @JavaProxy('com.tns.FragmentClass')
// class FragmentClass extends org.nativescript.widgets.FragmentBase {
// // This field is updated in the frame module upon `new` (although hacky this eases the Fragment->callbacks association a lot)
// private _callbacks: AndroidFragmentCallbacks;
// constructor() {
// super();
// return global.__native(this);
// }
// public onHiddenChanged(hidden: boolean): void {
// this._callbacks.onHiddenChanged(this, hidden, super.onHiddenChanged);
// }
// public onCreateAnimator(transit: number, enter: boolean, nextAnim: number): android.animation.Animator {
// return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator);
// }
// public onStop(): void {
// this._callbacks.onStop(this, super.onStop);
// }
// public onPause(): void {
// this._callbacks.onPause(this, super.onStop);
// }
// public onCreate(savedInstanceState: android.os.Bundle) {
// if (!this._callbacks) {
// setFragmentCallbacks(this);
// }
// this.setHasOptionsMenu(true);
// this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
// }
// public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle) {
// let result = this._callbacks.onCreateView(this, inflater, container, savedInstanceState, super.onCreateView);
// return result;
// }
// public onSaveInstanceState(outState: android.os.Bundle) {
// this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
// }
// public onDestroyView() {
// this._callbacks.onDestroyView(this, super.onDestroyView);
// }
// public onDestroy() {
// this._callbacks.onDestroy(this, super.onDestroy);
// }
// public toString(): string {
// const callbacks = this._callbacks;
// if (callbacks) {
// return callbacks.toStringOverride(this, super.toString);
// } else {
// super.toString();
// }
// }
// }
setFragmentClass(FragmentClass);

View File

@@ -211,6 +211,7 @@ function setupExitAndPopEnterAnimation(entry: ExpandedEntry, transition: Transit
function getAnimationListener(): android.animation.Animator.AnimatorListener {
if (!AnimationListener) {
@NativeClass
@Interfaces([android.animation.Animator.AnimatorListener])
class AnimationListenerImpl extends java.lang.Object implements android.animation.Animator.AnimatorListener {
constructor() {
@@ -323,6 +324,7 @@ export function _reverseTransitions(previousEntry: ExpandedEntry, currentEntry:
// android is cloning transitions and we can't expand them :(
function getTransitionListener(entry: ExpandedEntry, transition: androidx.transition.Transition): ExpandedTransitionListener {
if (!TransitionListener) {
@NativeClass
@Interfaces([(<any>androidx).transition.Transition.TransitionListener])
class TransitionListenerImpl extends java.lang.Object implements androidx.transition.Transition.TransitionListener {
constructor(public entry: ExpandedEntry, public transition: androidx.transition.Transition) {

View File

@@ -48,49 +48,50 @@ export let attachStateChangeListener: android.view.View.OnAttachStateChangeListe
function getAttachListener(): android.view.View.OnAttachStateChangeListener {
if (!attachStateChangeListener) {
var AttachListener = (function (_super) {
__extends(AttachListener, _super);
function AttachListener() {
var _this = _super.call(this) || this;
return global.__native(_this);
}
AttachListener.prototype.onViewAttachedToWindow = function (view) {
var owner = view[ownerSymbol];
if (owner) {
owner._onAttachedToWindow();
}
};
AttachListener.prototype.onViewDetachedFromWindow = function (view) {
var owner = view[ownerSymbol];
if (owner) {
owner._onDetachedFromWindow();
}
};
AttachListener = __decorate([Interfaces([android.view.View.OnAttachStateChangeListener])], AttachListener);
return AttachListener;
})(java.lang.Object);
// const AttachListener = (<any>java.lang.Object).extend({
// interfaces: [android.view.View.OnAttachStateChangeListener],
// init() {
// // this.super(this);
// // return global.__native(this);
// },
// onViewAttachedToWindow(view: android.view.View): void {
// console.log('onViewAttachedToWindow')
// const owner: View = view[ownerSymbol];
// console.log('owner:', owner)
// var AttachListener = (function (_super) {
// __extends(AttachListener, _super);
// function AttachListener() {
// var _this = _super.call(this) || this;
// return global.__native(_this);
// }
// AttachListener.prototype.onViewAttachedToWindow = function (view) {
// var owner = view[ownerSymbol];
// if (owner) {
// // console.log('owner._onAttachedToWindow:', owner._onAttachedToWindow)
// owner._onAttachedToWindow();
// }
// },
// onViewDetachedFromWindow(view: android.view.View): void {
// const owner: View = view[ownerSymbol];
// };
// AttachListener.prototype.onViewDetachedFromWindow = function (view) {
// var owner = view[ownerSymbol];
// if (owner) {
// owner._onDetachedFromWindow();
// }
// },
// });
// };
// AttachListener = __decorate([Interfaces([android.view.View.OnAttachStateChangeListener])], AttachListener);
// return AttachListener;
// })(java.lang.Object);
const AttachListener = (<any>java.lang.Object).extend({
interfaces: [android.view.View.OnAttachStateChangeListener],
init() {
// this.super(this);
// return global.__native(this);
},
onViewAttachedToWindow(view: android.view.View): void {
console.log('onViewAttachedToWindow');
const owner: View = view[ownerSymbol];
console.log('owner:', owner);
if (owner) {
// console.log('owner._onAttachedToWindow:', owner._onAttachedToWindow)
owner._onAttachedToWindow();
}
},
onViewDetachedFromWindow(view: android.view.View): void {
const owner: View = view[ownerSymbol];
if (owner) {
owner._onDetachedFromWindow();
}
},
});
// class AttachListener extends java.lang.Object implements android.view.View.OnAttachStateChangeListener {
// constructor() {
// super();