Skip to content

Commit

Permalink
native app
Browse files Browse the repository at this point in the history
  • Loading branch information
meepobrother committed May 3, 2019
1 parent b45e007 commit 91fcad9
Show file tree
Hide file tree
Showing 21 changed files with 487 additions and 161 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
/**/.rts2_cache_cjs
/**/.rts2_cache_es
/**/.rts2_cache_umd
/**/node_modules
/**/node_modules
/app
/hooks
3 changes: 2 additions & 1 deletion addon/nger-todo/template/admin/task-edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Page } from 'nger-core';

@Page({
path: 'task/edit',
type: 'admin',
type: ['admin'],
title: '编辑',
styleUrls: ['./index.scss']
})
Expand Down
7 changes: 2 additions & 5 deletions addon/nger-todo/template/admin/task-list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Page } from 'nger-core';
import { Table } from 'nger-ui'
import { NgerTodoAdminHome } from './index.controller'
@Page({
path: 'task/list',
type: 'admin',
type: ['admin'],
title: '任务',
styleUrls: ['./index.scss']
})
export class NgerTodoTaskListPage {
constructor(public controller: NgerTodoAdminHome) { }
render() {
return <Table onEditor={this.controller.onEditor} source={this.controller.getTasks()} />
}
render() {}
}
4 changes: 4 additions & 0 deletions nsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"appResourcesPath": "app/App_Resources",
"appPath": "app"
}
35 changes: 34 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@babel/template": "^7.4.4",
"@babel/traverse": "^7.4.4",
"@babel/types": "^7.4.4",
"@progress-nativechat/nativescript-nativechat": "2.0.3",
"@stencil/core": "^0.18.1",
"@types/autoprefixer": "^9.4.0",
"@types/babel__core": "^7.1.1",
Expand Down Expand Up @@ -71,6 +72,7 @@
"imagemin-mozjpeg": "^8.0.0",
"imagemin-pngquant": "^7.0.0",
"imagemin-svgo": "^7.0.0",
"kinvey-nativescript-sdk": "3.12.4",
"koa-compress": "^3.0.0",
"koa-webpack": "^5.2.2",
"less": "^3.9.0",
Expand All @@ -79,11 +81,31 @@
"mocha": "^6.1.4",
"multihashing": "^0.3.3",
"multihashing-async": "^0.7.0",
"nativescript-accelerometer": "2.0.1",
"nativescript-background-http": "3.4.0",
"nativescript-camera": "4.4.0",
"nativescript-dev-typescript": "0.9.0",
"nativescript-dev-webpack": "0.21.0",
"nativescript-fresco": "5.2.0",
"nativescript-geolocation": "5.0.0",
"nativescript-imagepicker": "6.1.2",
"nativescript-intl": "3.0.0",
"nativescript-iqkeyboardmanager": "1.4.0",
"nativescript-social-share": "1.5.1",
"nativescript-theme-core": "1.0.4",
"nativescript-ui-autocomplete": "4.0.0",
"nativescript-ui-calendar": "4.0.0",
"nativescript-ui-chart": "4.0.0",
"nativescript-ui-dataform": "4.0.0",
"nativescript-ui-gauge": "4.0.0",
"nativescript-ui-listview": "6.1.0",
"nativescript-ui-sidedrawer": "6.0.0",
"node-sass": "^4.11.0",
"ora": "^3.4.0",
"postcss": "^7.0.14",
"postcss-mpvue-wxss": "^1.0.2",
"postcss-wxss": "^1.0.6",
"preact": "^8.4.2",
"readable-stream": "^3.3.0",
"resolve-from": "^5.0.0",
"rollup": "^1.10.1",
Expand All @@ -95,6 +117,7 @@
"stylelint-webpack-plugin": "^0.10.5",
"stylus": "^0.54.5",
"tns-core-modules": "^5.3.1",
"tns-platform-declarations": "5.3.1",
"ts-loader": "^5.4.4",
"ts-node": "^8.1.0",
"tsconfig-paths": "^3.8.0",
Expand Down Expand Up @@ -133,6 +156,15 @@
"typeorm": "^0.2.16",
"webpack-merge": "^4.2.1"
},
"nativescript": {
"id": "org.nativescript.blankts",
"tns-android": {
"version": "5.3.0"
},
"tns-ios": {
"version": "5.3.0"
}
},
"scripts": {
"test": "mocha -r ts-node/register -r tsconfig-paths/register ./**/__tests__/**/*.ts",
"ts": "ts-node -r tsconfig-paths/register",
Expand All @@ -143,8 +175,9 @@
"admin:build": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build admin",
"admin:dev": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build admin --watch",
"admin:stats": "webpack-bundle-analyzer template/admin/stats.json",
"preview:android": "tns preview",
"platform:native": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build lib -n nger-platform-native",
"platform:ios": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build lib -n nger-platform-ios",
"platform:android": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build lib -n nger-platform-android"
}
}
}
2 changes: 1 addition & 1 deletion packages/nger-core/lib/decorators/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ComponentOptions<T = any> extends DirectiveOptions {
interpolation?: [string, string];
entryComponents?: Array<Type<any> | any[]>;
preserveWhitespaces?: boolean;
type: ComponentType[];
type?: ComponentType[];
}
// P 是props
// S 是state
Expand Down
24 changes: 13 additions & 11 deletions packages/nger-platform-browser/lib/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ export class BrowserApplicationRef extends ApplicationRef {
const factory = ref.injector.get(ComponentFactory)
const parent = ref.injector.get(ElementRef, null, InjectFlags.SkipSelf) || new ElementRef(this.root);
//这里渲染preact
const tpl = factory.def.render;
const res = tpl(ref.instance)
render(res, parent.nativeElement)
// 更新试图,后面有可能会自己实现
ref.$ngOnChange && ref.$ngOnChange.subscribe(() => {
if (ref.instance.render) {
const tpl = ref.instance.render();
const res = tpl(ref.instance)
render(res, parent.nativeElement, parent.nativeElement.lastElementChild)
});
super.attachView(ref, injector);
const nowTime = new Date().getTime();
const totalTime = nowTime - (window as any).nger.startTime
console.log(`总耗时:${totalTime}ms`);
render(res, parent.nativeElement)
// 更新试图,后面有可能会自己实现
ref.$ngOnChange && ref.$ngOnChange.subscribe(() => {
const res = tpl(ref.instance)
render(res, parent.nativeElement, parent.nativeElement.lastElementChild)
});
super.attachView(ref, injector);
const nowTime = new Date().getTime();
const totalTime = nowTime - (window as any).nger.startTime
console.log(`总耗时:${totalTime}ms`);
}
} catch (e) {
console.log({
ref, injector,
Expand Down
12 changes: 9 additions & 3 deletions packages/nger-platform-h5/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Cache } from 'nger-core'
export class NgerH5Cache extends Cache {
get<T>(key: string): Promise<T> { }
put<T>(key: string, value: T): Promise<boolean> { }
remove<T>(key: string): Promise<boolean> { }
get<T>(key: string): Promise<T> {
return new Promise(() => { })
}
put<T>(key: string, value: T): Promise<boolean> {
return new Promise(() => { })
}
remove<T>(key: string): Promise<boolean> {
return new Promise(() => { })
}
clear(): void { }
}
20 changes: 15 additions & 5 deletions packages/nger-platform-h5/lib/router.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { Router } from 'nger-core'
export class NgerH5Router extends Router {
// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
switchTab(url: string): Promise<boolean> { }
switchTab(url: string): Promise<boolean> {
return new Promise(() => { })
}
// 关闭所有页面,打开到应用内的某个页面
reLaunch(url: string): Promise<boolean> { }
reLaunch(url: string): Promise<boolean> {
return new Promise(() => { })
}
// 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
redirectTo(url: string): Promise<boolean> { }
redirectTo(url: string): Promise<boolean> {
return new Promise(() => { })
}
// 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面
navigateTo(url: string): Promise<boolean> { }
async navigateTo(url: string): Promise<boolean> {
return new Promise(() => { })
}
// 关闭当前页面,返回上一页面或多级页面
navigateBack(delta: number): Promise<boolean> { }
navigateBack(delta: number): Promise<boolean> {
return new Promise(() => { })
}
}
34 changes: 34 additions & 0 deletions packages/nger-platform-ios/lib/app-host-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ContentView } from "tns-core-modules/ui/content-view";
import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout";
import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container";
import { View } from "tns-core-modules/ui/core/view";

export class AppHostView extends ContentView {
private _ngAppRoot: View;
private _content: View;
get ngAppRoot(): View {
return this._ngAppRoot;
}
set ngAppRoot(value: View) {
this._ngAppRoot = value;
}
get content(): View {
return this._content;
}
set content(value: View) {
if (this._content) {
this._content.parentNode = undefined as any;
}
this._content = value;
if (value) {
this._content.parentNode = this;
}
this.ngAppRoot = value;
if (this._content instanceof ProxyViewContainer) {
const grid = new GridLayout();
grid.addChild(this._content);
this.ngAppRoot = grid;
}
}

}
49 changes: 46 additions & 3 deletions packages/nger-platform-ios/lib/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,55 @@
import { NgModuleBootstrap, NgModuleRef } from 'nger-core'
import { NgModuleBootstrap, NgModuleRef, ApplicationRef, NgModuleMetadataKey, NgModuleClassAst } from 'nger-core'
import {
run as applicationRun
run as applicationRun,
on,
launchEvent,
LaunchEventData,
exitEvent,
ApplicationEventData,
} from "tns-core-modules/application";
import { Injector } from 'nger-di'
import { profile, uptime } from "tns-core-modules/profiling";
import { View } from "tns-core-modules/ui/core/view/view";
import { Injector, InjectionToken } from 'nger-di'
import { AppHostView } from './app-host-view'
import { setRootPage } from 'nger-platform-native'
export const NATIVE_CONFIG = new InjectionToken(`NATIVE_CONFIG`)
export class NgerPlatformIosBootstrap extends NgModuleBootstrap {
injector: Injector;
async run(ref: NgModuleRef<any>) {
this.injector = ref.injector;
on('launch', (args) => {
console.log(`launch`)
})
on('exitEvent', (args) => {
console.log(`exitEvent`)
});
const config = ref.injector.get(NATIVE_CONFIG)
// ref.componentFactoryResolver.resolveComponentFactory()
const ngModule = ref.context.getClass(NgModuleMetadataKey) as NgModuleClassAst;
const bootstrap = ngModule.ast.metadataDef.bootstrap;
const root = document.getElementById('app') as HTMLDivElement;
const application = ref.injector.get(ApplicationRef)
let rootContent: View;
let tempAppHostView: AppHostView;
tempAppHostView = new AppHostView();
setRootPage(<any>tempAppHostView);
if (bootstrap) {
bootstrap.map(boot => {
const factory = ref.componentFactoryResolver.resolveComponentFactory(boot)
const component = factory.create(ref.injector);
})
}
const launchCallback = profile(
"nativescript-angular/platform-common.launchCallback",
(args: LaunchEventData) => {
console.log(`launchCallback`)
})
const exitCallback = profile(
"nativescript-angular/platform-common.exitCallback", (args: ApplicationEventData) => {
console.log(`exitCallback`)
})
on(launchEvent, launchCallback);
on(exitEvent, exitCallback);
applicationRun();
}
}
3 changes: 2 additions & 1 deletion packages/nger-platform-ios/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default createPlatformFactory(ngerPlatformNative, 'native', [
useClass: NgerPlatformIosBootstrap,
deps: []
}
])
])
export { NATIVE_CONFIG } from './bootstrap'
3 changes: 2 additions & 1 deletion packages/nger-platform-native/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import {platformCore,createPlatformFactory} from 'nger-core'
import platformProviders from './platform-providers'
export default createPlatformFactory(platformCore,'native',[
...platformProviders
])
])
export * from './platform-providers'
12 changes: 9 additions & 3 deletions packages/nger-platform-swap/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Cache } from 'nger-core'
export class NgerSwapCache extends Cache {
get<T>(key: string): Promise<T> { }
put<T>(key: string, value: T): Promise<boolean> { }
remove<T>(key: string): Promise<boolean> { }
get<T>(key: string): Promise<T> {
return new Promise(() => { })
}
put<T>(key: string, value: T): Promise<boolean> {
return new Promise(() => { })
}
remove<T>(key: string): Promise<boolean> {
return new Promise(() => { })
}
clear(): void { }
}
8 changes: 7 additions & 1 deletion packages/nger-platform-swap/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export class NgerSwapLogger implements Logger { }
import { Logger } from 'nger-core'
export class NgerSwapLogger implements Logger {
debug(...args: any[]) { }
info(...args: any[]) { }
warn(...args: any[]) { }
error(...args: any[]) { }
}
12 changes: 9 additions & 3 deletions packages/nger-platform-tt/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Cache } from 'nger-core'
export class NgerTtCache extends Cache {
get<T>(key: string): Promise<T> { }
put<T>(key: string, value: T): Promise<boolean> { }
remove<T>(key: string): Promise<boolean> { }
async get<T>(key: string): Promise<T> {
return new Promise(() => { })
}
async put<T>(key: string, value: T): Promise<boolean> {
return new Promise(() => { })
}
async remove<T>(key: string): Promise<boolean> {
return new Promise(() => { })
}
clear(): void { }
}
12 changes: 9 additions & 3 deletions packages/nger-platform-weapp/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Cache } from 'nger-core'
export class NgerWeappCache extends Cache {
get<T>(key: string): Promise<T> { }
put<T>(key: string, value: T): Promise<boolean> { }
remove<T>(key: string): Promise<boolean> { }
async get<T>(key: string): Promise<T> {
return new Promise(() => { })
}
async put<T>(key: string, value: T): Promise<boolean> {
return new Promise(() => { })
}
async remove<T>(key: string): Promise<boolean> {
return new Promise(() => { })
}
clear(): void { }
}
Loading

0 comments on commit 91fcad9

Please sign in to comment.