Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
ac82a6b2
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac82a6b2
编写于
5月 19, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: onWindowResize、offWindowResize
上级
787956f8
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
301 addition
and
197 deletion
+301
-197
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+1
-0
packages/uni-api/src/protocols/ui/window.ts
packages/uni-api/src/protocols/ui/window.ts
+5
-0
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+235
-197
packages/uni-h5/src/service/api/index.ts
packages/uni-h5/src/service/api/index.ts
+1
-0
packages/uni-h5/src/service/api/ui/window.ts
packages/uni-h5/src/service/api/ui/window.ts
+59
-0
未找到文件。
packages/uni-api/src/index.ts
浏览文件 @
ac82a6b2
...
...
@@ -66,6 +66,7 @@ export * from './protocols/ui/showToast'
export
*
from
'
./protocols/ui/startPullDownRefresh
'
export
*
from
'
./protocols/ui/stopPullDownRefresh
'
export
*
from
'
./protocols/ui/tabBar
'
export
*
from
'
./protocols/ui/window
'
// helpers
export
{
defineOnApi
,
...
...
packages/uni-api/src/protocols/ui/window.ts
0 → 100644
浏览文件 @
ac82a6b2
export
const
API_ON_WINDOW_RESIZE
=
'
onWindowResize
'
export
type
API_TYPE_ON_WINDOW_RESIZE
=
typeof
uni
.
onWindowResize
export
const
API_OFF_WINDOW_RESIZE
=
'
offWindowResize
'
export
type
API_TYPE_OFF_WINDOW_RESIZE
=
typeof
uni
.
offWindowResize
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
ac82a6b2
...
...
@@ -266,7 +266,7 @@ function converType(type) {
}).replace("webkit", "-webkit");
}
function getStyle(action) {
const animateTypes1
2
= [
const animateTypes1 = [
"matrix",
"matrix3d",
"scale",
...
...
@@ -276,7 +276,7 @@ function getStyle(action) {
"translate",
"translate3d"
];
const animateTypes2
2
= [
const animateTypes2 = [
"scaleX",
"scaleY",
"scaleZ",
...
...
@@ -290,7 +290,7 @@ function getStyle(action) {
"translateY",
"translateZ"
];
const animateTypes3
2
= ["opacity", "background-color"];
const animateTypes3 = ["opacity", "background-color"];
const animateTypes4 = ["width", "height", "left", "right", "top", "bottom"];
const animates = action.animates;
const option = action.option;
...
...
@@ -300,17 +300,17 @@ function getStyle(action) {
animates.forEach((animate) => {
let type = animate.type;
let args = [...animate.args];
if (animateTypes1
2.concat(animateTypes2
2).includes(type)) {
if (animateTypes1
.concat(animateTypes
2).includes(type)) {
if (type.startsWith("rotate") || type.startsWith("skew")) {
args = args.map((value) => parseFloat(value) + "deg");
} else if (type.startsWith("translate")) {
args = args.map(converPx);
}
if (animateTypes2
2
.indexOf(type) >= 0) {
if (animateTypes2.indexOf(type) >= 0) {
args.length = 1;
}
transform.push(`${type}(${args.join(",")})`);
} else if (animateTypes3
2
.concat(animateTypes4).includes(args[0])) {
} else if (animateTypes3.concat(animateTypes4).includes(args[0])) {
type = args[0];
const value = args[1];
style[type] = animateTypes4.includes(type) ? converPx(value) : value;
...
...
@@ -9365,7 +9365,7 @@ var index$a = /* @__PURE__ */ defineBuiltInComponent({
el.style.height = height + "px";
}
});
function onResize({
function onResize
2
({
height
}) {
heightRef.value = height;
...
...
@@ -9440,7 +9440,7 @@ var index$a = /* @__PURE__ */ defineBuiltInComponent({
"class": "uni-textarea-compute"
}, [valueCompute.value.map((item) => createVNode("div", null, [item.trim() ? item : "."])), createVNode(ResizeSensor, {
"initial": true,
"onResize": onResize
"onResize": onResize
2
}, null, 8, ["initial", "onResize"])]), props2.confirmType === "search" ? createVNode("form", {
"action": "",
"onSubmit": () => false,
...
...
@@ -10106,7 +10106,11 @@ const CanvasPutImageDataProtocol = /* @__PURE__ */ extend({
type: Uint8ClampedArray,
required: true
}
}, CanvasGetImageDataProtocol);
}, CanvasGetImageDataProtocol, {
height: {
type: Number
}
});
const fileTypes = {
PNG: "png",
JPG: "jpg",
...
...
@@ -10718,7 +10722,8 @@ class CanvasContext {
});
}
}
[...methods1, ...methods2].forEach(function(method) {
const initCanvasContextProperty = /* @__PURE__ */ once(() => {
[...methods1, ...methods2].forEach(function(method) {
function get(method2) {
switch (method2) {
case "fill":
...
...
@@ -10807,8 +10812,8 @@ class CanvasContext {
}
}
CanvasContext.prototype[method] = get(method);
});
methods3.forEach(function(method) {
});
methods3.forEach(function(method) {
function get(method2) {
switch (method2) {
case "setFillStyle":
...
...
@@ -10875,8 +10880,10 @@ methods3.forEach(function(method) {
}
}
CanvasContext.prototype[method] = get(method);
});
});
const createCanvasContext = /* @__PURE__ */ defineSyncApi(API_CREATE_CANVAS_CONTEXT, (canvasId, componentInstance) => {
initCanvasContextProperty();
if (componentInstance) {
return new CanvasContext(canvasId, getPageIdByVm(componentInstance));
}
...
...
@@ -11266,7 +11273,8 @@ class MPAnimation {
return this;
}
}
const animateTypes1 = [
const initAnimationProperty = /* @__PURE__ */ once(() => {
const animateTypes1 = [
"matrix",
"matrix3d",
"rotate",
...
...
@@ -11287,24 +11295,25 @@ const animateTypes1 = [
"translateX",
"translateY",
"translateZ"
];
const animateTypes2 = ["opacity", "backgroundColor"];
const animateTypes3 = ["width", "height", "left", "right", "top", "bottom"];
animateTypes1.concat(animateTypes2, animateTypes3).forEach((type) => {
];
const animateTypes2 = ["opacity", "backgroundColor"];
const animateTypes3 = ["width", "height", "left", "right", "top", "bottom"];
animateTypes1.concat(animateTypes2, animateTypes3).forEach((type) => {
MPAnimation.prototype[type] = function(...args) {
let _this = this;
if (animateTypes2.concat(animateTypes3).includes(type)) {
_
this._pushAnimates("style", [
_
this._converType(type),
animateTypes3.includes(type) ? _
this._getValue(args[0]) : args[0]
this._pushAnimates("style", [
this._converType(type),
animateTypes3.includes(type) ?
this._getValue(args[0]) : args[0]
]);
} else {
_
this._pushAnimates(type, args);
this._pushAnimates(type, args);
}
return _
this;
return
this;
};
});
});
const createAnimation = /* @__PURE__ */ defineSyncApi(API_CREATE_ANIMATION, (option) => {
initAnimationProperty();
return new MPAnimation(option);
}, CreateAnimationProtocol, CreateAnimationOptions);
const API_ON_TAB_BAR_MID_BUTTON_TAP = "onTabBarMidButtonTap";
...
...
@@ -12175,6 +12184,8 @@ const SetTabBarBadgeOptions = {
}
}, IndexOptions.formatArgs)
};
const API_ON_WINDOW_RESIZE = "onWindowResize";
const API_OFF_WINDOW_RESIZE = "offWindowResize";
const initIntersectionObserverPolyfill = function() {
if (typeof window !== "object") {
return;
...
...
@@ -17632,6 +17643,31 @@ const removeTabBarBadge = /* @__PURE__ */ defineAsyncApi(API_REMOVE_TAB_BAR_BADG
const setTabBarBadge = /* @__PURE__ */ defineAsyncApi(API_SET_TAB_BAR_BADGE, (args, {resolve}) => {
setTabBar(API_SET_TAB_BAR_BADGE, args, resolve);
}, SetTabBarBadgeProtocol, SetTabBarBadgeOptions);
var tasks = [];
function onResize() {
tasks.push(setTimeout(() => {
tasks.forEach((task) => clearTimeout(task));
tasks.length = 0;
const {windowWidth, windowHeight, screenWidth, screenHeight} = uni.getSystemInfoSync();
var landscape = Math.abs(Number(window.orientation)) === 90;
var deviceOrientation = landscape ? "landscape" : "portrait";
UniServiceJSBridge.invokeOnCallback(API_ON_WINDOW_RESIZE, {
deviceOrientation,
size: {
windowWidth,
windowHeight,
screenWidth,
screenHeight
}
});
}, 20));
}
const onWindowResize = /* @__PURE__ */ defineOnApi(API_ON_WINDOW_RESIZE, () => {
window.addEventListener("resize", onResize);
});
const offWindowResize = /* @__PURE__ */ defineOffApi(API_OFF_WINDOW_RESIZE, () => {
window.removeEventListener("resize", onResize);
});
var api = /* @__PURE__ */ Object.freeze({
__proto__: null,
[Symbol.toStringTag]: "Module",
...
...
@@ -17736,7 +17772,9 @@ var api = /* @__PURE__ */ Object.freeze({
hideTabBarRedDot,
showTabBarRedDot,
removeTabBarBadge,
setTabBarBadge
setTabBarBadge,
onWindowResize,
offWindowResize
});
const CONTEXT_ID = "MAP_LOCATION";
const ICON_PATH = "data:image/png;base64,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";
...
...
@@ -20092,4 +20130,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export {$emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, _sfc_main$8 as Audio, index$n as Button, _sfc_main$7 as Canvas, index$k as Checkbox, index$m as CheckboxGroup, _sfc_main$2 as CoverImage, _sfc_main$3 as CoverView, index$j as Editor, index$o as Form, Friction, index$i as Icon, index$h as Image, Input, index$l as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, _sfc_main$6 as Navigator, index$2 as PageComponent, _sfc_main$1 as Picker, PickerView, PickerViewColumn, index$g as Progress, index$e as Radio, index$f as RadioGroup, ResizeSensor, _sfc_main$5 as RichText, _sfc_main$4 as ScrollView, Scroller, index$d as Slider, Spring, Swiper, SwiperItem, index$c as Switch, index$b as Text, index$a as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$5 as Video, index$9 as View, index$4 as WebView, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createMapContext, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, defineBuiltInComponent, defineSystemComponent, disableScrollBounce, downloadFile, getApp$1 as getApp, getContextInfo, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLocation, getNetworkType, getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getVideoInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, hideToast, initScrollBounce, loadFontFace, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, o
nAccelerometerChange, onCompassChange, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap
, openDocument, openLocation, pageScrollTo, index$6 as plugin, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeStorage, removeStorageSync, removeTabBarBadge, request, sendSocketMessage, setNavigationBarColor, setNavigationBarTitle, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showActionSheet, showLoading, showModal, showNavigationBarLoading, showTabBar, showTabBarRedDot, showToast, startAccelerometer, startCompass, startPullDownRefresh, stopAccelerometer, stopCompass, stopPullDownRefresh, switchTab, uni$1 as uni, uniFormKey, uploadFile, upx2px, useAttrs, useBooleanAttr, useContextInfo, useCustomEvent, useNativeEvent, useOn, useScroller, useSubscribe, useTouchtrack, useUserAction, vibrateLong, vibrateShort, withWebEvent};
export {$emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, _sfc_main$8 as Audio, index$n as Button, _sfc_main$7 as Canvas, index$k as Checkbox, index$m as CheckboxGroup, _sfc_main$2 as CoverImage, _sfc_main$3 as CoverView, index$j as Editor, index$o as Form, Friction, index$i as Icon, index$h as Image, Input, index$l as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, _sfc_main$6 as Navigator, index$2 as PageComponent, _sfc_main$1 as Picker, PickerView, PickerViewColumn, index$g as Progress, index$e as Radio, index$f as RadioGroup, ResizeSensor, _sfc_main$5 as RichText, _sfc_main$4 as ScrollView, Scroller, index$d as Slider, Spring, Swiper, SwiperItem, index$c as Switch, index$b as Text, index$a as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$5 as Video, index$9 as View, index$4 as WebView, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createMapContext, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, defineBuiltInComponent, defineSystemComponent, disableScrollBounce, downloadFile, getApp$1 as getApp, getContextInfo, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLocation, getNetworkType, getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getVideoInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, hideToast, initScrollBounce, loadFontFace, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, o
ffWindowResize, onAccelerometerChange, onCompassChange, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onWindowResize
, openDocument, openLocation, pageScrollTo, index$6 as plugin, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeStorage, removeStorageSync, removeTabBarBadge, request, sendSocketMessage, setNavigationBarColor, setNavigationBarTitle, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showActionSheet, showLoading, showModal, showNavigationBarLoading, showTabBar, showTabBarRedDot, showToast, startAccelerometer, startCompass, startPullDownRefresh, stopAccelerometer, stopCompass, stopPullDownRefresh, switchTab, uni$1 as uni, uniFormKey, uploadFile, upx2px, useAttrs, useBooleanAttr, useContextInfo, useCustomEvent, useNativeEvent, useOn, useScroller, useSubscribe, useTouchtrack, useUserAction, vibrateLong, vibrateShort, withWebEvent};
packages/uni-h5/src/service/api/index.ts
浏览文件 @
ac82a6b2
...
...
@@ -58,6 +58,7 @@ export * from './ui/pageScrollTo'
export
*
from
'
./ui/startPullDownRefresh
'
export
*
from
'
./ui/stopPullDownRefresh
'
export
*
from
'
./ui/tabBar
'
export
*
from
'
./ui/window
'
export
{
upx2px
,
...
...
packages/uni-h5/src/service/api/ui/window.ts
0 → 100644
浏览文件 @
ac82a6b2
import
{
API_ON_WINDOW_RESIZE
,
API_TYPE_ON_WINDOW_RESIZE
,
API_OFF_WINDOW_RESIZE
,
API_TYPE_OFF_WINDOW_RESIZE
,
defineOnApi
,
defineOffApi
,
}
from
'
@dcloudio/uni-api
'
var
tasks
:
number
[]
=
[]
function
onResize
()
{
tasks
.
push
(
setTimeout
(()
=>
{
tasks
.
forEach
((
task
)
=>
clearTimeout
(
task
))
tasks
.
length
=
0
const
{
windowWidth
,
windowHeight
,
screenWidth
,
screenHeight
}
=
uni
.
getSystemInfoSync
()
var
landscape
=
Math
.
abs
(
Number
(
window
.
orientation
))
===
90
var
deviceOrientation
=
landscape
?
'
landscape
'
:
'
portrait
'
UniServiceJSBridge
.
invokeOnCallback
<
API_TYPE_ON_WINDOW_RESIZE
>
(
API_ON_WINDOW_RESIZE
,
{
// @ts-ignore
deviceOrientation
,
size
:
{
windowWidth
,
windowHeight
,
screenWidth
,
screenHeight
,
},
}
)
},
20
)
)
}
/**
* 监听窗口大小变化
* @param {*} callbackId
*/
export
const
onWindowResize
=
defineOnApi
<
API_TYPE_ON_WINDOW_RESIZE
>
(
API_ON_WINDOW_RESIZE
,
()
=>
{
window
.
addEventListener
(
'
resize
'
,
onResize
)
}
)
/**
* 取消监听窗口大小变化
* @param {*} callbackId
*/
export
const
offWindowResize
=
defineOffApi
<
API_TYPE_OFF_WINDOW_RESIZE
>
(
API_OFF_WINDOW_RESIZE
,
()
=>
{
window
.
removeEventListener
(
'
resize
'
,
onResize
)
}
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录