Skip to content

Commit 8ce8c51

Browse files
authored
Feat v3 cpp td (#3364)
* feat: 鸿蒙适配td * chore: 强制指向某些版本 * fix: swipe 在鸿蒙下不好使的问题 * fix(toast): 无法在鸿蒙下换行的问题 * fix: 调整滑动时动效时间 * fix: 去掉注释 * chore: 升级nutui版本 * chore: 升级版本号 * fix: lint
1 parent 88462db commit 8ce8c51

File tree

11 files changed

+7985
-7215
lines changed

11 files changed

+7985
-7215
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nutui/nutui-react-taro",
3-
"version": "3.0.19-cpp-beta.3",
3+
"version": "3.0.19-cpp.1",
44
"style": "dist/style.css",
55
"main": "dist/nutui.react.umd.js",
66
"module": "dist/es/packages/nutui.react.build.js",
@@ -109,7 +109,7 @@
109109
"dependencies": {
110110
"@babel/runtime": "^7.23.9",
111111
"@nutui/icons-react": "^3.0.2-beta.5",
112-
"@nutui/icons-react-taro": "^3.0.2-beta.3",
112+
"@nutui/icons-react-taro": "^3.0.2-cpp.1",
113113
"@nutui/jdesign-icons-react-taro": "1.0.6-beta.2",
114114
"@nutui/touch-emulator": "^1.0.0",
115115
"@nutui/lottie-miniprogram": "^1.0.2",
@@ -241,6 +241,7 @@
241241
"@types/react-dom": "^18.2.19",
242242
"sass": "1.77.6",
243243
"@tarojs/api": "4.0.12",
244-
"@tarojs/components": "4.0.12"
244+
"@tarojs/components": "4.0.12",
245+
"@nutui/icons-react-taro": "^3.0.2-cpp.1"
245246
}
246247
}

pnpm-lock.yaml

Lines changed: 7870 additions & 7127 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks/taro/use-custom-event.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useEffect, useRef } from 'react'
22
import isEqual from 'react-fast-compare'
3-
import { Events, getCurrentInstance } from '@tarojs/taro'
3+
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
44
import { useForceUpdate } from '@/hooks/use-force-update'
55

6-
export const customEvents = new Events()
6+
// export const customEvents = new Events()
7+
export const customEvents = eventCenter
78

