move dir
This commit is contained in:
64
doric-js/src/native/animate.ts
Normal file
64
doric-js/src/native/animate.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 { Panel } from "../ui/panel"
|
||||
import { takeLet } from "../pattern/candies"
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
/**
|
||||
* Only supports x,y,width,height,corner(just for four corners),rotation,bgColor,
|
||||
* @param panel @see Panel
|
||||
*/
|
||||
export function animate(context: BridgeContext) {
|
||||
const entity = context.entity
|
||||
if (entity instanceof Panel) {
|
||||
let panel = entity
|
||||
return (args: {
|
||||
animations: () => void,
|
||||
duration: number,
|
||||
}) => {
|
||||
return takeLet(panel.context.animate)(it => {
|
||||
return it.submit().then(() => {
|
||||
args.animations()
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
if (root.isDirty()) {
|
||||
const model = root.toModel();
|
||||
(model as any).duration = args.duration
|
||||
const ret = it.animateRender(model)
|
||||
root.clean()
|
||||
return ret
|
||||
}
|
||||
for (let v of panel.allHeadViews()) {
|
||||
if (v.isDirty()) {
|
||||
const model = v.toModel()
|
||||
const ret = it.animateRender(model)
|
||||
it.clean()
|
||||
return ret
|
||||
}
|
||||
}
|
||||
throw new Error('Cannot find any animated elements')
|
||||
})
|
||||
})
|
||||
}) as Promise<any>
|
||||
}
|
||||
} else {
|
||||
return (args: {
|
||||
animations: () => void,
|
||||
duration: number,
|
||||
}) => {
|
||||
return Promise.reject(`Cannot find panel in Context:${context.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
22
doric-js/src/native/index.native.ts
Normal file
22
doric-js/src/native/index.native.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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'
|
||||
export * from './popover'
|
||||
export * from './animate'
|
61
doric-js/src/native/modal.ts
Normal file
61
doric-js/src/native/modal.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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
doric-js/src/native/navbar.ts
Normal file
47
doric-js/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(),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
36
doric-js/src/native/navigator.ts
Normal file
36
doric-js/src/native/navigator.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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, config?: {
|
||||
alias?: string,
|
||||
animated?: boolean,
|
||||
extra?: object,
|
||||
}) => {
|
||||
if (config && config.extra) {
|
||||
(config as any).extra = JSON.stringify(config.extra)
|
||||
}
|
||||
return context.navigator.push({
|
||||
scheme, config
|
||||
})
|
||||
},
|
||||
pop: (animated = true) => {
|
||||
return context.navigator.pop({ animated })
|
||||
},
|
||||
}
|
||||
}
|
109
doric-js/src/native/network.ts
Normal file
109
doric-js/src/native/network.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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 interface IRequest {
|
||||
// `url` is the server URL that will be used for the request
|
||||
url?: string,
|
||||
// `method` is the request method to be used when making the request
|
||||
method?: "get" | "post" | "put" | "delete",
|
||||
// `headers` are custom headers to be sent
|
||||
headers?: { [index: string]: string }
|
||||
// `params` are the URL parameters to be sent with the request
|
||||
// Must be a plain object or a URLSearchParams object
|
||||
params?: { [index: string]: string }
|
||||
// `data` is the data to be sent as the request body
|
||||
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
|
||||
data?: object | string
|
||||
// `timeout` specifies the number of milliseconds before the request times out.
|
||||
// If the request takes longer than `timeout`, the request will be aborted.
|
||||
timeout?: number, // default is `0` (no timeout)
|
||||
}
|
||||
|
||||
export interface IResponse {
|
||||
// `data` is the response that was provided by the server
|
||||
data: any,
|
||||
// `status` is the HTTP status code from the server response
|
||||
status: number,
|
||||
// `headers` the headers that the server responded with
|
||||
// All header names are lower cased
|
||||
headers?: { [index: string]: string },
|
||||
}
|
||||
|
||||
function transformRequest(request: IRequest) {
|
||||
let url = request.url || ""
|
||||
if (request.params !== undefined) {
|
||||
const queryStrings = []
|
||||
for (let key in request.params) {
|
||||
queryStrings.push(`${key}=${encodeURIComponent(request.params[key])}`)
|
||||
}
|
||||
request.url = `${request.url}${url.indexOf('?') >= 0 ? '&' : '?'}${queryStrings.join('&')}`
|
||||
}
|
||||
if (typeof request.data === 'object') {
|
||||
request.data = JSON.stringify(request.data)
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
export function network(context: BridgeContext) {
|
||||
return {
|
||||
request: (config: IRequest) => {
|
||||
return context.network.request(transformRequest(config)) as Promise<IResponse>
|
||||
},
|
||||
get: (url: string, config?: IRequest) => {
|
||||
let finalConfig = config
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {}
|
||||
}
|
||||
finalConfig.url = url
|
||||
finalConfig.method = "get"
|
||||
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
||||
},
|
||||
post: (url: string, data?: object | string, config?: IRequest) => {
|
||||
let finalConfig = config
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {}
|
||||
}
|
||||
finalConfig.url = url
|
||||
finalConfig.method = "post"
|
||||
if (data !== undefined) {
|
||||
finalConfig.data = data
|
||||
}
|
||||
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
||||
},
|
||||
put: (url: string, data?: object | string, config?: IRequest) => {
|
||||
let finalConfig = config
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {}
|
||||
}
|
||||
finalConfig.url = url
|
||||
finalConfig.method = "put"
|
||||
if (data !== undefined) {
|
||||
finalConfig.data = data
|
||||
}
|
||||
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
||||
},
|
||||
delete: (url: string, data?: object | string, config?: IRequest) => {
|
||||
let finalConfig = config
|
||||
if (finalConfig === undefined) {
|
||||
finalConfig = {}
|
||||
}
|
||||
finalConfig.url = url
|
||||
finalConfig.method = "delete"
|
||||
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse>
|
||||
},
|
||||
}
|
||||
}
|
44
doric-js/src/native/popover.ts
Normal file
44
doric-js/src/native/popover.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 { View } from "../ui/view"
|
||||
import { Panel } from "../ui/panel"
|
||||
|
||||
export function popover(context: BridgeContext) {
|
||||
const entity = context.entity
|
||||
let panel: Panel | undefined = undefined
|
||||
if (entity instanceof Panel) {
|
||||
panel = entity
|
||||
}
|
||||
return {
|
||||
show: (view: View) => {
|
||||
if (panel) {
|
||||
panel.addHeadView(view)
|
||||
}
|
||||
return context.popover.show(view.toModel())
|
||||
},
|
||||
dismiss: (view: View | undefined = undefined) => {
|
||||
if (panel) {
|
||||
if (view) {
|
||||
panel.removeHeadView(view)
|
||||
} else {
|
||||
panel.clearHeadViews()
|
||||
}
|
||||
}
|
||||
return context.popover.dismiss(view ? { id: view.viewId } : undefined)
|
||||
},
|
||||
}
|
||||
}
|
33
doric-js/src/native/storage.ts
Normal file
33
doric-js/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 })
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user