Skip to content

Commit fe39348

Browse files
authored
Merge branch 'master' into fix-rn-onAppHide
2 parents cd13b08 + 06b893d commit fe39348

5 files changed

Lines changed: 514 additions & 25 deletions

File tree

docs-vitepress/guide/platform/rn.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,37 @@ level 有效值:
11641164
| ----------------| --------------------------------------------------- |
11651165
| bindchange | 点击导致 checked 改变时会触发 change 事件,`event.detail = { value }` |
11661166

1167+
#### slider
1168+
滑动选择器。
1169+
1170+
属性
1171+
1172+
| 属性名 | 类型 | 默认值 | 说明 |
1173+
| ----------------------- | ------- | ------------- | ---------------------------------------------------------- |
1174+
| min | number | `0` | 最小值 |
1175+
| max | number | `100` | 最大值 |
1176+
| step | number | `1` | 步长,取值必须大于 0,并且可被(max - min)整除 |
1177+
| disabled | boolean | `false` | 是否禁用 |
1178+
| value | number | `0` | 当前取值 |
1179+
| color | color | `#e9e9e9` | 背景条的颜色(已废弃,请使用 backgroundColor) |
1180+
| selected-color | color | `#1aad19` | 已选择的颜色(已废弃,请使用 activeColor) |
1181+
| activeColor | color | `#1aad19` | 已选择的颜色 |
1182+
| backgroundColor | color | `#e9e9e9` | 背景条的颜色 |
1183+
| block-size | number | `28` | 滑块的大小,取值范围为 12 - 28 |
1184+
| block-color | color | `#ffffff` | 滑块的颜色 |
1185+
1186+
事件
1187+
1188+
| 事件名 | 说明 |
1189+
| ----------------| --------------------------------------------------- |
1190+
| bindchange | 完成一次拖动后触发的事件,`event.detail = {value}` |
1191+
| bindchanging | 拖动过程中触发的事件,`event.detail = {value}` |
1192+
1193+
注意事项
1194+
1195+
1. 不支持 `show-value` 属性,即不支持在滑块旁显示当前数值
1196+
2. 当设置了 `step` 时,最终值会按步长进行对齐
1197+
11671198
#### navigator
11681199
页面链接。
11691200

packages/webpack-plugin/lib/platform/template/wx/component-config/slider.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ module.exports = function ({ print }) {
88
el.isBuiltIn = true
99
return 'mpx-slider'
1010
},
11+
android (tag, { el }) {
12+
el.isBuiltIn = true
13+
return 'mpx-slider'
14+
},
15+
harmony (tag, { el }) {
16+
el.isBuiltIn = true
17+
return 'mpx-slider'
18+
},
19+
ios (tag, { el }) {
20+
el.isBuiltIn = true
21+
return 'mpx-slider'
22+
},
1123
props: [
1224
{
1325
test: /^color$/,

packages/webpack-plugin/lib/platform/template/wx/component-config/unsupported.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher',
1111
// 快应用不支持的标签集合
1212
const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image']
1313
// RN不支持的标签集合
14-
const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'slider', 'audio', 'camera', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
14+
const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'audio', 'camera', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
1515

1616
/**
1717
* @param {function(object): function} print

packages/webpack-plugin/lib/runtime/components/react/mpx-progress.tsx

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Animated, {
3535

3636
import useInnerProps from './getInnerListeners'
3737
import useNodesRef, { HandlerRef } from './useNodesRef'
38-
import { useLayout, useTransformStyle, extendObject } from './utils'
38+
import { useLayout, useTransformStyle, extendObject, useRunOnJSCallback } from './utils'
3939
import Portal from './mpx-portal'
4040

4141
export interface ProgressProps {
@@ -70,7 +70,6 @@ const Progress = forwardRef<
7070
active = false,
7171
'active-mode': activeMode = 'backwards',
7272
duration = 30,
73-
bindactiveend,
7473
style = {},
7574
'enable-var': enableVar,
7675
'external-var-context': externalVarContext,
@@ -80,7 +79,7 @@ const Progress = forwardRef<
8079
} = props
8180

8281
const nodeRef = useRef(null)
83-
const propsRef = useRef({})
82+
const propsRef = useRef(props)
8483
propsRef.current = props
8584

8685
// 进度值状态
@@ -113,6 +112,22 @@ const Progress = forwardRef<
113112
style: normalStyle
114113
})
115114

115+
// 使用 useRunOnJSCallback 处理动画回调
116+
const runOnJSCallbackRef = useRef({
117+
triggerActiveEnd: (percent: number) => {
118+
const currentProps = propsRef.current
119+
if (currentProps.bindactiveend) {
120+
currentProps.bindactiveend({
121+
type: 'activeend',
122+
detail: {
123+
percent: percent
124+
}
125+
})
126+
}
127+
}
128+
})
129+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
130+
116131
// 进度条动画函数
117132
const startProgressAnimation = (targetPercent: number, startPercent: number, animationDuration: number, onFinished?: () => void) => {
118133
// 根据 active-mode 设置起始位置
@@ -125,25 +140,13 @@ const Progress = forwardRef<
125140
},
126141
(finished) => {
127142
if (finished && onFinished) {
128-
// 在动画回调中,需要使用runOnJS回到主线程
129-
runOnJS(onFinished)()
143+
// 在动画回调中,执行传入的worklet函数
144+
onFinished()
130145
}
131146
}
132147
)
133148
}
134149

135-
// 创建在主线程执行的事件回调函数
136-
const triggerActiveEnd = (percent: number) => {
137-
if (bindactiveend) {
138-
bindactiveend({
139-
type: 'activeend',
140-
detail: {
141-
percent: percent
142-
}
143-
})
144-
}
145-
}
146-
147150
// 进度变化时的动画效果
148151
useEffect(() => {
149152
const targetPercent = Math.max(0, Math.min(100, percent))
@@ -161,19 +164,18 @@ const Progress = forwardRef<
161164
const percentDiff = Math.abs(targetPercent - startPercent)
162165
const animationDuration = percentDiff * duration
163166

164-
// 创建动画完成回调
165-
const onAnimationFinished = () => {
166-
triggerActiveEnd(targetPercent)
167-
}
168-
169167
// 执行动画
170-
startProgressAnimation(targetPercent, startPercent, animationDuration, onAnimationFinished)
168+
startProgressAnimation(targetPercent, startPercent, animationDuration, () => {
169+
'worklet'
170+
// 在worklet函数内部执行runOnJS调用runOnJSCallback
171+
runOnJS(runOnJSCallback)('triggerActiveEnd', targetPercent)
172+
})
171173
} else {
172174
progressWidth.value = targetPercent
173175
}
174176

175177
setLastPercent(targetPercent)
176-
}, [percent, active, activeMode, duration, bindactiveend])
178+
}, [percent, active, activeMode, duration])
177179

178180
// 初始化时设置进度值
179181
useEffect(() => {

0 commit comments

Comments
 (0)