提交 d294cce7 编写于 作者: Q qiang

Merge branch 'dev' into alpha

MediaQueryObserver 对象,用于监听页面 media query 状态的变化,如界面的长宽是不是在某个指定的范围内。
### uni.createMediaQueryObserver([this])
创建并返回一个 ``MediaQueryObserver`` 对象实例。
**this说明:**
自定义组件实例。**支付宝小程序不支持此参数,传入仅为抹平写法差异**
### MediaQueryObserver 对象的方法列表
|方法|说明|
|:-|:-|
|MediaQueryObserver.observe(Object descriptor, function callback)|开始监听页面 media query 变化情况|
|MediaQueryObserver.disconnect()|停止监听,回调函数将不再触发|
**observe 回调函数包含一个参数**
||类型|说明|
|:-|:-|:-|
|intersectionRatio|boolean|页面的当前状态是否满足所指定的 media query|
### 代码示例
```
<template>
<view class="content">
<view class="">
matches: {{matches}}
</view>
<view>
landscape: {{landscape}}
</view>
<button type="success" @click="remove">destroy</button>
</view>
</view>
</template>
<script>
let landscapeObs, interObs
export default {
data() {
return {
matches: false,
landscape: false,
}
},
onLoad() {
},
mounted() {
this.testMediaQueryObserver()
this.landscapeObserver()
},
methods: {
changeMinWidth() {
console.log("======= changeMinWidth ======")
var that = this
setTimeout(() => {
that.minWidth = 420
console.log("that.minwidth", that.minWidth)
}, 1000)
},
testMediaQueryObserver() {
this.mediaQueryOb = uni.createMediaQueryObserver(this)
this.mediaQueryOb.observe({
minWidth: 305,
maxWidth: 400,
orientation: 'portrait'
}, matches => {
console.log('######### matches #########', matches)
this.matches = matches;
})
console.log('########## create mediaQueryOb ###########', this.mediaQueryOb)
},
landscapeObserver() {
// console.log('--------- this----------', this)
landscapeObs = uni.createMediaQueryObserver(this)
landscapeObs.observe({
}, matches => {
this.landscape = matches
})
console.log('--------- landscapeObs -------', landscapeObs)
return landscapeObs
},
remove() {
this.mediaQueryOb.disconnect()
landscapeObs.disconnect()
console.log('########## destroy mediaQueryOb ###########', this.mediaQueryOb)
}
}
}
</script>
<style>
.content {
text-align: center;
height: 400upx;
}
</style>
```
...@@ -92,6 +92,8 @@ const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g ...@@ -92,6 +92,8 @@ const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g
function normalizeNodeModules (str) { function normalizeNodeModules (str) {
str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules') str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules')
// HBuilderX 内置模块路径转换
str = str.replace(/.*HBuilderX\/plugins\/uniapp-cli\/node[-_]modules/, 'node-modules')
if (process.env.UNI_PLATFORM === 'mp-alipay') { if (process.env.UNI_PLATFORM === 'mp-alipay') {
str = str.replace('node-modules/@', 'node-modules/npm-scope-') str = str.replace('node-modules/@', 'node-modules/npm-scope-')
} }
...@@ -136,4 +138,4 @@ module.exports = { ...@@ -136,4 +138,4 @@ module.exports = {
getTemplatePath () { getTemplatePath () {
return path.join(__dirname, '../template') return path.join(__dirname, '../template')
} }
} }
...@@ -89,11 +89,7 @@ module.exports = function generateComponent (compilation) { ...@@ -89,11 +89,7 @@ module.exports = function generateComponent (compilation) {
let resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath)) let resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath))
const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath)) const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath))
if ( if (modulePath.includes('@dcloudio') && isBuiltInComponentPath(modulePath)) {
/^win/.test(process.platform) &&
modulePath.includes('@dcloudio') &&
isBuiltInComponentPath(modulePath)
) {
resource = normalizePath(path.resolve(process.env.UNI_CLI_CONTEXT, modulePath)) resource = normalizePath(path.resolve(process.env.UNI_CLI_CONTEXT, modulePath))
} }
...@@ -234,4 +230,4 @@ function removeUnusedComponent (name) { ...@@ -234,4 +230,4 @@ function removeUnusedComponent (name) {
fs.renameSync(path.join(process.env.UNI_OUTPUT_DIR, name + '.json'), path.join(process.env.UNI_OUTPUT_DIR, name + fs.renameSync(path.join(process.env.UNI_OUTPUT_DIR, name + '.json'), path.join(process.env.UNI_OUTPUT_DIR, name +
'.bak.json')) '.bak.json'))
} catch (e) {} } catch (e) {}
} }
...@@ -95,7 +95,7 @@ function createValidator (type) { ...@@ -95,7 +95,7 @@ function createValidator (type) {
} }
// 主要拦截目标为用户快速点击时触发的多次跳转,该情况,通常前后 url 是一样的 // 主要拦截目标为用户快速点击时触发的多次跳转,该情况,通常前后 url 是一样的
if (navigatorLock === url) { if (navigatorLock === url && params.openType !== 'appLaunch') {
return `${navigatorLock} locked` return `${navigatorLock} locked`
} }
// 至少 onLaunch 之后,再启用lock逻辑(onLaunch之前可能开发者手动调用路由API,来提前跳转) // 至少 onLaunch 之后,再启用lock逻辑(onLaunch之前可能开发者手动调用路由API,来提前跳转)
......
...@@ -328,38 +328,16 @@ export class CanvasContext { ...@@ -328,38 +328,16 @@ export class CanvasContext {
} }
} }
measureText (text, callback) { measureText (text) {
const font = this.state.font const font = this.state.font
let width
if (__PLATFORM__ === 'h5') { if (__PLATFORM__ === 'h5') {
const width = measureText(text, font) width = measureText(text, font)
const textMetrics = new TextMetrics(width)
if (typeof callback === 'function') {
setTimeout(() => callback(textMetrics), 0)
}
return textMetrics
} else { } else {
let textMetrics = new TextMetrics(0) const webview = plus.webview.getWebviewById(String(this.pageId))
if (typeof callback === 'function') { width = webview.evalJSSync(`(${measureText.toString()})(${JSON.stringify(text)},${JSON.stringify(font)})`)
const callbackId = canvasEventCallbacks.push(function ({ width }) {
callback(new TextMetrics(width))
})
operateCanvas(this.id, this.pageId, 'measureText', {
text,
font,
callbackId
})
} else {
const webview = plus.webview.getWebviewById(String(this.pageId))
if (webview && webview.evalJSSync) {
const js = `(${measureText.toString()})(${JSON.stringify(text)},${JSON.stringify(font)})`
const width = webview.evalJSSync(js) || 0
textMetrics = new TextMetrics(width)
} else {
console.error('warning: measureText missing required arguments: callback')
}
}
return textMetrics
} }
return new TextMetrics(width)
} }
save () { save () {
......
...@@ -277,22 +277,6 @@ export default { ...@@ -277,22 +277,6 @@ export default {
}, this.$page.id) }, this.$page.id)
} }
}, },
measureText ({
text,
font,
callbackId
}) {
const canvas = getTempCanvas()
const c2d = canvas.getContext('2d')
c2d.font = font
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'measureText:ok',
width: c2d.measureText(text).width || 0
}
}, this.$page.id)
},
preloadImage: function (actions) { preloadImage: function (actions) {
var self = this var self = this
actions.forEach(function (action) { actions.forEach(function (action) {
......
...@@ -3,7 +3,6 @@ import { ...@@ -3,7 +3,6 @@ import {
} from 'uni-shared' } from 'uni-shared'
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import createCanvasContext from '../../../mp-weixin/helpers/create-canvas-context'
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
...@@ -478,8 +477,7 @@ const protocols = { // 需要做转换的 API 列表 ...@@ -478,8 +477,7 @@ const protocols = { // 需要做转换的 API 列表
result.telNumber = info.mobilePhone result.telNumber = info.mobilePhone
result.errMsg = result.resultStatus result.errMsg = result.resultStatus
} }
}, }
createCanvasContext
} }
export { export {
......
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import createCanvasContext from '../../../mp-weixin/helpers/create-canvas-context'
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
...@@ -120,12 +119,11 @@ const protocols = { ...@@ -120,12 +119,11 @@ const protocols = {
getAccountInfoSync: { getAccountInfoSync: {
name: 'getEnvInfoSync', name: 'getEnvInfoSync',
returnValue: _handleEnvInfo returnValue: _handleEnvInfo
}, }
createCanvasContext
} }
export { export {
protocols, protocols,
todos, todos,
canIUses canIUses
} }
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import createCanvasContext from '../../../mp-weixin/helpers/create-canvas-context'
export const protocols = { export const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage
createCanvasContext
} }
export const todos = [ export const todos = [
'vibrate' 'vibrate'
......
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import createCanvasContext from '../../../mp-weixin/helpers/create-canvas-context'
export const protocols = { export const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage
createCanvasContext
} }
export const todos = [ export const todos = [
'preloadPage', 'preloadPage',
......
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import createCanvasContext from '../../../mp-weixin/helpers/create-canvas-context'
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
...@@ -101,8 +100,8 @@ const protocols = { ...@@ -101,8 +100,8 @@ const protocols = {
args: { args: {
sizeType: false sizeType: false
} }
}, },
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage,
connectSocket: { connectSocket: {
...@@ -170,8 +169,7 @@ const protocols = { ...@@ -170,8 +169,7 @@ const protocols = {
args: { args: {
digestAlgorithm: false digestAlgorithm: false
} }
}, }
createCanvasContext
} }
export { export {
......
export default {
returnValue (fromRes, toRes) {
const measureText = fromRes.measureText
toRes.measureText = function (text, callback) {
const textMetrics = measureText.call(this, text)
if (typeof callback === 'function') {
setTimeout(() => callback(textMetrics), 0)
}
return textMetrics
}
}
}
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../helpers/redirect-to' import redirectTo from '../../helpers/redirect-to'
import previewImage from '../../helpers/normalize-preview-image' import previewImage from '../../helpers/normalize-preview-image'
import createCanvasContext from '../../helpers/create-canvas-context'
function addSafeAreaInsets (result) { function addSafeAreaInsets (result) {
if (result.safeArea) { if (result.safeArea) {
...@@ -15,7 +14,7 @@ function addSafeAreaInsets (result) { ...@@ -15,7 +14,7 @@ function addSafeAreaInsets (result) {
} }
} }
export const protocols = { export const protocols = {
redirectTo, redirectTo,
navigateTo, navigateTo,
previewImage, previewImage,
getSystemInfo: { getSystemInfo: {
...@@ -23,8 +22,7 @@ export const protocols = { ...@@ -23,8 +22,7 @@ export const protocols = {
}, },
getSystemInfoSync: { getSystemInfoSync: {
returnValue: addSafeAreaInsets returnValue: addSafeAreaInsets
}, }
createCanvasContext
} }
export const todos = [ export const todos = [
'vibrate', 'vibrate',
...@@ -32,4 +30,4 @@ export const todos = [ ...@@ -32,4 +30,4 @@ export const todos = [
'unPreloadPage', 'unPreloadPage',
'loadSubPackage' 'loadSubPackage'
] ]
export const canIUses = [] export const canIUses = []
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import createCanvasContext from '../../../mp-weixin/helpers/create-canvas-context'
export const protocols = { export const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage
createCanvasContext
} }
export const todos = [ export const todos = [
'preloadPage', 'preloadPage',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册