feat:split native module ts

This commit is contained in:
pengfei.zhou 2019-11-28 10:51:46 +08:00
parent c1b5b917b3
commit 84f12bd964
8 changed files with 202 additions and 107 deletions

View File

@ -29,4 +29,4 @@ export * from './src/util/gravity'
export * from './src/util/candies'
export * from './src/vm/mvvm'
export * from './src/runtime/global'
export * from './src/util/nativeModules'
export * from './src/native/index.native'

View File

@ -0,0 +1,20 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './modal'
export * from './navbar'
export * from './navigator'
export * from './network'
export * from './storage'

View File

@ -0,0 +1,62 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BridgeContext } from "../runtime/global"
import { Gravity } from "../util/gravity"
export function modal(context: BridgeContext) {
return {
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
context.modal.toast({
msg,
gravity: gravity.toModel(),
})
},
alert: (arg: string | {
title: string,
msg: string,
okLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.alert({ msg: arg })
} else {
return context.modal.alert(arg)
}
},
confirm: (arg: string | {
title: string,
msg: string,
okLabel?: string,
cancelLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg })
} else {
return context.modal.confirm(arg)
}
},
prompt: (arg: {
title?: string,
msg?: string,
okLabel?: string,
cancelLabel?: string,
text?: string,
defaultText?: string,
}) => {
return context.modal.prompt(arg) as Promise<string>
},
}
}

View File

@ -0,0 +1,47 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BridgeContext } from "../runtime/global"
import { Panel } from "../ui/panel"
import { Color } from "../util/color"
export function navbar(context: BridgeContext) {
const entity = context.entity
let panel: Panel | undefined = undefined
if (entity instanceof Panel) {
panel = entity
}
return {
isHidden: () => {
return context.navbar.isHidden() as Promise<boolean>
},
setHidden: (hidden: boolean) => {
return context.navbar.setHidden({
hidden,
})
},
setTitle: (title: string) => {
return context.navbar.setTitle({
title,
})
},
setBgColor: (color: Color) => {
return context.navbar.setBgColor({
color: color.toModel(),
})
},
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BridgeContext } from "../runtime/global"
export function navigator(context: BridgeContext) {
return {
push: (scheme: string, alias: string, animated = true) => {
return context.navigator.push({
scheme, alias, animated
})
},
pop: (animated = true) => {
return context.navigator.pop({ animated })
},
}
}

View File

@ -13,54 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BridgeContext } from "../runtime/global";
import { Gravity } from "./gravity";
import { Panel } from "../ui/panel";
import { Color } from "./color";
import { BridgeContext } from "../runtime/global"
export function modal(context: BridgeContext) {
return {
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
context.modal.toast({
msg,
gravity: gravity.toModel(),
})
},
alert: (arg: string | {
title: string,
msg: string,
okLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.alert({ msg: arg })
} else {
return context.modal.alert(arg)
}
},
confirm: (arg: string | {
title: string,
msg: string,
okLabel?: string,
cancelLabel?: string,
}) => {
if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg })
} else {
return context.modal.confirm(arg)
}
},
prompt: (arg: {
title?: string,
msg?: string,
okLabel?: string,
cancelLabel?: string,
text?: string,
defaultText?: string,
}) => {
return context.modal.prompt(arg) as Promise<string>
},
}
}
export interface IRequest {
// `url` is the server URL that will be used for the request
url?: string,
@ -103,6 +57,7 @@ function transformRequest(request: IRequest) {
}
return request
}
export function network(context: BridgeContext) {
return {
request: (config: IRequest) => {
@ -152,62 +107,3 @@ export function network(context: BridgeContext) {
},
}
}
export function storage(context: BridgeContext) {
return {
setItem: (key: string, value: string, zone?: string) => {
return context.storage.setItem({ key, value, zone })
},
getItem: (key: string, zone?: string) => {
return context.storage.getItem({ key, zone }) as Promise<string>
},
remove: (key: string, zone?: string) => {
return context.storage.remove({ key, zone })
},
clear: (zone: string) => {
return context.storage.clear({ zone })
},
}
}
export function navigator(context: BridgeContext) {
return {
push: (scheme: string, alias: string, animated = true) => {
return context.navigator.push({
scheme, alias, animated
})
},
pop: (animated = true) => {
return context.navigator.pop({ animated })
},
}
}
export function navbar(context: BridgeContext) {
const entity = context.entity
let panel: Panel | undefined = undefined
if (entity instanceof Panel) {
panel = entity
}
return {
isHidden: () => {
return context.navbar.isHidden() as Promise<boolean>
},
setHidden: (hidden: boolean) => {
return context.navbar.setHidden({
hidden,
})
},
setTitle: (title: string) => {
return context.navbar.setTitle({
title,
})
},
setBgColor: (color: Color) => {
return context.navbar.setBgColor({
color: color.toModel(),
})
},
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BridgeContext } from "../runtime/global"
export function storage(context: BridgeContext) {
return {
setItem: (key: string, value: string, zone?: string) => {
return context.storage.setItem({ key, value, zone })
},
getItem: (key: string, zone?: string) => {
return context.storage.getItem({ key, zone }) as Promise<string>
},
remove: (key: string, zone?: string) => {
return context.storage.remove({ key, zone })
},
clear: (zone: string) => {
return context.storage.clear({ zone })
},
}
}

View File

@ -50,6 +50,14 @@ export abstract class Panel {
this.headviews.set(v.viewId, v)
}
removeHeadView(v: View | string) {
if (v instanceof View) {
this.headviews.delete(v.viewId)
} else {
this.headviews.delete(v)
}
}
getRootView() {
return this.__root__
}