feat: Scoped Packages (#7911)

* chore: move tns-core-modules to nativescript-core

* chore: preparing compat generate script

* chore: add missing definitions

* chore: no need for http-request to be private

* chore: packages chore

* test: generate tests for tns-core-modules

* chore: add anroid module for consistency

* chore: add .npmignore

* chore: added privateModulesWhitelist

* chore(webpack): added bundle-entry-points

* chore: scripts

* chore: tests changed to use @ns/core

* test: add scoped-packages test project

* test: fix types

* test: update test project

* chore: build scripts

* chore: update build script

* chore: npm scripts cleanup

* chore: make the compat pgk work with old wp config

* test: generate diff friendly tests

* chore: create barrel exports

* chore: move files after rebase

* chore: typedoc config

* chore: compat mode

* chore: review of barrels

* chore: remove tns-core-modules import after rebase

* chore: dev workflow setup

* chore: update developer-workflow

* docs: experiment with API extractor

* chore: api-extractor and barrel exports

* chore: api-extractor configs

* chore: generate d.ts rollup with api-extractor

* refactor: move methods inside Frame

* chore: fic tests to use Frame static methods

* refactor: create Builder class

* refactor: use Builder class in tests

* refactor: include Style in ui barrel

* chore: separate compat build script

* chore: fix tslint errors

* chore: update NATIVESCRIPT_CORE_ARGS

* chore: fix compat pack

* chore: fix ui-test-app build with linked modules

* chore: Application, ApplicationSettings, Connectivity and Http

* chore: export Trace, Profiling and Utils

* refactor: Static create methods for ImageSource

* chore: fix deprecated usages of ImageSource

* chore: move Span and FormattedString to ui

* chore: add events-args and ImageSource to index files

* chore: check for CLI >= 6.2 when building for IOS

* chore: update travis build

* chore: copy Pod file to compat package

* chore: update error msg ui-tests-app

* refactor: Apply suggestions from code review

Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com>

* chore: typings and refs

* chore: add missing d.ts files for public API

* chore: adress code review FB

* chore: update api-report

* chore: dev-workflow for other apps

* chore: api update

* chore: update api-report
This commit is contained in:
Alexander Vakrilov
2019-10-17 00:45:33 +03:00
committed by GitHub
parent 6c7139477e
commit cc97a16800
880 changed files with 9090 additions and 2104 deletions

View File

@ -0,0 +1,208 @@
import {
write as traceWrite, categories as traceCategories, messageType as traceMessageType
} from "../trace";
import { layoutCommon } from "./utils-common";
export * from "./utils-common";
let mainScreenScale;
function isOrientationLandscape(orientation: number) {
return orientation === UIDeviceOrientation.LandscapeLeft /* 3 */ ||
orientation === UIDeviceOrientation.LandscapeRight /* 4 */;
}
export module layout {
const MODE_SHIFT = 30;
const MODE_MASK = 0x3 << MODE_SHIFT;
export function makeMeasureSpec(size: number, mode: number): number {
return (Math.round(Math.max(0, size)) & ~MODE_MASK) | (mode & MODE_MASK);
}
export function getDisplayDensity(): number {
return mainScreenScale;
}
export function toDevicePixels(value: number): number {
return value * mainScreenScale;
}
export function toDeviceIndependentPixels(value: number): number {
return value / mainScreenScale;
}
export function measureNativeView(nativeView: any /* UIView */, width: number, widthMode: number, height: number, heightMode: number): { width: number, height: number } {
const view = <UIView>nativeView;
const nativeSize = view.sizeThatFits({
width: widthMode === 0 /* layout.UNSPECIFIED */ ? Number.POSITIVE_INFINITY : toDeviceIndependentPixels(width),
height: heightMode === 0 /* layout.UNSPECIFIED */ ? Number.POSITIVE_INFINITY : toDeviceIndependentPixels(height)
});
nativeSize.width = layoutCommon.round(toDevicePixels(nativeSize.width));
nativeSize.height = layoutCommon.round(toDevicePixels(nativeSize.height));
return nativeSize;
}
}
// TODO(webpack-workflow): Export all methods from layoutCommon
// Think of a cleaner way to do that
Object.assign(layout, layoutCommon);
export module ios {
// TODO: remove for NativeScript 7.0
export function getter<T>(_this: any, property: T | { (): T }): T {
console.log("utils.ios.getter() is deprecated; use the respective native property instead");
if (typeof property === "function") {
return (<{ (): T }>property).call(_this);
} else {
return <T>property;
}
}
export module collections {
export function jsArrayToNSArray(str: string[]): NSArray<any> {
return NSArray.arrayWithArray(<any>str);
}
export function nsArrayToJSArray(a: NSArray<any>): Array<Object> {
const arr = [];
if (a !== undefined) {
let count = a.count;
for (let i = 0; i < count; i++) {
arr.push(a.objectAtIndex(i));
}
}
return arr;
}
}
export function isLandscape(): boolean {
console.log("utils.ios.isLandscape() is deprecated; use application.orientation instead");
const deviceOrientation = UIDevice.currentDevice.orientation;
const statusBarOrientation = UIApplication.sharedApplication.statusBarOrientation;
const isDeviceOrientationLandscape = isOrientationLandscape(deviceOrientation);
const isStatusBarOrientationLandscape = isOrientationLandscape(statusBarOrientation);
return isDeviceOrientationLandscape || isStatusBarOrientationLandscape;
}
export const MajorVersion = NSString.stringWithString(UIDevice.currentDevice.systemVersion).intValue;
export function openFile(filePath: string): boolean {
console.log("utils.ios.openFile() is deprecated; use utils.openFile() instead");
return openFileAtRootModule(filePath);
}
export function getCurrentAppPath(): string {
const currentDir = __dirname;
const tnsModulesIndex = currentDir.indexOf("/tns_modules");
// Module not hosted in ~/tns_modules when bundled. Use current dir.
let appPath = currentDir;
if (tnsModulesIndex !== -1) {
// Strip part after tns_modules to obtain app root
appPath = currentDir.substring(0, tnsModulesIndex);
}
return appPath;
}
export function joinPaths(...paths: string[]): string {
if (!paths || paths.length === 0) {
return "";
}
return NSString.stringWithString(NSString.pathWithComponents(<any>paths)).stringByStandardizingPath;
}
export function getVisibleViewController(rootViewController: UIViewController): UIViewController {
if (rootViewController.presentedViewController) {
return getVisibleViewController(rootViewController.presentedViewController);
}
if (rootViewController.isKindOfClass(UINavigationController.class())) {
return getVisibleViewController((<UINavigationController>rootViewController).visibleViewController);
}
if (rootViewController.isKindOfClass(UITabBarController.class())) {
return getVisibleViewController(<UITabBarController>rootViewController);
}
return rootViewController;
}
}
export function openFile(filePath: string): boolean {
try {
const appPath = ios.getCurrentAppPath();
const path = filePath.replace("~", appPath);
const controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
controller.delegate = new UIDocumentInteractionControllerDelegateImpl();
return controller.presentPreviewAnimated(true);
}
catch (e) {
traceWrite("Error in openFile", traceCategories.Error, traceMessageType.error);
}
return false;
}
// Need this so that we can use this function inside the ios module (avoid name clashing).
const openFileAtRootModule = openFile;
export function GC() {
__collect();
}
export function releaseNativeObject(object: NSObject) {
__releaseNativeCounterpart(object);
}
export function openUrl(location: string): boolean {
try {
const url = NSURL.URLWithString(location.trim());
if (UIApplication.sharedApplication.canOpenURL(url)) {
return UIApplication.sharedApplication.openURL(url);
}
}
catch (e) {
// We Don't do anything with an error. We just output it
traceWrite("Error in OpenURL", traceCategories.Error, traceMessageType.error);
}
return false;
}
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
public getViewController(): UIViewController {
const app = UIApplication.sharedApplication;
return app.keyWindow.rootViewController;
}
public documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) {
return this.getViewController();
}
public documentInteractionControllerViewForPreview(controller: UIDocumentInteractionController) {
return this.getViewController().view;
}
public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect {
return this.getViewController().view.frame;
}
}
mainScreenScale = UIScreen.mainScreen.scale;