Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4144729

Browse files
committedJul 11, 2022
fix Preview component working wrong
1 parent 9f2c9eb commit 4144729

File tree

11 files changed

+55
-29
lines changed

11 files changed

+55
-29
lines changed
 

‎packages/nextjs/components/src/preview/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {useState} from 'react'
22
import Mask from '../mask'
3-
import {Swiper, SwiperItem} from '../swiper'
3+
import Swiper from '../swiper'
4+
import SwiperItem from '../swiper-item'
45

56
interface PreviewProps {
67
/**

‎packages/nextjs/components/src/swiper-item/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface SwiperItemProps extends TaroBaseProps {
1515
children?: React.ReactNode
1616
}
1717

18-
const SwiperItem = ({className, itemId, children, ...rest}) => {
18+
const SwiperItem: React.FC<SwiperItemProps> = ({className, itemId, children, ...rest}) => {
1919
const props = useTaroBaseEvents(rest)
2020

2121
return (

‎packages/nextjs/taro/src/basics/system.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ const getSystemInfoSyncInternal = () => {
144144
const deviceInfo = getDeviceInfo()
145145
const appBaseInfo = getAppBaseInfoInternal()
146146
const appAuthorizeSetting = getAppAuthorizeSetting()
147-
delete deviceInfo.abi
148147

149148
return {
150149
...windowInfo,

‎packages/nextjs/taro/src/canvas/canvasGetImageData.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ const canvasGetImageDataInternal: typeof swan.canvasGetImageData = ({
2929
return
3030
}
3131

32+
const ctx = canvas.getContext('2d')
33+
if (!ctx) {
34+
fail?.({
35+
errMsg: 'Your browser does not support canvas api.'
36+
})
37+
complete?.()
38+
return
39+
}
40+
3241
try {
33-
const ctx = canvas.getContext('2d')
3442
const imageData = ctx.getImageData(x, y, width, height)
3543
success?.({
3644
width,

‎packages/nextjs/taro/src/canvas/canvasPutImageData.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ const canvasPutImageDataInternal: typeof swan.canvasPutImageData = ({
3030
return
3131
}
3232

33+
const ctx = canvas.getContext('2d')
34+
if (!ctx) {
35+
fail?.({
36+
errMsg: 'Your browser does not support canvas api.'
37+
})
38+
complete?.()
39+
return
40+
}
41+
3342
try {
34-
const ctx = canvas.getContext('2d')
3543
const imageData = new ImageData(data, width, height)
3644
ctx.putImageData(imageData, x, y)
3745
success?.()

‎packages/nextjs/taro/src/canvas/createCanvasContext.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { CanvasContext } from './CanvasContext'
55
* 创建 canvas 的绘图上下文 CanvasContext 对象
66
*/
77
export const createCanvasContext = (canvasId, inst) => {
8-
const el = findDOM(inst) as HTMLElement
9-
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
10-
const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D
11-
const context = new CanvasContext(canvas, ctx)
12-
if (!ctx) return context
13-
context.canvas = canvas
14-
context.ctx = ctx
8+
const el = findDOM(inst) as HTMLElement
9+
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
10+
const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D
11+
const context = new CanvasContext(canvas, ctx)
12+
if (!ctx) return context
13+
context.canvas = canvas
14+
context.ctx = ctx
1515

16-
return context
16+
return context
1717
}

‎packages/nextjs/taro/src/dataCache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ const getStorageInfoSyncInternal: typeof swan.getStorageInfoSync = () => {
110110
for (const key in localStorage){
111111
keys.push(key)
112112
const value = localStorage.getItem(key)
113-
currentSize += key.length + value.length
113+
if (value != null) {
114+
currentSize += key.length + value.length
115+
}
114116
}
115117
return {
116118
keys,

‎packages/nextjs/taro/src/media/image.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ function previewImageInternal({
117117
}
118118

119119
if (!urls) {
120-
fail({
120+
fail?.({
121121
errMsg: 'The urls param is required.'
122122
})
123-
complete()
123+
complete?.()
124124
return
125125
}
126126

@@ -131,13 +131,13 @@ function previewImageInternal({
131131
defaultCurrent={current}
132132
urls={urls}
133133
onClose={() => {
134-
ReactDOM.unmountComponentAtNode(previewContainer)
134+
ReactDOM.unmountComponentAtNode(previewContainer!)
135135
previewContainer = null
136136
}}
137137
/>,
138138
previewContainer
139139
)
140-
success({})
140+
success?.({})
141141
}
142142

143143
/**

‎packages/nextjs/taro/src/network/upload.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export const uploadFile: typeof swan.uploadFile = ({
6868

6969
xhr.onload = () => {
7070
const status = xhr.status
71-
clearTimeout(timeoutTimer)
71+
if (timeoutTimer) {
72+
clearTimeout(timeoutTimer)
73+
}
7274
success?.({
7375
statusCode: status,
7476
data: xhr.responseText || xhr.response
@@ -77,15 +79,19 @@ export const uploadFile: typeof swan.uploadFile = ({
7779
}
7880

7981
xhr.onabort = () => {
80-
clearTimeout(timeoutTimer)
82+
if (timeoutTimer) {
83+
clearTimeout(timeoutTimer)
84+
}
8185
fail?.({
8286
errMsg: 'uploadFile:fail abort'
8387
})
8488
complete?.()
8589
}
8690

8791
xhr.onerror = (e: ProgressEvent<EventTarget> & { message?: string }) => {
88-
clearTimeout(timeoutTimer)
92+
if (timeoutTimer) {
93+
clearTimeout(timeoutTimer)
94+
}
8995
fail?.({
9096
errMsg: `uploadFile:fail ${e.message}`
9197
})
@@ -96,7 +102,9 @@ export const uploadFile: typeof swan.uploadFile = ({
96102
* 中断任务
97103
*/
98104
const abort = () => {
99-
clearTimeout(timeoutTimer)
105+
if (timeoutTimer) {
106+
clearTimeout(timeoutTimer)
107+
}
100108
xhr.abort()
101109
}
102110

‎packages/nextjs/taro/src/ui/background.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import promisify from 'mpromisify'
22
import {unsupported, limited} from '../_util'
33
import * as swan from '../swan'
44

5-
const setBackgroundColorInternal: typeof swan.setBackgroundColor = ({backgroundColor, success, complete}) => {
5+
const setBackgroundColorInternal: typeof swan.setBackgroundColor = ({backgroundColor = '', success, complete}) => {
66
document.documentElement.style.backgroundColor = backgroundColor
77
success?.()
88
complete?.()

‎packages/nextjs/taro/src/ui/interactive.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Portals<T> {
3434

3535
component?: React.ComponentType<T>
3636

37-
container?: HTMLDivElement
37+
container: HTMLDivElement
3838

3939
timer?: ReturnType<typeof setTimeout>
4040

@@ -102,7 +102,7 @@ export const registerToastComponent = toastComponent => {
102102

103103
const showToastInternal: typeof swan.showToast = ({title, icon, duration = 1500, success, fail, complete}) => {
104104
try {
105-
globalToast.new(
105+
globalToast?.new(
106106
{
107107
icon: icon === 'none' ? undefined : icon,
108108
children: title,
@@ -127,7 +127,7 @@ const showToastInternal: typeof swan.showToast = ({title, icon, duration = 1500,
127127
export const showToast = promisify(limited.async('showToast', showToastInternal))
128128

129129
const hideToastInternal: typeof swan.hideToast = ({success, complete}) => {
130-
globalToast.destroy(() => {
130+
globalToast?.destroy(() => {
131131
success?.()
132132
complete?.()
133133
})
@@ -139,7 +139,7 @@ const hideToastInternal: typeof swan.hideToast = ({success, complete}) => {
139139
export const hideToast = promisify(limited.async('hideToast', hideToastInternal))
140140

141141
const showLoadingInternal: typeof swan.showLoading = ({title = '正在加载...', success, complete}) => {
142-
globalToast.new(
142+
globalToast?.new(
143143
{
144144
icon: 'loading',
145145
children: title
@@ -157,7 +157,7 @@ const showLoadingInternal: typeof swan.showLoading = ({title = '正在加载...'
157157
export const showLoading = promisify(limited.async('showLoading', showLoadingInternal))
158158

159159
const hideLoadingInternal: typeof swan.hideLoading = ({success, complete}) => {
160-
globalToast.destroy(() => {
160+
globalToast?.destroy(() => {
161161
success?.()
162162
complete?.()
163163
})
@@ -246,7 +246,7 @@ const showModalInternal: typeof swan.showModal = ({
246246
success,
247247
complete
248248
}) => {
249-
globalModal.new({
249+
globalModal?.new({
250250
title,
251251
children: content,
252252
showCancel,

0 commit comments

Comments
 (0)
Please sign in to comment.