mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup android refs
This commit is contained in:
@@ -80,7 +80,7 @@ function initializeMenuItemClickListener(): void {
|
||||
}
|
||||
|
||||
MenuItemClickListener = MenuItemClickListenerImpl;
|
||||
appResources = (getNativeApp() as android.app.Application).getApplicationContext().getResources();
|
||||
appResources = getNativeApp<android.app.Application>().getApplicationContext().getResources();
|
||||
}
|
||||
|
||||
export class ActionItem extends ActionItemBase {
|
||||
@@ -310,7 +310,7 @@ export class ActionBar extends ActionBarBase {
|
||||
if (title !== undefined) {
|
||||
this.nativeViewProtected.setTitle(title);
|
||||
} else {
|
||||
const appContext = (getNativeApp() as android.app.Application).getApplicationContext();
|
||||
const appContext = getNativeApp<android.app.Application>().getApplicationContext();
|
||||
const appInfo = appContext.getApplicationInfo();
|
||||
const appLabel = appContext.getPackageManager().getApplicationLabel(appInfo);
|
||||
if (appLabel) {
|
||||
@@ -547,7 +547,7 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re
|
||||
|
||||
let result = null;
|
||||
if (icon.indexOf(RESOURCE_PREFIX) === 0) {
|
||||
const resourceId: number = resources.getIdentifier(icon.substr(RESOURCE_PREFIX.length), 'drawable', (getNativeApp() as android.app.Application).getApplicationContext().getPackageName());
|
||||
const resourceId: number = resources.getIdentifier(icon.substring(RESOURCE_PREFIX.length), 'drawable', getNativeApp<android.app.Application>().getApplicationContext().getPackageName());
|
||||
if (resourceId > 0) {
|
||||
result = resourceId;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import { profile } from '../../../profiling';
|
||||
import { unsetValue, PropertyOptions, CoerciblePropertyOptions, CssPropertyOptions, ShorthandPropertyOptions, CssAnimationPropertyOptions, isCssWideKeyword, isCssUnsetValue, isResetValue } from './property-shared';
|
||||
import { calc } from '@csstools/css-calc';
|
||||
|
||||
// Backwards compatibility
|
||||
export { unsetValue } from './property-shared';
|
||||
|
||||
const cssPropertyNames: string[] = [];
|
||||
const symbolPropertyMap = {};
|
||||
const cssSymbolPropertyMap = {};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { isAccessibilityServiceEnabled } from '../../../application';
|
||||
import { updateA11yPropertiesCallback } from '../../../application/helpers-common';
|
||||
import { ShowModalOptions, hiddenProperty } from '../view-base';
|
||||
import { Trace } from '../../../trace';
|
||||
import { layout, ios as iosUtils, SDK_VERSION } from '../../../utils';
|
||||
import { layout, ios as iosUtils, SDK_VERSION, getWindow } from '../../../utils';
|
||||
import { IOSHelper } from './view-helper';
|
||||
import { ios as iosBackground, Background } from '../../styling/background';
|
||||
import { perspectiveProperty, visibilityProperty, opacityProperty, rotateProperty, rotateXProperty, rotateYProperty, scaleXProperty, scaleYProperty, translateXProperty, translateYProperty, zIndexProperty, backgroundInternalProperty } from '../../styling/style-properties';
|
||||
@@ -1082,7 +1082,7 @@ export class CustomLayoutView extends ContainerView {
|
||||
nativeViewProtected: UIView;
|
||||
|
||||
createNativeView() {
|
||||
const window = iosUtils.getWindow();
|
||||
const window = getWindow<UIWindow>();
|
||||
return UIView.alloc().initWithFrame(window ? window.screen.bounds : UIScreen.mainScreen.bounds);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
*/
|
||||
import { DialogOptions, ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from './dialogs-common';
|
||||
import { getLabelColor, getButtonColors, isDialogOptions, inputType, capitalizationType, DialogStrings, parseLoginOptions } from './dialogs-common';
|
||||
import { ad } from '../../utils/native-helper';
|
||||
import { android as androidUtils } from '../../utils/native-helper';
|
||||
import { getNativeApp } from '../../application/helpers-common';
|
||||
|
||||
export * from './dialogs-common';
|
||||
|
||||
@@ -12,7 +13,7 @@ function isString(value): value is string {
|
||||
}
|
||||
|
||||
function createAlertDialog(options?: DialogOptions): android.app.AlertDialog.Builder {
|
||||
const alert = new android.app.AlertDialog.Builder(ad.getCurrentActivity(), options.theme ? options.theme : -1);
|
||||
const alert = new android.app.AlertDialog.Builder(androidUtils.getCurrentActivity(), options.theme ? options.theme : -1);
|
||||
alert.setTitle(options && isString(options.title) ? options.title : '');
|
||||
alert.setMessage(options && isString(options.message) ? options.message : '');
|
||||
if (options && options.cancelable === false) {
|
||||
@@ -202,7 +203,7 @@ export function prompt(...args): Promise<PromptResult> {
|
||||
try {
|
||||
const alert = createAlertDialog(options);
|
||||
|
||||
const input = new android.widget.EditText(ad.getCurrentActivity());
|
||||
const input = new android.widget.EditText(androidUtils.getCurrentActivity());
|
||||
|
||||
if (options) {
|
||||
if (options.inputType === inputType.password) {
|
||||
@@ -259,19 +260,19 @@ export function login(...args: any[]): Promise<LoginResult> {
|
||||
try {
|
||||
const alert = createAlertDialog(options);
|
||||
|
||||
const userNameInput = new android.widget.EditText(ad.getApplicationContext());
|
||||
const userNameInput = new android.widget.EditText(getNativeApp<android.app.Application>().getApplicationContext());
|
||||
|
||||
userNameInput.setHint(options.userNameHint ? options.userNameHint : '');
|
||||
userNameInput.setText(options.userName ? options.userName : '');
|
||||
|
||||
const passwordInput = new android.widget.EditText(ad.getApplicationContext());
|
||||
const passwordInput = new android.widget.EditText(getNativeApp<android.app.Application>().getApplicationContext());
|
||||
passwordInput.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
passwordInput.setTypeface(android.graphics.Typeface.DEFAULT);
|
||||
|
||||
passwordInput.setHint(options.passwordHint ? options.passwordHint : '');
|
||||
passwordInput.setText(options.password ? options.password : '');
|
||||
|
||||
const layout = new android.widget.LinearLayout(ad.getApplicationContext());
|
||||
const layout = new android.widget.LinearLayout(getNativeApp<android.app.Application>().getApplicationContext());
|
||||
layout.setOrientation(1);
|
||||
layout.addView(userNameInput);
|
||||
layout.addView(passwordInput);
|
||||
@@ -322,7 +323,7 @@ export function action(...args): Promise<string> {
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
try {
|
||||
const alert = new android.app.AlertDialog.Builder(ad.getCurrentActivity(), options.theme ? options.theme : -1);
|
||||
const alert = new android.app.AlertDialog.Builder(androidUtils.getCurrentActivity(), options.theme ? options.theme : -1);
|
||||
const message = options && isString(options.message) ? options.message : '';
|
||||
const title = options && isString(options.title) ? options.title : '';
|
||||
if (options && options.cancelable === false) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { View } from '../../ui/core/view';
|
||||
import type { View } from '../core/view';
|
||||
|
||||
declare namespace org {
|
||||
namespace nativescript {
|
||||
|
||||
2
packages/core/ui/embedding/index.d.ts
vendored
2
packages/core/ui/embedding/index.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import type { View } from '../../ui/core/view';
|
||||
import type { View } from '../core/view';
|
||||
|
||||
/**
|
||||
* Whether the app is embedded into a host project or standalone project
|
||||
|
||||
@@ -207,7 +207,7 @@ export class FragmentCallbacksImplementation implements AndroidFragmentCallbacks
|
||||
if (hasRemovingParent) {
|
||||
const nativeFrameView = this.frame.nativeViewProtected;
|
||||
if (nativeFrameView) {
|
||||
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable((getNativeApp() as android.app.Application).getApplicationContext().getResources(), this.backgroundBitmap);
|
||||
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(getNativeApp<android.app.Application>().getApplicationContext().getResources(), this.backgroundBitmap);
|
||||
this.frame._originalBackground = this.frame.backgroundColor || new Color('White');
|
||||
nativeFrameView.setBackgroundDrawable(bitmapDrawable);
|
||||
this.backgroundBitmap = null;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { View } from '../core/view';
|
||||
import { LinearGradient } from './linear-gradient';
|
||||
import { ClipPathFunction } from './clip-path-function';
|
||||
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX, FILE_PREFIX } from '../../utils';
|
||||
import { CSSValue, parse } from '../../css-value';
|
||||
import { CSSValue, parse } from '../../css-value/reworkcss-value';
|
||||
import { path, knownFolders } from '../../file-system';
|
||||
export * from './background-common';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Font as FontBase, parseFontFamily, genericFontFamilies, FontWeight, FontVariationSettings, FONTS_BASE_PATH } from './font-common';
|
||||
import { FontStyleType, FontWeightType, FontVariationSettingsType } from './font-interfaces';
|
||||
import { getNativeApp } from '../../application/helpers-common';
|
||||
import { Trace } from '../../trace';
|
||||
import { SDK_VERSION } from '../../utils/constants';
|
||||
import * as fs from '../../file-system';
|
||||
import { ad } from '../../utils';
|
||||
|
||||
export * from './font-common';
|
||||
|
||||
@@ -60,7 +60,7 @@ function computeFontCacheKey(fontFamily: string, font: Font) {
|
||||
function loadFontFromFile(fontFamily: string, font: Font): android.graphics.Typeface {
|
||||
const cacheKey = SDK_VERSION >= 26 ? computeFontCacheKey(fontFamily, font) : fontFamily;
|
||||
|
||||
appAssets = appAssets || (ad.getApplicationContext() as android.content.Context).getAssets();
|
||||
appAssets = appAssets || getNativeApp<android.app.Application>().getApplicationContext().getAssets();
|
||||
if (!appAssets) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ function initializeNativeClasses() {
|
||||
}
|
||||
|
||||
PagerAdapter = FragmentPagerAdapter;
|
||||
appResources = (getNativeApp() as android.app.Application).getApplicationContext().getResources();
|
||||
appResources = getNativeApp<android.app.Application>().getApplicationContext().getResources();
|
||||
}
|
||||
|
||||
function createTabItemSpec(item: TabViewItem): org.nativescript.widgets.TabItemSpec {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { View } from '../core/view';
|
||||
import { ViewBase } from '../core/view-base';
|
||||
import { BackstackEntry } from '../frame';
|
||||
import type { ViewBase } from '../core/view-base';
|
||||
import type { BackstackEntry } from '../frame';
|
||||
import { isNumber } from '../../utils/types';
|
||||
import { Transition } from '.';
|
||||
import { getRectFromProps, SharedTransition, SharedTransitionAnimationType, SharedTransitionEventData } from './shared-transition';
|
||||
import { ImageSource } from '../../image-source';
|
||||
import { ContentView } from '../content-view';
|
||||
import { GridLayout } from '../layouts/grid-layout';
|
||||
import { Screen } from '../../platform';
|
||||
import { Screen } from '../../platform/screen';
|
||||
import { ExpandedEntry } from '../frame/fragment.transitions.android';
|
||||
import { android as AndroidUtils } from '../../utils/native-helper';
|
||||
import { android as androidUtils } from '../../utils/native-helper';
|
||||
// import { Image } from '../image';
|
||||
|
||||
@NativeClass
|
||||
@@ -289,10 +289,10 @@ function loadViewInBackground(view: View) {
|
||||
hiddenHost.content = hostView;
|
||||
hiddenHost.visibility = 'collapse';
|
||||
hostView.addChild(view);
|
||||
hiddenHost._setupAsRootView(AndroidUtils.getApplicationContext());
|
||||
hiddenHost._setupAsRootView(androidUtils.getApplicationContext());
|
||||
hiddenHost.callLoaded();
|
||||
|
||||
AndroidUtils.getCurrentActivity().addContentView(hiddenHost.android, new android.view.ViewGroup.LayoutParams(0, 0));
|
||||
androidUtils.getCurrentActivity().addContentView(hiddenHost.android, new android.view.ViewGroup.LayoutParams(0, 0));
|
||||
|
||||
return {
|
||||
hiddenHost,
|
||||
|
||||
Reference in New Issue
Block a user