89
export function useCustomEventsPath(selector?: string) {
910
selector = selector || ''

src/packages/button/button.taro.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import React, { CSSProperties, useCallback, useMemo } from 'react'
22
import type { MouseEvent } from 'react'
33
import classNames from 'classnames'
44
import {
5-
ButtonProps as MiniProgramButtonProps,
5+
// ButtonProps as MiniProgramButtonProps,
66
View,
7-
Button as TaroButton,
7+
// Button as TaroButton,
88
} from '@tarojs/components'
99
import { Loading } from '@nutui/icons-react-taro'
10-
import { getEnv } from '@tarojs/taro'
1110
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
1211
import { harmony } from '@/utils/taro/platform'
1312

14-
type OmitMiniProgramButtonProps = Omit<
15-
MiniProgramButtonProps,
16-
'size' | 'type' | 'onClick' | 'style'
17-
>
13+
// type OmitMiniProgramButtonProps = Omit<
14+
// MiniProgramButtonProps,
15+
// 'size' | 'type' | 'onClick' | 'style'
16+
// >
1817

1918
export type ButtonType =
2019
| 'default'
@@ -27,9 +26,11 @@ export type ButtonSize = 'xlarge' | 'large' | 'normal' | 'small' | 'mini'
2726
export type ButtonShape = 'square' | 'round'
2827
export type ButtonFill = 'solid' | 'outline' | 'dashed' | 'none'
2928

30-
export interface ButtonProps
31-
extends BasicComponent,
32-
OmitMiniProgramButtonProps {
29+
// export interface ButtonProps
30+
// extends BasicComponent,
31+
// OmitMiniProgramButtonProps {
32+
33+
export interface ButtonProps extends BasicComponent {
3334
color: string
3435
shape: ButtonShape
3536
type: ButtonType
@@ -76,7 +77,7 @@ export const Button = React.forwardRef<HTMLButtonElement, Partial<ButtonProps>>(
7677
children,
7778
className,
7879
style,
79-
formType,
80+
// formType,
8081
nativeType,
8182
onClick,
8283
...rest
@@ -145,17 +146,18 @@ export const Button = React.forwardRef<HTMLButtonElement, Partial<ButtonProps>>(
145146
className
146147
)
147148

148-
if (getEnv() === 'WEB') {
149-
;(rest as any).type = formType
150-
}
149+
// if (getEnv() === 'WEB') {
150+
// ;(rest as any).type = formType
151+
// }
151152
return (
152153
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
153154
// @ts-ignore
154155
// eslint-disable-next-line react/button-has-type
155-
<TaroButton
156+
// <TaroButton
157+
<View
156158
{...rest}
157159
ref={ref}
158-
formType={formType || nativeType}
160+
// formType={formType || nativeType}
159161
className={buttonClassNames}
160162
style={{ ...getStyle, ...style }}
161163
onClick={(e) => handleClick(e as any)}
@@ -175,7 +177,8 @@ export const Button = React.forwardRef<HTMLButtonElement, Partial<ButtonProps>>(
175177
)}
176178
{rightIcon}
177179
</View>
178-
</TaroButton>
180+
</View>
181+
// </TaroButton>
179182
)
180183
}
181184
)

src/packages/input/input.taro.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@ import React, {
77
} from 'react'
88
import { Input as TaroInput, View } from '@tarojs/components'
99
import { MaskClose } from '@nutui/icons-react-taro'
10-
import Taro, { ENV_TYPE, getEnv } from '@tarojs/taro'
10+
import Taro, { getEnv } from '@tarojs/taro'
1111
import { BaseEventOrig } from '@tarojs/components/types/common'
1212
import { formatNumber } from './utils'
1313
import { useConfig, useRtl } from '@/packages/configprovider/index.taro'
1414
import { ComponentDefaults } from '@/utils/typings'
1515
import { usePropsValue } from '@/hooks/use-props-value'
1616
import { InputFormatTrigger, TaroInputProps } from '@/types'
1717

18+
const ENV_TYPE = {
19+
WEAPP: 'WEAPP',
20+
SWAN: 'SWAN',
21+
ALIPAY: 'ALIPAY',
22+
TT: 'TT',
23+
QQ: 'QQ',
24+
JD: 'JD',
25+
WEB: 'WEB',
26+
RN: 'RN',
27+
HARMONY: 'HARMONY',
28+
QUICKAPP: 'QUICKAPP',
29+
}
30+
1831
const defaultProps = {
1932
...ComponentDefaults,
2033
type: 'text',

src/packages/steps/steps.taro.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export const Steps: FunctionComponent<
3939
classPrefix,
4040
{
4141
[`${classPrefix}-${direction}`]: true,
42-
[`${classPrefix}-${direction}-count-${React.Children.count(children)}`]:
43-
true,
42+
[`${classPrefix}-${direction}-count-${React.Children.count(children)}`]: true,
4443
[`${classPrefix}-${direction}-${layout}`]: true,
4544
[`${classPrefix}-${direction}-${type}`]: true,
4645
[`${classPrefix}-${direction}-${status}`]: true,

src/packages/steps/steps.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export const Steps: FunctionComponent<
3939
classPrefix,
4040
{
4141
[`${classPrefix}-${direction}`]: true,
42-
[`${classPrefix}-${direction}-count-${React.Children.count(children)}`]:
43-
true,
42+
[`${classPrefix}-${direction}-count-${React.Children.count(children)}`]: true,
4443
[`${classPrefix}-${direction}-${layout}`]: true,
4544
[`${classPrefix}-${direction}-${type}`]: true,
4645
[`${classPrefix}-${direction}-${status}`]: true,

src/packages/swipe/swipe.taro.tsx

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, {
22
forwardRef,
33
MouseEvent,
4+
useCallback,
45
useEffect,
56
useImperativeHandle,
7+
useMemo,
68
useRef,
79
useState,
810
} from 'react'
@@ -13,7 +15,6 @@ import { nextTick, useReady } from '@tarojs/taro'
1315
import { useTouch } from '@/hooks/use-touch'
1416
import { getRectInMultiPlatform } from '@/utils/taro/get-rect'
1517
import { ComponentDefaults } from '@/utils/typings'
16-
import { harmony } from '@/utils/taro/platform'
1718
import { useRefState } from '@/hooks/use-ref-state'
1819
import { useUuid } from '@/hooks/use-uuid'
1920
import { PositionX, SwipeRef, TaroSwipeProps } from '@/types'
@@ -45,25 +46,23 @@ export const Swipe = forwardRef<
4546
const leftId = `swipe-left-${uid}`
4647
const rightId = `swipe-right-${uid}`
4748

49+
const getWidth = async () => {
50+
if (leftWrapper.current) {
51+
const leftRect = await getRectInMultiPlatform(leftWrapper.current, leftId)
52+
leftRect && setActionWidth((v: any) => ({ ...v, left: leftRect.width }))
53+
}
54+
if (rightWrapper.current) {
55+
const rightRect = await getRectInMultiPlatform(
56+
rightWrapper.current,
57+
rightId
58+
)
59+
rightRect &&
60+
setActionWidth((v: any) => ({ ...v, right: rightRect.width }))
61+
}
62+
}
63+
4864
// 获取元素的时候要在页面 onReady 后,需要参考小程序的事件周期
4965
useReady(() => {
50-
const getWidth = async () => {
51-
if (leftWrapper.current) {
52-
const leftRect = await getRectInMultiPlatform(
53-
leftWrapper.current,
54-
leftId
55-
)
56-
leftRect && setActionWidth((v: any) => ({ ...v, left: leftRect.width }))
57-
}
58-
if (rightWrapper.current) {
59-
const rightRect = await getRectInMultiPlatform(
60-
rightWrapper.current,
61-
rightId
62-
)
63-
rightRect &&
64-
setActionWidth((v: any) => ({ ...v, right: rightRect.width }))
65-
}
66-
}
6766
nextTick(() => getWidth())
6867
})
6968

@@ -78,7 +77,6 @@ export const Swipe = forwardRef<
7877
offset: 0,
7978
dragging: false,
8079
})
81-
8280
const [actionWidth, updateState] = useRefState({
8381
left: 0,
8482
right: 0,
@@ -98,57 +96,48 @@ export const Swipe = forwardRef<
9896
})
9997
}
10098
}
101-
const wrapperStyle = {
102-
transform: `translate(${state.offset}${!harmony() ? 'px' : ''}, 0)`,
103-
transitionDuration: state.dragging ? '0s' : '.6s',
104-
}
105-
const onTouchStart = async (event: BaseEventOrig<HTMLDivElement>) => {
106-
if (leftWrapper.current) {
107-
const leftRect = await getRectInMultiPlatform(leftWrapper.current, leftId)
108-
leftRect && setActionWidth((v: any) => ({ ...v, left: leftRect.width }))
109-
}
110-
if (rightWrapper.current) {
111-
const rightRect = await getRectInMultiPlatform(
112-
rightWrapper.current,
113-
rightId
114-
)
115-
rightRect &&
116-
setActionWidth((v: any) => ({ ...v, right: rightRect.width }))
99+
const wrapperStyle = useMemo(() => {
100+
return {
101+
transform: `translate(${state.offset}px, 0)`,
102+
transitionDuration: state.dragging ? '0.01s' : '.6s',
117103
}
104+
}, [state.offset, state.dragging])
105+
106+
const onTouchStart = async (event: BaseEventOrig<HTMLDivElement>) => {
118107
if (!props.disabled) {
108+
getWidth()
119109
startOffset.current = state.offset
120110
touch.start(event)
121111
props.onTouchStart?.(event)
122112
}
123113
}
124114

125115
const onTouchMove = (event: BaseEventOrig<HTMLDivElement>) => {
126-
if (props.disabled) {
127-
return
128-
}
129-
116+
if (props.disabled) return
130117
touch.move(event)
131118
props.onTouchMove?.(event)
132119
if (touch.isHorizontal()) {
133120
lockClick.current = true
134-
const newState = { ...state, dragging: true }
135121
const isEdge = !opened || touch.deltaX.current * startOffset.current < 0
136122
if (isEdge) {
137123
preventDefault(event, true)
138124
}
139-
140-
newState.offset = rangeCalculation(
125+
const offset = rangeCalculation(
141126
touch.deltaX.current + startOffset.current,
142127
-actionWidth.current.right || 0,
143128
actionWidth.current.left || 0
144129
)
145-
setState(newState)
130+
setState((prevState) => ({
131+
...prevState,
132+
dragging: true,
133+
offset: Number(offset) || 0,
134+
}))
146135
}
147136
}
148137

149138
const onTouchEnd = (event: BaseEventOrig<HTMLDivElement>) => {
150139
if (state.dragging) {
151-
setState((v) => ({ ...v, dragging: false }))
140+
setState((prevState) => ({ ...prevState, dragging: false }))
152141
toggle(state.offset > 0 ? 'left' : 'right')
153142
setTimeout(() => {
154143
lockClick.current = false
@@ -175,20 +164,30 @@ export const Swipe = forwardRef<
175164
side === 'left' ? actionWidth.current.left : -actionWidth.current.right
176165
const name = props.name as number | string
177166
props.onOpen?.({ name, position: side })
178-
setState((v) => ({ ...v, offset: Number(offset) || 0 }))
179-
}
180167

181-
const close = (position?: PositionX) => {
182-
if (opened.current) {
183-
opened.current = false
184-
props.onClose?.({
185-
name: props.name as number | string,
186-
position: position || 'left',
187-
})
188-
}
189-
setState((v) => ({ ...v, offset: 0 }))
168+
setState((prevState) => ({
169+
...prevState,
170+
offset: Number(offset) || 0,
171+
}))
190172
}
191173

174+
const close = useCallback(
175+
(position?: PositionX) => {
176+
if (opened.current) {
177+
opened.current = false
178+
props.onClose?.({
179+
name: props.name as number | string,
180+
position: position || 'left',
181+
})
182+
}
183+
setState((prevState) => ({
184+
...prevState,
185+
offset: 0,
186+
}))
187+
},
188+
[props]
189+
)
190+
192191
const rangeCalculation = (
193192
num: number | string,
194193
min: number | string,
@@ -232,8 +231,7 @@ export const Swipe = forwardRef<
232231
}))
233232

234233
useEffect(() => {
235-
if (harmony()) return
236-
234+
// 并没有生效
237235
const handler: any = (event: { target: Node | null }) => {
238236
const targets = [root]
239237
if (
@@ -248,11 +246,10 @@ export const Swipe = forwardRef<
248246
}
249247

250248
document.addEventListener('touchstart', handler)
251-
252249
return () => {
253250
document.removeEventListener('touchstart', handler)
254251
}
255-
}, [])
252+
}, [close])
256253

257254
return (
258255
<View

src/packages/toast/toast.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
color: #ffffff;
9797
text-align: $toast-inner-text-align;
9898
line-height: 20px;
99+
height: auto;
99100
}
100101

101102
&-title {

src/packages/toast/toast.taro.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const Toast: FunctionComponent<
182182
{renderIcon()}
183183
{title && <Text className={`${classPrefix}-title`}>{title}</Text>}
184184
{content && (
185-
<Text className={`${classPrefix}-text`}>{content}</Text>
185+
<View className={`${classPrefix}-text`}>{content}</View>
186186
)}
187187
</View>
188188
</View>

0 commit comments

Comments
 (0)