vantui-edit
Version:
一套适用于Taro3及React的vantui组件库
54 lines (48 loc) • 1.5 kB
JavaScript
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { useEffect, useState } from 'react';
import { ScrollView } from '@tarojs/components';
import { jsx as _jsx } from "react/jsx-runtime";
export default function ScrollViewTimeout(props) {
var _useState = useState(''),
_useState2 = _slicedToArray(_useState, 2),
target = _useState2[0],
setTarget = _useState2[1];
var timeout = props.timeout,
optiosData = props.optiosData,
tabvalue = props.tabvalue,
value = props.value,
_props$scrollIntoView = props.scrollIntoView,
scrollIntoView = _props$scrollIntoView === void 0 ? true : _props$scrollIntoView;
useEffect(function () {
if (scrollIntoView && value) {
var index = getIndexByValue(optiosData, tabvalue);
var val = value[index];
if (val !== undefined) {
setTimeout(function () {
setTarget("vant-cascader-item".concat(val));
}, timeout);
} else {
setTarget('');
}
}
}, // eslint-disable-next-line react-hooks/exhaustive-deps
[tabvalue, value]);
return /*#__PURE__*/_jsx(ScrollView, {
scrollWithAnimation: false,
scrollY: true,
className: "van-cascader-tab",
scrollIntoView: target,
children: props.children
});
}
function getIndexByValue(arr, value) {
var res = 0;
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
if (item.paneKey === value) {
res = i;
break;
}
}
return res;
}