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

@@ -58,6 +58,8 @@ export const hasListeners = (<any>global).NativeScriptGlobals.events.hasListener
let app: iOSApplication | AndroidApplication;
export function setApplication(instance: iOSApplication | AndroidApplication): void {
app = instance;
// signal when the application instance is ready globally
(<any>global).NativeScriptGlobals.appInstanceReady = true;
}
export function livesync(rootView: View, context?: ModuleContext) {

View File

@@ -1,15 +1,16 @@
// Types.
import { AndroidApplication as AndroidApplicationDefinition } from '.';
import { AndroidActivityBackPressedEventData, AndroidActivityBundleEventData, AndroidActivityEventData, AndroidActivityNewIntentEventData, AndroidActivityRequestPermissionsEventData, AndroidActivityResultEventData, ApplicationEventData, CssChangedEventData, OrientationChangedEventData, SystemAppearanceChangedEventData } from './application-interfaces';
import { View } from '../ui/core/view';
import { NavigationEntry, AndroidActivityCallbacks } from '../ui/frame/frame-interfaces';
import { Observable } from '../data/observable';
// Use requires to ensure order of imports is maintained
const appCommon = require('./application-common');
// First reexport so that app module is initialized.
export * from './application-common';
import { View } from '../ui/core/view';
import { NavigationEntry, AndroidActivityCallbacks } from '../ui/frame/frame-interfaces';
import { Observable } from '../data/observable';
import { profile } from '../profiling';
const ActivityCreated = 'activityCreated';
@@ -482,6 +483,20 @@ function ensureBroadCastReceiverClass() {
return;
}
const BroadcastReceiver = (<any>android.content.BroadcastReceiver).extend({
init(onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) {
// super();
this._onReceiveCallback = onReceiveCallback;
// return global.__native(this);
},
_onReceiveCallback(context: android.content.Context, intent: android.content.Intent) {
if (this._onReceiveCallback) {
this._onReceiveCallback(context, intent);
}
},
});
// @NativeClass
// class BroadcastReceiver extends android.content.BroadcastReceiver {
// private _onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void;
@@ -499,20 +514,20 @@ function ensureBroadCastReceiverClass() {
// }
// }
// }
var BroadcastReceiver = (function (_super) {
__extends(BroadcastReceiver, _super);
function BroadcastReceiver(onReceiveCallback) {
var _this = _super.call(this) || this;
_this._onReceiveCallback = onReceiveCallback;
return global.__native(_this);
}
BroadcastReceiver.prototype.onReceive = function (context, intent) {
if (this._onReceiveCallback) {
this._onReceiveCallback(context, intent);
}
};
return BroadcastReceiver;
})(android.content.BroadcastReceiver);
// var BroadcastReceiver = (function (_super) {
// __extends(BroadcastReceiver, _super);
// function BroadcastReceiver(onReceiveCallback) {
// var _this = _super.call(this) || this;
// _this._onReceiveCallback = onReceiveCallback;
// return global.__native(_this);
// }
// BroadcastReceiver.prototype.onReceive = function (context, intent) {
// if (this._onReceiveCallback) {
// this._onReceiveCallback(context, intent);
// }
// };
// return BroadcastReceiver;
// })(android.content.BroadcastReceiver);
BroadcastReceiverClass = BroadcastReceiver;
}

View File

@@ -1,6 +1,5 @@
import { FileSystemAccess } from './file-system-access';
import { isIOS } from '../platform';
import { profile } from '../profiling';
// The FileSystemAccess implementation, used through all the APIs.
let fileAccess: FileSystemAccess;
@@ -319,7 +318,6 @@ export class File extends FileSystemEntity {
});
}
@profile
public readTextSync(onError?: (error: any) => any, encoding?: string): string {
this.checkAccess();

View File

@@ -39,8 +39,11 @@ function registerOnGlobalContext(moduleName: string, exportName: string): void {
* Manages internal framework global state
*/
export class NativeScriptGlobalState {
events: Observable<any>;
events: Observable;
launched = false;
// used by various classes to setup callbacks to wire up global app event handling when the app instance is ready
appEventWiring: Array<any>;
private _appInstanceReady = false;
private _setLaunched: () => void;
constructor() {
// console.log('creating NativeScriptGlobals...')
@@ -57,6 +60,37 @@ export class NativeScriptGlobalState {
}
}
get appInstanceReady() {
return this._appInstanceReady;
}
set appInstanceReady(value: boolean) {
this._appInstanceReady = value;
// app instance ready, wire up any app events waiting in startup queue
if (this.appEventWiring && this.appEventWiring.length) {
for (const callback of this.appEventWiring) {
callback();
}
// cleanup
this.appEventWiring = null;
}
}
/**
* Ability for classes to initialize app event handling early even before the app instance is ready during boot cycle avoiding boot race conditions
* @param callback wire up any global event handling inside the callback
*/
addEventWiring(callback: () => void) {
if (this._appInstanceReady) {
callback();
} else {
if (!this.appEventWiring) {
this.appEventWiring = [];
}
this.appEventWiring.push(callback);
}
}
private _setLaunchedFn() {
// console.log('NativeScriptGlobals launch fired!');
this.launched = true;

View File

@@ -7,6 +7,7 @@
"noImplicitAny": false,
"noImplicitUseStrict": true,
"removeComments": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"diagnostics": true,
"sourceMap": true,

View File

@@ -62,6 +62,7 @@ function initializeMenuItemClickListener(): void {
AppCompatTextView = androidx.appcompat.widget.AppCompatTextView;
@NativeClass
@Interfaces([androidx.appcompat.widget.Toolbar.OnMenuItemClickListener])
class MenuItemClickListenerImpl extends java.lang.Object implements androidx.appcompat.widget.Toolbar.OnMenuItemClickListener {
constructor(public owner: ActionBar) {

View File

@@ -199,6 +199,7 @@ function initializeNativeClasses() {
}
}
@NativeClass
@Interfaces([android.view.View.OnAttachStateChangeListener])
class AttachListener extends java.lang.Object implements android.view.View.OnAttachStateChangeListener {
constructor() {

View File

@@ -25,6 +25,7 @@ function initializeClickListener(): void {
return;
}
@NativeClass
@Interfaces([android.view.View.OnClickListener])
class ClickListenerImpl extends java.lang.Object implements android.view.View.OnClickListener {
constructor(public owner: Button) {

View File

@@ -93,6 +93,7 @@ function initializeTouchListener(): void {
return;
}
@NativeClass
@Interfaces([android.view.View.OnTouchListener])
class TouchListenerImpl extends java.lang.Object implements android.view.View.OnTouchListener {
private owner: WeakRef<View>;
@@ -122,212 +123,68 @@ function initializeTouchListener(): void {
TouchListener = TouchListenerImpl;
}
// function initializeDialogFragment() {
// if (DialogFragment) {
// return;
// }
// @NativeClass
// class DialogImpl extends android.app.Dialog {
// constructor(public fragment: DialogFragmentImpl, context: android.content.Context, themeResId: number) {
// super(context, themeResId);
// return global.__native(this);
// }
// public onDetachedFromWindow(): void {
// super.onDetachedFromWindow();
// this.fragment = null;
// }
// public onBackPressed(): void {
// const view = this.fragment.owner;
// const args = <AndroidActivityBackPressedEventData>{
// eventName: 'activityBackPressed',
// object: view,
// activity: view._context,
// cancel: false,
// };
// // Fist fire application.android global event
// androidApp.notify(args);
// if (args.cancel) {
// return;
// }
// view.notify(args);
// if (!args.cancel && !view.onBackPressed()) {
// super.onBackPressed();
// }
// }
// }
// class DialogFragmentImpl extends androidx.fragment.app.DialogFragment {
// public owner: View;
// private _fullscreen: boolean;
// private _animated: boolean;
// private _stretched: boolean;
// private _cancelable: boolean;
// private _shownCallback: () => void;
// private _dismissCallback: () => void;
// constructor() {
// super();
// return global.__native(this);
// }
// public onCreateDialog(savedInstanceState: android.os.Bundle): android.app.Dialog {
// const ownerId = this.getArguments().getInt(DOMID);
// const options = getModalOptions(ownerId);
// this.owner = options.owner;
// // Set owner._dialogFragment to this in case the DialogFragment was recreated after app suspend
// this.owner._dialogFragment = this;
// this._fullscreen = options.fullscreen;
// this._animated = options.animated;
// this._cancelable = options.cancelable;
// this._stretched = options.stretched;
// this._dismissCallback = options.dismissCallback;
// this._shownCallback = options.shownCallback;
// this.setStyle(androidx.fragment.app.DialogFragment.STYLE_NO_TITLE, 0);
// let theme = this.getTheme();
// if (this._fullscreen) {
// // In fullscreen mode, get the application's theme.
// theme = this.getActivity().getApplicationInfo().theme;
// }
// const dialog = new DialogImpl(this, this.getActivity(), theme);
// // do not override alignment unless fullscreen modal will be shown;
// // otherwise we might break component-level layout:
// // https://github.com/NativeScript/NativeScript/issues/5392
// if (!this._fullscreen && !this._stretched) {
// this.owner.horizontalAlignment = 'center';
// this.owner.verticalAlignment = 'middle';
// } else {
// this.owner.horizontalAlignment = 'stretch';
// this.owner.verticalAlignment = 'stretch';
// }
// // set the modal window animation
// // https://github.com/NativeScript/NativeScript/issues/5989
// if (this._animated) {
// dialog.getWindow().setWindowAnimations(styleAnimationDialog);
// }
// dialog.setCanceledOnTouchOutside(this._cancelable);
// return dialog;
// }
// public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle): android.view.View {
// const owner = this.owner;
// owner._setupAsRootView(this.getActivity());
// owner._isAddedToNativeVisualTree = true;
// return owner.nativeViewProtected;
// }
// public onStart(): void {
// super.onStart();
// if (this._fullscreen) {
// const window = this.getDialog().getWindow();
// const length = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
// window.setLayout(length, length);
// // This removes the default backgroundDrawable so there are no margins.
// window.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.WHITE));
// }
// const owner = this.owner;
// if (owner && !owner.isLoaded) {
// owner.callLoaded();
// }
// this._shownCallback();
// }
// public onDismiss(dialog: android.content.DialogInterface): void {
// super.onDismiss(dialog);
// const manager = this.getFragmentManager();
// if (manager) {
// removeModal(this.owner._domId);
// this._dismissCallback();
// }
// const owner = this.owner;
// if (owner && owner.isLoaded) {
// owner.callUnloaded();
// }
// }
// public onDestroy(): void {
// super.onDestroy();
// const owner = this.owner;
// if (owner) {
// // Android calls onDestroy before onDismiss.
// // Make sure we unload first and then call _tearDownUI.
// if (owner.isLoaded) {
// owner.callUnloaded();
// }
// owner._isAddedToNativeVisualTree = false;
// owner._tearDownUI(true);
// }
// }
// }
// DialogFragment = DialogFragmentImpl;
// }
function initializeDialogFragment() {
if (DialogFragment) {
return;
}
var DialogImpl = (function (_super) {
__extends(DialogImpl, _super);
function DialogImpl(fragment, context, themeResId) {
var _this = _super.call(this, context, themeResId) || this;
_this.fragment = fragment;
return global.__native(_this);
@NativeClass
class DialogImpl extends android.app.Dialog {
constructor(public fragment: DialogFragmentImpl, context: android.content.Context, themeResId: number) {
super(context, themeResId);
return global.__native(this);
}
DialogImpl.prototype.onDetachedFromWindow = function () {
_super.prototype.onDetachedFromWindow.call(this);
public onDetachedFromWindow(): void {
super.onDetachedFromWindow();
this.fragment = null;
};
DialogImpl.prototype.onBackPressed = function () {
var view = this.fragment.owner;
if (!view) {
return;
}
var args = {
}
public onBackPressed(): void {
const view = this.fragment.owner;
const args = <AndroidActivityBackPressedEventData>{
eventName: 'activityBackPressed',
object: view,
activity: view._context,
cancel: false,
};
application_1.android.notify(args);
// Fist fire application.android global event
androidApp.notify(args);
if (args.cancel) {
return;
}
view.notify(args);
if (!args.cancel && !view.onBackPressed()) {
_super.prototype.onBackPressed.call(this);
super.onBackPressed();
}
};
return DialogImpl;
})(android.app.Dialog);
var DialogFragmentImpl = (function (_super) {
__extends(DialogFragmentImpl, _super);
function DialogFragmentImpl() {
var _this = _super.call(this) || this;
return global.__native(_this);
}
DialogFragmentImpl.prototype.onCreateDialog = function (savedInstanceState) {
var ownerId = this.getArguments().getInt(DOMID);
var options = getModalOptions(ownerId);
}
class DialogFragmentImpl extends androidx.fragment.app.DialogFragment {
public owner: View;
private _fullscreen: boolean;
private _animated: boolean;
private _stretched: boolean;
private _cancelable: boolean;
private _shownCallback: () => void;
private _dismissCallback: () => void;
constructor() {
super();
return global.__native(this);
}
public onCreateDialog(savedInstanceState: android.os.Bundle): android.app.Dialog {
const ownerId = this.getArguments().getInt(DOMID);
const options = getModalOptions(ownerId);
this.owner = options.owner;
// Set owner._dialogFragment to this in case the DialogFragment was recreated after app suspend
this.owner._dialogFragment = this;
this._fullscreen = options.fullscreen;
this._animated = options.animated;
this._cancelable = options.cancelable;
@@ -335,11 +192,18 @@ function initializeDialogFragment() {
this._dismissCallback = options.dismissCallback;
this._shownCallback = options.shownCallback;
this.setStyle(androidx.fragment.app.DialogFragment.STYLE_NO_TITLE, 0);
var theme = this.getTheme();
let theme = this.getTheme();
if (this._fullscreen) {
// In fullscreen mode, get the application's theme.
theme = this.getActivity().getApplicationInfo().theme;
}
var dialog = new DialogImpl(this, this.getActivity(), theme);
const dialog = new DialogImpl(this, this.getActivity(), theme);
// do not override alignment unless fullscreen modal will be shown;
// otherwise we might break component-level layout:
// https://github.com/NativeScript/NativeScript/issues/5392
if (!this._fullscreen && !this._stretched) {
this.owner.horizontalAlignment = 'center';
this.owner.verticalAlignment = 'middle';
@@ -347,57 +211,75 @@ function initializeDialogFragment() {
this.owner.horizontalAlignment = 'stretch';
this.owner.verticalAlignment = 'stretch';
}
// set the modal window animation
// https://github.com/NativeScript/NativeScript/issues/5989
if (this._animated) {
dialog.getWindow().setWindowAnimations(styleAnimationDialog);
}
dialog.setCanceledOnTouchOutside(this._cancelable);
return dialog;
};
DialogFragmentImpl.prototype.onCreateView = function (inflater, container, savedInstanceState) {
var owner = this.owner;
}
public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle): android.view.View {
const owner = this.owner;
owner._setupAsRootView(this.getActivity());
owner._isAddedToNativeVisualTree = true;
return owner.nativeViewProtected;
};
DialogFragmentImpl.prototype.onStart = function () {
_super.prototype.onStart.call(this);
}
public onStart(): void {
super.onStart();
if (this._fullscreen) {
var window_1 = this.getDialog().getWindow();
var length_1 = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
window_1.setLayout(length_1, length_1);
window_1.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.WHITE));
const window = this.getDialog().getWindow();
const length = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
window.setLayout(length, length);
// This removes the default backgroundDrawable so there are no margins.
window.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.WHITE));
}
var owner = this.owner;
const owner = this.owner;
if (owner && !owner.isLoaded) {
owner.callLoaded();
}
this._shownCallback();
};
DialogFragmentImpl.prototype.onDismiss = function (dialog) {
_super.prototype.onDismiss.call(this, dialog);
var manager = this.getFragmentManager();
}
public onDismiss(dialog: android.content.DialogInterface): void {
super.onDismiss(dialog);
const manager = this.getFragmentManager();
if (manager) {
removeModal(this.owner._domId);
this._dismissCallback();
}
var owner = this.owner;
const owner = this.owner;
if (owner && owner.isLoaded) {
owner.callUnloaded();
}
};
DialogFragmentImpl.prototype.onDestroy = function () {
_super.prototype.onDestroy.call(this);
var owner = this.owner;
}
public onDestroy(): void {
super.onDestroy();
const owner = this.owner;
if (owner) {
// Android calls onDestroy before onDismiss.
// Make sure we unload first and then call _tearDownUI.
if (owner.isLoaded) {
owner.callUnloaded();
}
owner._isAddedToNativeVisualTree = false;
owner._tearDownUI(true);
}
};
return DialogFragmentImpl;
})(androidx.fragment.app.DialogFragment);
}
}
DialogFragment = DialogFragmentImpl;
}

View File

@@ -13,6 +13,7 @@ function initializeDateChangedListener(): void {
return;
}
@NativeClass
@Interfaces([android.widget.DatePicker.OnDateChangedListener])
class DateChangedListenerImpl extends java.lang.Object implements android.widget.DatePicker.OnDateChangedListener {
constructor(public owner: DatePicker) {

View File

@@ -47,6 +47,7 @@ function initializeEditTextListeners(): void {
return;
}
@NativeClass
@Interfaces([android.text.TextWatcher, android.view.View.OnFocusChangeListener, android.widget.TextView.OnEditorActionListener])
class EditTextListenersImpl extends java.lang.Object implements android.text.TextWatcher, android.view.View.OnFocusChangeListener, android.widget.TextView.OnEditorActionListener {
constructor(private owner: EditableTextBase) {

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();

View File

@@ -24,6 +24,7 @@ function initializeImageLoadedListener() {
return;
}
@NativeClass
@Interfaces([org.nativescript.widgets.image.Worker.OnImageLoadedListener])
class ImageLoadedListenerImpl extends java.lang.Object implements org.nativescript.widgets.image.Worker.OnImageLoadedListener {
constructor(public owner: Image) {

View File

@@ -24,6 +24,7 @@ function initializeNativeClasses(): void {
return;
}
@NativeClass
@Interfaces([android.widget.NumberPicker.Formatter])
class FormatterImpl extends java.lang.Object implements android.widget.NumberPicker.Formatter {
constructor(private owner: ListPicker) {
@@ -37,6 +38,7 @@ function initializeNativeClasses(): void {
}
}
@NativeClass
@Interfaces([android.widget.NumberPicker.OnValueChangeListener])
class ValueChangeListenerImpl extends java.lang.Object implements android.widget.NumberPicker.OnValueChangeListener {
constructor(private owner: ListPicker) {

View File

@@ -27,6 +27,7 @@ function initializeItemClickListener(): void {
return;
}
@NativeClass
@Interfaces([android.widget.AdapterView.OnItemClickListener])
class ItemClickListenerImpl extends java.lang.Object implements android.widget.AdapterView.OnItemClickListener {
constructor(public owner: ListView) {

View File

@@ -26,6 +26,7 @@ function initializeNativeClasses(): void {
return;
}
@NativeClass
@Interfaces([androidx.appcompat.widget.SearchView.OnQueryTextListener])
class CompatQueryTextListenerImpl extends java.lang.Object implements androidx.appcompat.widget.SearchView.OnQueryTextListener {
constructor(private owner: SearchBar) {
@@ -62,6 +63,7 @@ function initializeNativeClasses(): void {
}
}
@NativeClass
@Interfaces([androidx.appcompat.widget.SearchView.OnCloseListener])
class CompatCloseListenerImpl extends java.lang.Object implements androidx.appcompat.widget.SearchView.OnCloseListener {
constructor(private owner: SearchBar) {

View File

@@ -39,6 +39,7 @@ function initializeNativeClasses(): void {
// Indicator thickness for material - 2dip. For pre-material - 5dip.
selectedIndicatorThickness = layout.toDevicePixels(apiLevel >= 21 ? 2 : 5);
@NativeClass
@Interfaces([android.widget.TabHost.OnTabChangeListener])
class TabChangeListenerImpl extends java.lang.Object implements android.widget.TabHost.OnTabChangeListener {
constructor(public owner: SegmentedBar) {
@@ -55,6 +56,7 @@ function initializeNativeClasses(): void {
}
}
@NativeClass
@Interfaces([android.widget.TabHost.TabContentFactory])
class TabContentFactoryImpl extends java.lang.Object implements android.widget.TabHost.TabContentFactory {
constructor(public owner: SegmentedBar) {

View File

@@ -14,6 +14,7 @@ let SeekBarChangeListener: android.widget.SeekBar.OnSeekBarChangeListener;
function initializeListenerClass(): void {
if (!SeekBarChangeListener) {
@NativeClass
@Interfaces([android.widget.SeekBar.OnSeekBarChangeListener])
class SeekBarChangeListenerImpl extends java.lang.Object implements android.widget.SeekBar.OnSeekBarChangeListener {
constructor() {

View File

@@ -247,24 +247,23 @@ function onLivesync(args): void {
imageFetcher.clearCache();
}
}
application.on('livesync', onLivesync);
application.android.on(
'activityStarted',
<any>profile('initImageCache', (args) => {
(<any>global).NativeScriptGlobals.events.on('livesync', onLivesync);
(<any>global).NativeScriptGlobals.addEventWiring(() => {
application.android.on('activityStarted', (args) => {
if (!imageFetcher) {
initImageCache(args.activity);
} else {
imageFetcher.initCache();
}
})
);
});
});
application.android.on(
'activityStopped',
<any>profile('closeImageCache', (args) => {
(<any>global).NativeScriptGlobals.addEventWiring(() => {
application.android.on('activityStopped', (args) => {
if (imageFetcher) {
imageFetcher.closeCache();
}
})
);
});
});

View File

@@ -355,8 +355,8 @@ const loadCss = profile(`"style-scope".loadCss`, (cssModule: string) => {
}
});
application.on('cssChanged', <any>onCssChanged);
application.on('livesync', onLiveSync);
(<any>global).NativeScriptGlobals.events.on('cssChanged', <any>onCssChanged);
(<any>global).NativeScriptGlobals.events.on('livesync', onLiveSync);
// Call to this method is injected in the application in:
// - no-snapshot - code injected in app.ts by [bundle-config-loader](https://github.com/NativeScript/nativescript-dev-webpack/blob/9b1e34d8ef838006c9b575285c42d2304f5f02b5/bundle-config-loader.ts#L85-L92)
@@ -365,7 +365,7 @@ application.on('livesync', onLiveSync);
// when the snapshot is created - there is no way to use file qualifiers or change the name of on app.css
export const loadAppCSS = profile('"style-scope".loadAppCSS', (args: application.LoadAppCSSEventData) => {
loadCss(args.cssFile, null, null);
application.off('loadAppCss', loadAppCSS);
(<any>global).NativeScriptGlobals.events.off('loadAppCss', loadAppCSS);
});
if (application.hasLaunched()) {
@@ -379,7 +379,7 @@ if (application.hasLaunched()) {
null
);
} else {
application.on('loadAppCss', <any>loadAppCSS);
(<any>global).NativeScriptGlobals.events.on('loadAppCss', <any>loadAppCSS);
}
export class CssState {

View File

@@ -15,6 +15,7 @@ function initializeCheckedChangeListener(): void {
return;
}
@NativeClass
@Interfaces([android.widget.CompoundButton.OnCheckedChangeListener])
class CheckedChangeListenerImpl extends java.lang.Object implements android.widget.CompoundButton.OnCheckedChangeListener {
constructor(private owner: Switch) {

View File

@@ -25,6 +25,7 @@ function initializeTextTransformation(): void {
return;
}
@NativeClass
@Interfaces([android.text.method.TransformationMethod])
class TextTransformationImpl extends java.lang.Object implements android.text.method.TransformationMethod {
constructor(public textBase: TextBase) {

View File

@@ -15,6 +15,7 @@ function initializeTimeChangedListener(): void {
apiLevel = android.os.Build.VERSION.SDK_INT;
@NativeClass
@Interfaces([android.widget.TimePicker.OnTimeChangedListener])
class TimeChangedListenerImpl extends java.lang.Object implements android.widget.TimePicker.OnTimeChangedListener {
constructor(public owner: TimePicker) {

View File

@@ -24,6 +24,5 @@
"@nativescript/types-android": ["packages/types-android/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp", "platforms", "__tests__"],
"includes": ["packages/**/*.{ios,android}.ts"]
"exclude": ["node_modules", "tmp", "platforms", "__tests__"]
}