提交 cd6afc80 编写于 作者: Q qiang

feat: 小程序 CanvasContext.measureText 支持异步返回

上级 14da9502
......@@ -34,7 +34,7 @@
"node": ">=10.0.0"
},
"devDependencies": {
"@dcloudio/types": "^2.0.0",
"@dcloudio/types": "^2.0.6",
"@ls-lint/ls-lint": "^1.8.0",
"@microsoft/api-extractor": "^7.3.9",
"@rollup/plugin-alias": "^3.1.1",
......
......@@ -2,7 +2,7 @@ import { isPlainObject, isArray } from '@vue/shared'
import { addSafeAreaInsets } from '@dcloudio/uni-mp-core'
export { redirectTo } from '@dcloudio/uni-mp-core'
export { redirectTo, createCanvasContext } from '@dcloudio/uni-mp-core'
function handleNetworkInfo(
fromRes: my.IGetNetworkTypeSuccessResult,
......
......@@ -2,7 +2,8 @@ export {
redirectTo,
previewImage,
getSystemInfo,
getSystemInfoSync
getSystemInfoSync,
createCanvasContext
} from '@dcloudio/uni-mp-core'
function createTodoMethod(contextName: string, methodName: string) {
......
......@@ -102,3 +102,19 @@ export const getSystemInfo = {
export const getSystemInfoSync = getSystemInfo
export const redirectTo = {}
export const createCanvasContext: MPProtocol = {
returnValue(fromRes: any, toRes: UniApp.CanvasContext) {
const measureText = fromRes.measureText
toRes.measureText = function(
text: string,
callback: (measureText: UniApp.CanvasTextMetrics) => void
) {
const textMetrics = measureText.call(this, text)
if (typeof callback === 'function') {
setTimeout(() => callback(textMetrics), 0)
}
return textMetrics
}
}
}
......@@ -38,7 +38,8 @@ export {
previewImage,
getSystemInfo,
getSystemInfoSync,
addSafeAreaInsets
addSafeAreaInsets,
createCanvasContext
} from './api/protocols'
// types
export { MiniProgramAppOptions, MiniProgramAppInstance } from './runtime/app'
......
......@@ -2,5 +2,6 @@ export {
redirectTo,
previewImage,
getSystemInfo,
getSystemInfoSync
getSystemInfoSync,
createCanvasContext
} from '@dcloudio/uni-mp-core'
export { redirectTo, previewImage } from '@dcloudio/uni-mp-core'
export {
redirectTo,
previewImage,
createCanvasContext
} from '@dcloudio/uni-mp-core'
export const chooseImage = {
args: {
sizeType: false
......
......@@ -2,5 +2,6 @@ export {
redirectTo,
previewImage,
getSystemInfo,
getSystemInfoSync
getSystemInfoSync,
createCanvasContext
} from '@dcloudio/uni-mp-core'
......@@ -2,5 +2,6 @@ export {
redirectTo,
previewImage,
getSystemInfo,
getSystemInfoSync
getSystemInfoSync,
createCanvasContext
} from '@dcloudio/uni-mp-core'
......@@ -271,10 +271,10 @@
exec-sh "^0.3.2"
minimist "^1.2.0"
"@dcloudio/types@^2.0.0":
version "2.0.5"
resolved "https://registry.npmjs.org/@dcloudio/types/-/types-2.0.5.tgz#4a1e719775b53363945548d45535d5386ffaeaf9"
integrity sha512-4lNLAEECY5DEqfsnWIKR2T3lgZKvZIHEpljHVcBr28evbae7GA6pbUnitkEoA7o+yW3E83Sin0hwWBnBfb7B1A==
"@dcloudio/types@^2.0.6":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.0.6.tgz#33daf724a58b593deef1294c210dad6509f1133d"
integrity sha512-ZOGaQMV2Xv8AtP2zBEURNVE62964fXZx1yCcMHRYxKPQtUzeOW0ZZVRkO6dxWLs/GE1GXTVJlJl/A9loLHqQOA==
"@eslint/eslintrc@^0.1.0":
version "0.1.0"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册