@tarojs/components-react 4.1.12-beta.4 → 4.1.12-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/image/index.js +5 -3
- package/dist/components/image/index.js.map +1 -1
- package/dist/components/map/MapContext.js +628 -0
- package/dist/components/map/MapContext.js.map +1 -0
- package/dist/components/map/MapCustomCallout.js +91 -0
- package/dist/components/map/MapCustomCallout.js.map +1 -0
- package/dist/components/map/common.js +4 -0
- package/dist/components/map/common.js.map +1 -0
- package/dist/components/map/createMapContext.js +34 -0
- package/dist/components/map/createMapContext.js.map +1 -0
- package/dist/components/map/handler.js +50 -0
- package/dist/components/map/handler.js.map +1 -0
- package/dist/components/map/index.js +327 -0
- package/dist/components/map/index.js.map +1 -0
- package/dist/components/picker/picker-group.js +130 -70
- package/dist/components/picker/picker-group.js.map +1 -1
- package/dist/components/scroll-view/index.js +51 -23
- package/dist/components/scroll-view/index.js.map +1 -1
- package/dist/components/switch/index.js +125 -0
- package/dist/components/switch/index.js.map +1 -0
- package/dist/components/switch/style/index.scss.js +4 -0
- package/dist/components/switch/style/index.scss.js.map +1 -0
- package/dist/contexts/ScrollElementContext.js +6 -0
- package/dist/contexts/ScrollElementContext.js.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/original/components/image/index.js +5 -3
- package/dist/original/components/image/index.js.map +1 -1
- package/dist/original/components/image/style/index.scss +5 -1
- package/dist/original/components/map/MapContext.js +628 -0
- package/dist/original/components/map/MapContext.js.map +1 -0
- package/dist/original/components/map/MapCustomCallout.js +91 -0
- package/dist/original/components/map/MapCustomCallout.js.map +1 -0
- package/dist/original/components/map/common.js +4 -0
- package/dist/original/components/map/common.js.map +1 -0
- package/dist/original/components/map/createMapContext.js +34 -0
- package/dist/original/components/map/createMapContext.js.map +1 -0
- package/dist/original/components/map/handler.js +50 -0
- package/dist/original/components/map/handler.js.map +1 -0
- package/dist/original/components/map/index.js +327 -0
- package/dist/original/components/map/index.js.map +1 -0
- package/dist/original/components/picker/picker-group.js +130 -70
- package/dist/original/components/picker/picker-group.js.map +1 -1
- package/dist/original/components/scroll-view/index.js +51 -23
- package/dist/original/components/scroll-view/index.js.map +1 -1
- package/dist/original/components/switch/index.js +125 -0
- package/dist/original/components/switch/index.js.map +1 -0
- package/dist/original/components/switch/style/index.scss +35 -0
- package/dist/original/contexts/ScrollElementContext.js +6 -0
- package/dist/original/contexts/ScrollElementContext.js.map +1 -0
- package/dist/original/index.js +5 -1
- package/dist/original/index.js.map +1 -1
- package/dist/solid/components/image/index.js +5 -3
- package/dist/solid/components/image/index.js.map +1 -1
- package/dist/solid/components/picker/picker-group.js +130 -70
- package/dist/solid/components/picker/picker-group.js.map +1 -1
- package/dist/solid/components/scroll-view/index.js +55 -27
- package/dist/solid/components/scroll-view/index.js.map +1 -1
- package/dist/solid/contexts/ScrollElementContext.js +6 -0
- package/dist/solid/contexts/ScrollElementContext.js.map +1 -0
- package/dist/solid/index.css +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/map/index.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport React, { Children, useEffect, useState } from 'react'\nimport { MultiMarker, MultiPolyline, TMap } from 'tlbs-map-react'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { logPrefix } from './common'\nimport { registerMapInstance, unregisterMapInstance } from './MapContext'\nimport MapCustomCallout from './MapCustomCallout'\n\nimport type { MapProps as TaroMapProps } from '@tarojs/components'\nimport type MapTypes from 'tmap-gl-types'\n\nexport interface MapProps extends Omit<TaroMapProps, 'onError'> {\n forwardedRef?: React.MutableRefObject<any>\n authKey?: string\n onError?: (e: any) => void\n}\n\nfunction Map (props: MapProps) {\n const {\n forwardedRef,\n id,\n className,\n style,\n authKey,\n longitude,\n latitude,\n scale,\n minScale,\n maxScale,\n enableRotate,\n rotate,\n skew,\n markers,\n polyline,\n onTap,\n onAuthSuccess,\n onError,\n } = props\n // eslint-disable-next-line no-console\n console.log(logPrefix, 'props', props)\n\n /** ************************处理 style********************** */\n const styleObj = typeof style === 'string' || style === undefined ? {} : (style as Record<string, string>)\n\n /** ************************处理 marker********************** */\n const normalizedMarkers = markers ?? []\n const markerStyles: Record<string, any> = {}\n const markerGeometries: any[] = []\n\n normalizedMarkers.forEach((m, index) => {\n const markerId = String(m.id ?? index)\n const styleId = `marker-${markerId}`\n\n // Taro: iconPath (string);tlbs-map-react: styles 中指定图标\n // Taro: width, height (number|string);tlbs-map-react: width, height\n // Taro: rotate (number);tlbs-map-react: rotation\n // Taro: alpha (number 0-1);tlbs-map-react: opacity (0-1)\n // Taro: zIndex (number);tlbs-map-react: zIndex\n\n // 解析宽高,支持数字和字符串(如 '20px')\n const parseSize = (size: number | string | undefined): number => {\n if (typeof size === 'number') return size\n if (typeof size === 'string') {\n const parsed = parseInt(size, 10)\n return isNaN(parsed) ? 20 : parsed\n }\n return 20 // 默认宽度\n }\n\n const markerWidth = parseSize(m.width)\n const markerHeight = parseSize(m.height)\n\n // 宽高为 0 时跳过渲染(隐藏 marker,仅保留气泡)\n if (markerWidth === 0 || markerHeight === 0) {\n return\n }\n\n markerStyles[styleId] = {\n width: markerWidth,\n height: markerHeight,\n anchor: { x: markerWidth / 2, y: markerHeight }, // 默认底部中心为锚点\n ...(m.iconPath && { src: m.iconPath }),\n ...(typeof m.rotate === 'number' && { rotation: m.rotate }),\n ...(typeof m.alpha === 'number' && { opacity: m.alpha }),\n ...(typeof m.zIndex === 'number' && { zIndex: m.zIndex }),\n }\n\n markerGeometries.push({\n id: markerId,\n styleId,\n position: { lat: m.latitude, lng: m.longitude },\n })\n })\n\n /** ************************处理 polyline********************** */\n const normalizedPolylines = polyline ?? []\n const polylineStyles: Record<string, any> = {}\n const polylineGeometries: any[] = []\n\n normalizedPolylines.forEach((line, lineIndex) => {\n if (!line.points || line.points.length === 0) return\n\n const styleId = `polyline-${lineIndex}`\n\n // Taro: color (hex);腾讯地图: color\n // Taro: width (number);腾讯地图: width\n // Taro: dottedLine (boolean);腾讯地图: dashArray ([10,10]虚线, [0,0]实线)\n polylineStyles[styleId] = {\n color: line.color || '#3777FF',\n width: Math.round(line.width ?? 3), // 取整,tlbs-map-react 要求 width 为整数\n // 虚线:[10, 10] 表示10像素实线 + 10像素空白;实线:[0, 0]\n dashArray: line.dottedLine ? [10, 10] : [0, 0],\n }\n\n // Taro: points 是 {latitude, longitude}[] 数组\n // tlbs-map-react: geometries 需要路径点数组\n polylineGeometries.push({\n id: String(lineIndex),\n styleId,\n paths: line.points.map((point) => ({\n lat: point.latitude,\n lng: point.longitude,\n })),\n })\n })\n\n /** ************************适配options参数********************** */\n const hasCenter = typeof latitude === 'number' && typeof longitude === 'number'\n const mergedOptions = {\n ...(hasCenter ? { center: { lat: latitude, lng: longitude } } : {}),\n zoom: scale ?? 13,\n minZoom: minScale ?? 3,\n maxZoom: maxScale ?? 20,\n rotatable: enableRotate ?? false, // Taro: enableRotate;tlbs-map-react: options.rotatable\n ...(typeof rotate === 'number' && { rotation: rotate }), // Taro: rotate;tlbs-map-react: options.rotation\n ...(typeof skew === 'number' && { pitch: skew }), // Taro: skew;tlbs-map-react: options.pitch\n }\n\n /** ************************处理事件********************** */\n // Taro: onTap;腾讯地图: click\n // 腾讯地图事件返回: MapEvent { latLng: LatLng, point: {x, y}, type, target, originalEvent }\n // Taro 事件格式: BaseEventOrig { type, timeStamp, target, currentTarget, detail, ... }\n const handleMapClick = (e: MapTypes.MapEvent) => {\n console.log(logPrefix, 'source click e:', e)\n if (typeof onTap === 'function') {\n onTap({\n type: e.type,\n timeStamp: Date.now(),\n target: {\n id: id || '',\n tagName: 'map',\n dataset: {},\n },\n currentTarget: {\n id: id || '',\n tagName: 'map',\n dataset: {},\n },\n detail: {\n latitude: e.latLng.lat,\n longitude: e.latLng.lng,\n },\n preventDefault: () => {},\n stopPropagation: () => {},\n })\n }\n }\n\n // 存储地图实例,用于 H5 端自定义气泡\n const [mapInstance, setMapInstance] = useState<MapTypes.Map | null>(null)\n\n // 地图初始化成功\n const handleMapInited = (instance: MapTypes.Map) => {\n console.log(logPrefix, '地图初始化成功', instance)\n setMapInstance(instance)\n\n // 注册地图实例到全局存储\n if (id) {\n registerMapInstance(id, instance)\n console.log(logPrefix, '已注册地图实例到 MapContext, id:', id)\n }\n\n let settled = false\n instance.on('tilesloaded', (_res) => { /** 瓦片加载完成,地图真正可用 */\n // TODO: 临时先这么简单处理鉴权成功\n if (!settled && typeof onAuthSuccess === 'function') {\n settled = true\n onAuthSuccess({\n type: 'authsuccess',\n timeStamp: Date.now(),\n target: {\n id: id || '',\n tagName: 'map',\n dataset: {},\n },\n currentTarget: {\n id: id || '',\n tagName: 'map',\n dataset: {},\n },\n detail: {\n errCode: 0,\n errMsg: 'ok',\n },\n preventDefault: () => {},\n stopPropagation: () => {},\n })\n }\n })\n setTimeout(() => {\n if (!settled && typeof onError === 'function') {\n settled = true\n onError({\n type: 'error',\n timeStamp: Date.now(),\n target: {\n id: id || '',\n tagName: 'map',\n dataset: {},\n },\n currentTarget: {\n id: id || '',\n tagName: 'map',\n dataset: {},\n },\n detail: {\n errCode: 1001,\n errMsg: 'timeout',\n },\n preventDefault: () => {},\n stopPropagation: () => {},\n })\n }\n }, 3000)\n }\n\n // 组件卸载时清理地图实例\n useEffect(() => {\n return () => {\n if (id) {\n unregisterMapInstance(id)\n console.log(logPrefix, '已注销地图实例, id:', id)\n }\n }\n }, [id])\n\n return (\n <TMap\n id={id}\n ref={forwardedRef}\n className={className}\n style={styleObj}\n apiKey={authKey ?? ''}\n options={mergedOptions}\n onClick={handleMapClick}\n onMapInited={handleMapInited}\n >\n {normalizedMarkers.length > 0 ? (\n <MultiMarker id=\"taro-markers\" styles={markerStyles} geometries={markerGeometries} />\n ) : null}\n {polylineGeometries.length > 0 ? (\n <MultiPolyline id=\"taro-polylines\" styles={polylineStyles} geometries={polylineGeometries} />\n ) : null}\n\n {/* H5 端:自动处理 slot=\"callout\" 的 CoverView */}\n {process.env.TARO_ENV === 'h5' ? renderH5CustomCallouts() : props.children}\n </TMap>\n )\n\n /**\n * H5 端渲染自定义气泡\n * 拦截 slot=\"callout\" 的 CoverView,转换为自定义 Overlay\n */\n function renderH5CustomCallouts() {\n if (!mapInstance) return null\n\n // 1. 遍历 props.children,找到 slot=\"callout\" 的 CoverView\n const childrenArray = Children.toArray(props.children)\n const calloutSlot = childrenArray.find((child: any) =>\n React.isValidElement(child) && child.props?.slot === 'callout'\n )\n\n if (!calloutSlot || !React.isValidElement(calloutSlot)) {\n return null\n }\n\n // 2. 遍历内层的 CoverView,提取 markerId 和内容\n const innerCoverViews = Children.toArray(calloutSlot.props.children)\n\n return innerCoverViews.map((child: any) => {\n if (!React.isValidElement(child)) return null\n\n const markerId = child.props?.markerId\n if (!markerId) return null\n\n // 3. 找到对应的 marker 信息\n const marker = normalizedMarkers.find((m: any) => m.id === markerId)\n if (!marker) {\n console.warn(logPrefix, `未找到 markerId=${markerId} 对应的 marker`)\n return null\n }\n\n // 4. 渲染自定义气泡\n return (\n <MapCustomCallout\n key={markerId}\n map={mapInstance}\n markerId={markerId}\n position={{ lat: marker.latitude, lng: marker.longitude }}\n anchorX={marker.customCallout?.anchorX ?? 0}\n anchorY={marker.customCallout?.anchorY ?? 0}\n display={marker.customCallout?.display ?? 'ALWAYS'}\n onCalloutTap={(id) => {\n // 触发 onCalloutTap 事件\n if (typeof props.onCalloutTap === 'function') {\n props.onCalloutTap({\n type: 'callouttap',\n timeStamp: Date.now(),\n target: {\n id: String(id) || '',\n tagName: 'callout',\n dataset: {},\n },\n currentTarget: {\n id: String(id) || '',\n tagName: 'callout',\n dataset: {},\n },\n detail: { markerId: id },\n preventDefault: () => {},\n stopPropagation: () => {},\n })\n }\n }}\n >\n {child.props.children}\n </MapCustomCallout>\n )\n })\n }\n}\n\nexport default createForwardRefComponent(Map)\n\n/**\n * @deprecated 请使用 Taro.createMapContext 代替\n *\n * 此导出仅用于向后兼容,将在未来版本中移除。\n *\n * 推荐用法:\n * ```tsx\n * import Taro from '@tarojs/taro'\n *\n * const mapCtx = Taro.createMapContext('mapId')\n * ```\n */\nexport { createMapContext } from './createMapContext'\n"],"names":["Map","props","forwardedRef","id","className","style","authKey","longitude","latitude","scale","minScale","maxScale","enableRotate","rotate","skew","markers","polyline","onTap","onAuthSuccess","onError","console","log","logPrefix","styleObj","undefined","normalizedMarkers","markerStyles","markerGeometries","forEach","m","index","markerId","String","_a","styleId","parseSize","size","parsed","parseInt","isNaN","markerWidth","width","markerHeight","height","anchor","x","y","iconPath","src","rotation","alpha","opacity","zIndex","push","position","lat","lng","normalizedPolylines","polylineStyles","polylineGeometries","line","lineIndex","points","length","color","Math","round","dashArray","dottedLine","paths","map","point","hasCenter","mergedOptions","center","zoom","minZoom","maxZoom","rotatable","pitch","handleMapClick","e","type","timeStamp","Date","now","target","tagName","dataset","currentTarget","detail","latLng","preventDefault","stopPropagation","mapInstance","setMapInstance","useState","handleMapInited","instance","registerMapInstance","settled","on","_res","errCode","errMsg","setTimeout","useEffect","unregisterMapInstance","_jsxs","TMap","ref","apiKey","options","onClick","onMapInited","children","_jsx","MultiMarker","styles","geometries","MultiPolyline","process","env","TARO_ENV","renderH5CustomCallouts","childrenArray","Children","toArray","calloutSlot","find","child","React","isValidElement","slot","innerCoverViews","marker","warn","MapCustomCallout","anchorX","_c","_b","customCallout","anchorY","_e","_d","display","_g","_f","onCalloutTap","createForwardRefComponent"],"mappings":";;;;;;;;;AAAA;AAkBA,SAASA,GAAGA,CAAEC,KAAe,EAAA;EAC3B,MAAM;IACJC,YAAY;IACZC,EAAE;IACFC,SAAS;IACTC,KAAK;IACLC,OAAO;IACPC,SAAS;IACTC,QAAQ;IACRC,KAAK;IACLC,QAAQ;IACRC,QAAQ;IACRC,YAAY;IACZC,MAAM;IACNC,IAAI;IACJC,OAAO;IACPC,QAAQ;IACRC,KAAK;IACLC,aAAa;AACbC,IAAAA;AACD,G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 大屏方案版本要求
|
|
16
|
+
const MIN_DESIGN_APP_VERSION = 16;
|
|
17
|
+
const MIN_APP_VERSION = '15.7.0';
|
|
18
|
+
// semver 版本比较
|
|
19
|
+
const isAppVersionAtLeast = (version, min) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (!version || typeof version !== 'string') return false;
|
|
22
|
+
const parts = v => {
|
|
23
|
+
const m = String(v).trim().match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
|
|
24
|
+
if (!m) return [];
|
|
25
|
+
return [parseInt(m[1], 10) || 0, parseInt(m[2] || '0', 10) || 0, parseInt(m[3] || '0', 10) || 0];
|
|
26
|
+
};
|
|
27
|
+
const a = parts(version);
|
|
28
|
+
const b = parts(min);
|
|
29
|
+
if (a.length === 0) return false;
|
|
30
|
+
if (b.length === 0) return true;
|
|
31
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
32
|
+
const da = (_a = a[i]) !== null && _a !== void 0 ? _a : 0;
|
|
33
|
+
const db = (_b = b[i]) !== null && _b !== void 0 ? _b : 0;
|
|
34
|
+
if (da > db) return true;
|
|
35
|
+
if (da < db) return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
// 读取 JDMobileConfig,异常时返回 undefined
|
|
40
|
+
const tryGetMobileConfigSync = opt => {
|
|
41
|
+
var _a;
|
|
42
|
+
try {
|
|
43
|
+
const fn = (_a = Taro.JDMobileConfig) === null || _a === void 0 ? void 0 : _a.getMobileConfigSync;
|
|
44
|
+
if (typeof fn !== 'function') return undefined;
|
|
45
|
+
return fn(opt);
|
|
46
|
+
} catch (_b) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
// 判断是否启用测量值缩放适配(true=启用, false=使用系统侧缩放)
|
|
51
|
+
const resolveUseMeasuredScale = res => {
|
|
52
|
+
// H5/weapp 不参与大屏系数
|
|
53
|
+
if (process.env.TARO_ENV === 'h5' || process.env.TARO_ENV === 'weapp') {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// 条件1: designAppVersion < 16,不满足则使用系统侧缩放
|
|
57
|
+
const designAppVersionRaw = res.designAppVersion;
|
|
58
|
+
const designAppVersionMajor = designAppVersionRaw != null ? parseInt(String(designAppVersionRaw).trim(), 10) : Number.NaN;
|
|
59
|
+
if (!Number.isFinite(designAppVersionMajor) || designAppVersionMajor < MIN_DESIGN_APP_VERSION) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
// 条件2: appVersion < 15.7.0,不满足则使用系统侧缩放
|
|
63
|
+
if (!isAppVersionAtLeast(res.version, MIN_APP_VERSION)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
// 条件3: 平台判断
|
|
67
|
+
const platform = String(res.platform || '').toLowerCase();
|
|
68
|
+
if (platform === 'harmony') {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (platform === 'android') {
|
|
72
|
+
const raw = tryGetMobileConfigSync({
|
|
73
|
+
space: 'taro',
|
|
74
|
+
configName: 'config',
|
|
75
|
+
key: 'disableFixBoundingScaleRatio'
|
|
76
|
+
});
|
|
77
|
+
return raw !== 1 && raw !== '1';
|
|
78
|
+
}
|
|
79
|
+
if (platform === 'ios') {
|
|
80
|
+
const raw = tryGetMobileConfigSync({
|
|
81
|
+
space: 'Taro',
|
|
82
|
+
configName: 'excutor',
|
|
83
|
+
key: 'disableBoundingScaleRatio'
|
|
84
|
+
});
|
|
85
|
+
return raw !== 1 && raw !== '1';
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
};
|
|
15
89
|
// 辅助函数:计算 lengthScaleRatio
|
|
16
90
|
const calculateLengthScaleRatio = res => {
|
|
17
91
|
let lengthScaleRatio = res === null || res === void 0 ? void 0 : res.lengthScaleRatio;
|
|
@@ -50,6 +124,29 @@ const setTargetScrollTopWithScale = function (setTargetScrollTop, baseValue, ran
|
|
|
50
124
|
setTargetScrollTop(finalValue);
|
|
51
125
|
}
|
|
52
126
|
};
|
|
127
|
+
// 根据 scrollTop 计算选中索引
|
|
128
|
+
// 系统侧缩放模式:scrollHeight 已被系统缩放,直接相除即可
|
|
129
|
+
// 自行缩放模式:需要除以 ratio 换算(harmony 特殊处理,ratio 已内嵌在 itemHeight 中)
|
|
130
|
+
const getSelectedIndex = function (scrollTop, itemHeight) {
|
|
131
|
+
let lengthScaleRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
132
|
+
let useMeasuredScale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
133
|
+
if (!useMeasuredScale || process.env.TARO_PLATFORM === 'harmony') {
|
|
134
|
+
return Math.round(scrollTop / itemHeight);
|
|
135
|
+
}
|
|
136
|
+
return Math.round(scrollTop / lengthScaleRatio / itemHeight);
|
|
137
|
+
};
|
|
138
|
+
// 计算单项高度(返回设计稿值)
|
|
139
|
+
const calculateItemHeight = function (scrollView, lengthScaleRatio) {
|
|
140
|
+
let useMeasuredScale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
141
|
+
if (process.env.TARO_PLATFORM === 'harmony') {
|
|
142
|
+
return useMeasuredScale ? PICKER_LINE_HEIGHT * lengthScaleRatio : PICKER_LINE_HEIGHT;
|
|
143
|
+
}
|
|
144
|
+
if (scrollView && (scrollView === null || scrollView === void 0 ? void 0 : scrollView.scrollHeight)) {
|
|
145
|
+
return useMeasuredScale ? scrollView.scrollHeight / lengthScaleRatio / scrollView.childNodes.length : scrollView.scrollHeight / scrollView.childNodes.length;
|
|
146
|
+
}
|
|
147
|
+
console.warn('Height measurement anomaly');
|
|
148
|
+
return PICKER_LINE_HEIGHT;
|
|
149
|
+
};
|
|
53
150
|
function PickerGroupBasic(props) {
|
|
54
151
|
const {
|
|
55
152
|
range = [],
|
|
@@ -70,35 +167,25 @@ function PickerGroupBasic(props) {
|
|
|
70
167
|
// 触摸状态用于优化用户体验
|
|
71
168
|
const [isTouching, setIsTouching] = React.useState(false);
|
|
72
169
|
const lengthScaleRatioRef = React.useRef(1);
|
|
170
|
+
const useMeasuredScaleRef = React.useRef(false);
|
|
73
171
|
const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
|
|
74
|
-
// 初始化时计算 lengthScaleRatio
|
|
172
|
+
// 初始化时计算 lengthScaleRatio 并判定缩放模式
|
|
75
173
|
React.useEffect(() => {
|
|
76
174
|
Taro.getSystemInfo({
|
|
77
175
|
success: res => {
|
|
78
176
|
lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
|
|
177
|
+
useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
|
|
178
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
79
179
|
},
|
|
80
180
|
fail: () => {
|
|
81
|
-
// 失败时使用默认值 1
|
|
82
181
|
lengthScaleRatioRef.current = 1;
|
|
182
|
+
useMeasuredScaleRef.current = false;
|
|
83
183
|
}
|
|
84
184
|
});
|
|
85
185
|
}, []);
|
|
86
186
|
React.useEffect(() => {
|
|
87
|
-
|
|
88
|
-
if (process.env.TARO_PLATFORM === 'harmony') {
|
|
89
|
-
itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
|
|
90
|
-
} else {
|
|
91
|
-
if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
|
|
92
|
-
itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
|
|
93
|
-
} else {
|
|
94
|
-
console.warn('Height measurement anomaly');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
187
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
97
188
|
}, [range.length]); // 只在range长度变化时重新计算
|
|
98
|
-
// 获取选中的索引
|
|
99
|
-
const getSelectedIndex = scrollTop => {
|
|
100
|
-
return Math.round(scrollTop / itemHeightRef.current);
|
|
101
|
-
};
|
|
102
189
|
// 当selectedIndex变化时,调整滚动位置
|
|
103
190
|
React.useEffect(() => {
|
|
104
191
|
if (scrollViewRef.current && range.length > 0 && !isTouching) {
|
|
@@ -120,7 +207,7 @@ function PickerGroupBasic(props) {
|
|
|
120
207
|
isCenterTimerId.current = setTimeout(() => {
|
|
121
208
|
if (!scrollViewRef.current) return;
|
|
122
209
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
123
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
210
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
124
211
|
setIsTouching(false);
|
|
125
212
|
const baseValue = newIndex * itemHeightRef.current;
|
|
126
213
|
const randomOffset = Math.random() * 0.001; // 随机数为了在一个项内滚动时强制刷新
|
|
@@ -141,7 +228,7 @@ function PickerGroupBasic(props) {
|
|
|
141
228
|
isCenterTimerId.current = null;
|
|
142
229
|
}
|
|
143
230
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
144
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
231
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
145
232
|
if (newIndex !== currentIndex) {
|
|
146
233
|
setCurrentIndex(newIndex);
|
|
147
234
|
}
|
|
@@ -214,34 +301,25 @@ function PickerGroupTime(props) {
|
|
|
214
301
|
const [currentIndex, setCurrentIndex] = React.useState(selectedIndex);
|
|
215
302
|
const [isTouching, setIsTouching] = React.useState(false);
|
|
216
303
|
const lengthScaleRatioRef = React.useRef(1);
|
|
304
|
+
const useMeasuredScaleRef = React.useRef(false);
|
|
217
305
|
const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
|
|
218
|
-
// 初始化时计算 lengthScaleRatio
|
|
306
|
+
// 初始化时计算 lengthScaleRatio 并判定缩放模式
|
|
219
307
|
React.useEffect(() => {
|
|
220
308
|
Taro.getSystemInfo({
|
|
221
309
|
success: res => {
|
|
222
310
|
lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
|
|
311
|
+
useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
|
|
312
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
223
313
|
},
|
|
224
314
|
fail: () => {
|
|
225
|
-
// 失败时使用默认值 1
|
|
226
315
|
lengthScaleRatioRef.current = 1;
|
|
316
|
+
useMeasuredScaleRef.current = false;
|
|
227
317
|
}
|
|
228
318
|
});
|
|
229
319
|
}, []);
|
|
230
320
|
React.useEffect(() => {
|
|
231
|
-
|
|
232
|
-
if (process.env.TARO_PLATFORM === 'harmony') {
|
|
233
|
-
itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
|
|
234
|
-
} else {
|
|
235
|
-
if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
|
|
236
|
-
itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
|
|
237
|
-
} else {
|
|
238
|
-
console.warn('Height measurement anomaly');
|
|
239
|
-
}
|
|
240
|
-
}
|
|
321
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
241
322
|
}, [range.length]); // 只在range长度变化时重新计算
|
|
242
|
-
const getSelectedIndex = scrollTop => {
|
|
243
|
-
return Math.round(scrollTop / itemHeightRef.current);
|
|
244
|
-
};
|
|
245
323
|
// 当selectedIndex变化时,调整滚动位置
|
|
246
324
|
React.useEffect(() => {
|
|
247
325
|
if (scrollViewRef.current && range.length > 0 && !isTouching) {
|
|
@@ -263,7 +341,7 @@ function PickerGroupTime(props) {
|
|
|
263
341
|
isCenterTimerId.current = setTimeout(() => {
|
|
264
342
|
if (!scrollViewRef.current) return;
|
|
265
343
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
266
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
344
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
267
345
|
setIsTouching(false);
|
|
268
346
|
// 调用updateIndex执行限位逻辑,获取是否触发了限位
|
|
269
347
|
const isLimited = Boolean(updateIndex(newIndex, columnId, true));
|
|
@@ -284,7 +362,7 @@ function PickerGroupTime(props) {
|
|
|
284
362
|
isCenterTimerId.current = null;
|
|
285
363
|
}
|
|
286
364
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
287
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
365
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
288
366
|
if (newIndex !== currentIndex) {
|
|
289
367
|
setCurrentIndex(newIndex);
|
|
290
368
|
}
|
|
@@ -355,34 +433,25 @@ function PickerGroupDate(props) {
|
|
|
355
433
|
const [currentIndex, setCurrentIndex] = React.useState(selectedIndex);
|
|
356
434
|
const [isTouching, setIsTouching] = React.useState(false);
|
|
357
435
|
const lengthScaleRatioRef = React.useRef(1);
|
|
436
|
+
const useMeasuredScaleRef = React.useRef(false);
|
|
358
437
|
const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
|
|
359
|
-
// 初始化时计算 lengthScaleRatio
|
|
438
|
+
// 初始化时计算 lengthScaleRatio 并判定缩放模式
|
|
360
439
|
React.useEffect(() => {
|
|
361
440
|
Taro.getSystemInfo({
|
|
362
441
|
success: res => {
|
|
363
442
|
lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
|
|
443
|
+
useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
|
|
444
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
364
445
|
},
|
|
365
446
|
fail: () => {
|
|
366
|
-
// 失败时使用默认值 1
|
|
367
447
|
lengthScaleRatioRef.current = 1;
|
|
448
|
+
useMeasuredScaleRef.current = false;
|
|
368
449
|
}
|
|
369
450
|
});
|
|
370
451
|
}, []);
|
|
371
452
|
React.useEffect(() => {
|
|
372
|
-
|
|
373
|
-
if (process.env.TARO_PLATFORM === 'harmony') {
|
|
374
|
-
itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
|
|
375
|
-
} else {
|
|
376
|
-
if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
|
|
377
|
-
itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
|
|
378
|
-
} else {
|
|
379
|
-
console.warn('Height measurement anomaly');
|
|
380
|
-
}
|
|
381
|
-
}
|
|
453
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
382
454
|
}, [range.length]); // 只在range长度变化时重新计算
|
|
383
|
-
const getSelectedIndex = scrollTop => {
|
|
384
|
-
return Math.round(scrollTop / itemHeightRef.current);
|
|
385
|
-
};
|
|
386
455
|
// 当selectedIndex变化时,调整滚动位置
|
|
387
456
|
React.useEffect(() => {
|
|
388
457
|
if (scrollViewRef.current && range.length > 0 && !isTouching) {
|
|
@@ -404,7 +473,7 @@ function PickerGroupDate(props) {
|
|
|
404
473
|
isCenterTimerId.current = setTimeout(() => {
|
|
405
474
|
if (!scrollViewRef.current) return;
|
|
406
475
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
407
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
476
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
408
477
|
setIsTouching(false);
|
|
409
478
|
const baseValue = newIndex * itemHeightRef.current;
|
|
410
479
|
const randomOffset = Math.random() * 0.001; // 随机数为了在一个项内滚动时强制刷新
|
|
@@ -427,7 +496,7 @@ function PickerGroupDate(props) {
|
|
|
427
496
|
isCenterTimerId.current = null;
|
|
428
497
|
}
|
|
429
498
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
430
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
499
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
431
500
|
if (newIndex !== currentIndex) {
|
|
432
501
|
setCurrentIndex(newIndex);
|
|
433
502
|
}
|
|
@@ -498,40 +567,31 @@ function PickerGroupRegion(props) {
|
|
|
498
567
|
const [currentIndex, setCurrentIndex] = React.useState(selectedIndex);
|
|
499
568
|
const [isTouching, setIsTouching] = React.useState(false);
|
|
500
569
|
const lengthScaleRatioRef = React.useRef(1);
|
|
570
|
+
const useMeasuredScaleRef = React.useRef(false);
|
|
501
571
|
const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
|
|
502
572
|
const isUserBeginScrollRef = React.useRef(false);
|
|
503
|
-
// 初始化时计算 lengthScaleRatio
|
|
573
|
+
// 初始化时计算 lengthScaleRatio 并判定缩放模式
|
|
504
574
|
React.useEffect(() => {
|
|
505
575
|
Taro.getSystemInfo({
|
|
506
576
|
success: res => {
|
|
507
577
|
lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
|
|
578
|
+
useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
|
|
579
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
508
580
|
},
|
|
509
581
|
fail: () => {
|
|
510
|
-
// 失败时使用默认值 1
|
|
511
582
|
lengthScaleRatioRef.current = 1;
|
|
583
|
+
useMeasuredScaleRef.current = false;
|
|
512
584
|
}
|
|
513
585
|
});
|
|
514
586
|
}, []);
|
|
515
587
|
React.useEffect(() => {
|
|
516
|
-
|
|
517
|
-
if (process.env.TARO_PLATFORM === 'harmony') {
|
|
518
|
-
itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
|
|
519
|
-
} else {
|
|
520
|
-
if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
|
|
521
|
-
itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
|
|
522
|
-
} else {
|
|
523
|
-
console.warn('Height measurement anomaly');
|
|
524
|
-
}
|
|
525
|
-
}
|
|
588
|
+
itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
526
589
|
}, [range.length]); // 只在range长度变化时重新计算
|
|
527
|
-
const getSelectedIndex = scrollTop => {
|
|
528
|
-
return Math.round(scrollTop / itemHeightRef.current);
|
|
529
|
-
};
|
|
530
590
|
// 当selectedIndex变化时,调整滚动位置
|
|
531
591
|
React.useEffect(() => {
|
|
532
592
|
if (scrollViewRef.current && range.length > 0 && !isTouching) {
|
|
533
593
|
const baseValue = selectedIndex * itemHeightRef.current;
|
|
534
|
-
setTargetScrollTopWithScale(setTargetScrollTop, baseValue);
|
|
594
|
+
setTargetScrollTopWithScale(setTargetScrollTop, baseValue, undefined, lengthScaleRatioRef.current);
|
|
535
595
|
setCurrentIndex(selectedIndex);
|
|
536
596
|
}
|
|
537
597
|
}, [selectedIndex, range]);
|
|
@@ -547,7 +607,7 @@ function PickerGroupRegion(props) {
|
|
|
547
607
|
isCenterTimerId.current = setTimeout(() => {
|
|
548
608
|
if (!scrollViewRef.current) return;
|
|
549
609
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
550
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
610
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
551
611
|
setIsTouching(false);
|
|
552
612
|
const baseValue = newIndex * itemHeightRef.current;
|
|
553
613
|
const randomOffset = Math.random() * 0.001; // 随机数为了在一个项内滚动时强制刷新
|
|
@@ -563,7 +623,7 @@ function PickerGroupRegion(props) {
|
|
|
563
623
|
isCenterTimerId.current = null;
|
|
564
624
|
}
|
|
565
625
|
const scrollTop = scrollViewRef.current.scrollTop;
|
|
566
|
-
const newIndex = getSelectedIndex(scrollTop);
|
|
626
|
+
const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
|
|
567
627
|
if (newIndex !== currentIndex) {
|
|
568
628
|
setCurrentIndex(newIndex);
|
|
569
629
|
}
|