feat:split native module ts
This commit is contained in:
parent
c1b5b917b3
commit
84f12bd964
@ -29,4 +29,4 @@ export * from './src/util/gravity'
|
|||||||
export * from './src/util/candies'
|
export * from './src/util/candies'
|
||||||
export * from './src/vm/mvvm'
|
export * from './src/vm/mvvm'
|
||||||
export * from './src/runtime/global'
|
export * from './src/runtime/global'
|
||||||
export * from './src/util/nativeModules'
|
export * from './src/native/index.native'
|
||||||
|
20
js-framework/src/native/index.native.ts
Normal file
20
js-framework/src/native/index.native.ts
Normal 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'
|
62
js-framework/src/native/modal.ts
Normal file
62
js-framework/src/native/modal.ts
Normal 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>
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
47
js-framework/src/native/navbar.ts
Normal file
47
js-framework/src/native/navbar.ts
Normal 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(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
29
js-framework/src/native/navigator.ts
Normal file
29
js-framework/src/native/navigator.ts
Normal 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 })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -13,54 +13,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { BridgeContext } from "../runtime/global";
|
import { BridgeContext } from "../runtime/global"
|
||||||
import { Gravity } from "./gravity";
|
|
||||||
import { Panel } from "../ui/panel";
|
|
||||||
import { Color } from "./color";
|
|
||||||
|
|
||||||
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 {
|
export interface IRequest {
|
||||||
// `url` is the server URL that will be used for the request
|
// `url` is the server URL that will be used for the request
|
||||||
url?: string,
|
url?: string,
|
||||||
@ -103,6 +57,7 @@ function transformRequest(request: IRequest) {
|
|||||||
}
|
}
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
export function network(context: BridgeContext) {
|
export function network(context: BridgeContext) {
|
||||||
return {
|
return {
|
||||||
request: (config: IRequest) => {
|
request: (config: IRequest) => {
|
||||||
@ -151,63 +106,4 @@ export function network(context: BridgeContext) {
|
|||||||
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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(),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
33
js-framework/src/native/storage.ts
Normal file
33
js-framework/src/native/storage.ts
Normal 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 })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,14 @@ export abstract class Panel {
|
|||||||
this.headviews.set(v.viewId, v)
|
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() {
|
getRootView() {
|
||||||
return this.__root__
|
return this.__root__
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user