dev android,and complete load context

This commit is contained in:
pengfei.zhou
2019-07-18 16:29:24 +08:00
parent f2fc57bbc7
commit 2a34d7b638
21 changed files with 425 additions and 43 deletions

View File

@@ -0,0 +1,29 @@
import { Text, Alignment, Color, VLayout, Registor, Panel, log, logw, loge } from "./index"
const v = new Text
v.width = 20
v.height = 30
v.left = 5
v.top = 5
v.bgColor = Color.parse('#00ff00')
v.config = {
alignment: Alignment.start
}
console.log(v.toModel())
const layout = new VLayout
layout.space = 10
console.log(layout.viewId)
console.log(layout.toModel())
@Registor
export class MyPage extends Panel {
build() {
return layout
}
log() {
log("Hello.HEGO")
logw("Hello.HEGO")
loge("Hello.HEGO")
}
}

View File

@@ -1,31 +1,4 @@
import { Text, Alignment, VLayout, Gravity } from "./src/ui/view";
import { Color } from "./src/util/color";
import { Panel, Registor } from "./src/ui/panel";
export * from "./src/ui/view"
export * from "./src/ui/panel"
export * from "./src/util/color"
const v = new Text
v.width = 20
v.height = 30
v.left = 5
v.top = 5
v.bgColor = Color.parse('#00ff00')
v.config = {
alignment: Alignment.start
}
console.log(v.toModel())
const layout = new VLayout
layout.space = 10
console.log(layout.viewId)
console.log(layout.toModel())
// @Registor
class MyPage extends Panel {
build(): import("./src/ui/view").View {
throw new Error("Method not implemented.");
}
}
console.log('end')
export * from './src/util/log'

View File

@@ -29,4 +29,17 @@ export default [
commonjs()
]
},
{
input: "build/index.test.js",
output: {
format: "cjs",
file: "bundle/test.js",
},
sourceMap: true,
plugins: [
resolve({ jsnext: true, main: true }),
commonjs()
],
external: ['./index'],
},
]

View File

@@ -8,9 +8,9 @@ import { loge } from "../util/log";
* function(hego,context,require){
* //Script content
* REG()
* },hego.obtainContext(id),[
* },hego.jsObtainContext(id),[
* undefined,
* hego.obtainContext(id),
* hego.jsObtainContext(id),
* hego.__require__,
* ])
* // load module in global scope
@@ -24,6 +24,7 @@ import { loge } from "../util/log";
*
* ```
*/
declare function nativeRequire(moduleName: string): boolean
declare function nativeBridge(contextId: string, namespace: string, method: string, args?: any, callbackId?: string): boolean

View File

@@ -1,11 +1,29 @@
declare function nativeLog(type: 'd' | 'w' | 'e', message: string): void
function toString(message: any) {
if (message instanceof Function) {
return message.toString()
} else if (message instanceof Object) {
try {
return JSON.stringify(message)
} catch (e) {
return message.toString()
}
} else if (message === undefined) {
return "undefined"
} else {
return message.toString()
}
}
export function log(message: any) {
console.log(message)
nativeLog('d', toString(message))
}
export function loge(message: any) {
console.error(message)
nativeLog('e', toString(message))
}
export function logw(message: any) {
console.warn(message)
nativeLog('w', toString(message))
}