@mpxjs/webpack-plugin 2.10.16 → 2.10.17

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.
Files changed (226) hide show
  1. package/lib/dependencies/AppEntryDependency.js +2 -2
  2. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  3. package/lib/dependencies/ResolveDependency.js +1 -1
  4. package/lib/helpers.js +2 -0
  5. package/lib/index.js +40 -15
  6. package/lib/json-compiler/helper.js +72 -2
  7. package/lib/json-compiler/index.js +14 -54
  8. package/lib/json-compiler/plugin.js +2 -2
  9. package/lib/loader.js +10 -4
  10. package/lib/native-loader.js +6 -3
  11. package/lib/platform/json/wx/index.js +24 -29
  12. package/lib/platform/style/wx/index.js +8 -1
  13. package/lib/platform/template/wx/component-config/button.js +12 -3
  14. package/lib/platform/template/wx/component-config/component.js +31 -33
  15. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  16. package/lib/react/index.js +2 -0
  17. package/lib/react/processJSON.js +39 -71
  18. package/lib/react/processStyles.js +3 -2
  19. package/lib/react/processTemplate.js +8 -6
  20. package/lib/react/script-helper.js +6 -16
  21. package/lib/react/style-helper.js +10 -2
  22. package/lib/runtime/components/react/context.ts +12 -6
  23. package/lib/runtime/components/react/dist/context.d.ts +75 -0
  24. package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
  25. package/lib/runtime/components/react/dist/context.js +1 -0
  26. package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
  27. package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
  29. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
  30. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
  31. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
  32. package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
  33. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
  39. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
  40. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
  41. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
  42. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
  43. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
  44. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
  45. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
  46. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
  47. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
  48. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
  49. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
  50. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  51. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
  52. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
  53. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
  54. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
  55. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
  56. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
  57. package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
  58. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
  59. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
  60. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
  61. package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
  62. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
  63. package/lib/runtime/components/react/dist/mpx-image.jsx +107 -57
  64. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
  65. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
  66. package/lib/runtime/components/react/dist/mpx-input.d.ts +50 -0
  67. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
  68. package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
  69. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
  70. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
  71. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +58 -50
  72. package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
  73. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
  74. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
  75. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
  76. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
  77. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
  78. package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
  79. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
  80. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  81. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
  82. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
  83. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
  84. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
  85. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
  86. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
  87. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
  88. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
  89. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
  92. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
  93. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
  94. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
  95. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
  96. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
  97. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
  98. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
  99. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
  100. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
  101. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
  102. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
  103. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  104. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
  105. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
  106. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
  107. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
  108. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  109. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
  110. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
  111. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  112. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
  113. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
  114. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  115. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
  116. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
  117. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
  118. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
  119. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
  120. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
  121. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
  122. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
  123. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
  124. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
  125. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
  126. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
  127. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  128. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
  129. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
  130. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
  131. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
  132. package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
  133. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
  134. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
  135. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
  136. package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
  137. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
  138. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
  139. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
  140. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
  141. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
  142. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  143. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
  144. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
  145. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
  146. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
  147. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  148. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
  149. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
  150. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
  151. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
  152. package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
  153. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
  154. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
  155. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
  156. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
  157. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
  158. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
  159. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
  160. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
  161. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
  162. package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
  163. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
  164. package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
  165. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
  166. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  167. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
  168. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
  169. package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
  170. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
  171. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  172. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
  173. package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
  174. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
  175. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
  176. package/lib/runtime/components/react/dist/mpx-web-view.jsx +10 -2
  177. package/lib/runtime/components/react/dist/parser.d.ts +40 -0
  178. package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
  179. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
  180. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
  181. package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
  182. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
  183. package/lib/runtime/components/react/dist/utils.d.ts +123 -0
  184. package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
  185. package/lib/runtime/components/react/dist/utils.jsx +16 -6
  186. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  187. package/lib/runtime/components/react/mpx-image.tsx +130 -77
  188. package/lib/runtime/components/react/mpx-input.tsx +38 -15
  189. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -49
  190. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  191. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  192. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  193. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  194. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  195. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  196. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  197. package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
  198. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  199. package/lib/runtime/components/react/mpx-view.tsx +1 -1
  200. package/lib/runtime/components/react/mpx-web-view.tsx +13 -4
  201. package/lib/runtime/components/react/types/common.d.ts +19 -0
  202. package/lib/runtime/components/react/utils.tsx +15 -6
  203. package/lib/script-setup-compiler/index.js +2 -2
  204. package/lib/style-compiler/index.js +3 -2
  205. package/lib/style-compiler/load-postcss-config.js +1 -1
  206. package/lib/style-compiler/plugins/trans-special.js +10 -2
  207. package/lib/style-compiler/strip-conditional-loader.js +177 -15
  208. package/lib/template-compiler/compiler.js +268 -70
  209. package/lib/template-compiler/gen-node-react.js +18 -6
  210. package/lib/template-compiler/index.js +6 -4
  211. package/lib/template-compiler/parse-exps.js +1 -1
  212. package/lib/utils/const.js +2 -1
  213. package/lib/utils/dom-tag-config.js +5 -5
  214. package/lib/utils/env.js +6 -1
  215. package/lib/utils/get-build-tag-component.js +35 -0
  216. package/lib/utils/merge-visitors.js +55 -0
  217. package/lib/utils/pre-process-json.js +5 -0
  218. package/lib/web/index.js +2 -0
  219. package/lib/web/processJSON.js +44 -16
  220. package/lib/web/processScript.js +1 -1
  221. package/lib/web/processTemplate.js +6 -4
  222. package/lib/web/script-helper.js +19 -9
  223. package/lib/wxs/pre-loader.js +9 -6
  224. package/lib/wxss/loader.js +1 -9
  225. package/package.json +15 -5
  226. package/lib/utils/chain-assign.js +0 -47
@@ -1,8 +1,9 @@
1
- import React, { ReactNode, useContext, useEffect } from 'react'
1
+ /* eslint-disable space-before-function-paren */
2
+ import React, { ReactNode, useContext, useEffect, useRef } from 'react'
2
3
  import { DimensionValue, EmitterSubscription, Keyboard, View, ViewStyle, NativeSyntheticEvent, NativeTouchEvent } from 'react-native'
3
- import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
4
+ import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, cancelAnimation } from 'react-native-reanimated'
4
5
  import { KeyboardAvoidContext } from './context'
5
- import { isIOS } from './utils'
6
+ import { isAndroid, isIOS } from './utils'
6
7
 
7
8
  type KeyboardAvoidViewProps = {
8
9
  children?: ReactNode
@@ -18,15 +19,34 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
18
19
  const basic = useSharedValue('auto')
19
20
  const keyboardAvoid = useContext(KeyboardAvoidContext)
20
21
 
22
+ // fix: 某些特殊机型下隐藏键盘可能会先触发一次 keyboardWillShow,
23
+ // 比如机型 iPhone 11 Pro,可能会导致显隐动画冲突
24
+ // 因此增加状态标记 + cancelAnimation 来优化
25
+ const isShow = useRef<boolean>(false)
26
+
21
27
  const animatedStyle = useAnimatedStyle(() => ({
22
- transform: [{ translateY: -offset.value }],
28
+ // translate/position top可能会导致底部渲染区域缺失
29
+ marginTop: -offset.value,
23
30
  flexBasis: basic.value as DimensionValue
24
31
  }))
25
32
 
26
33
  const resetKeyboard = () => {
34
+ if (!isShow.current) {
35
+ return
36
+ }
37
+
38
+ isShow.current = false
39
+
27
40
  if (keyboardAvoid?.current) {
41
+ const inputRef = keyboardAvoid.current.ref?.current
42
+ if (inputRef && inputRef.isFocused()) {
43
+ // 修复 Android 点击键盘收起按钮时当前 input 没触发失焦的问题
44
+ inputRef.blur()
45
+ }
28
46
  keyboardAvoid.current = null
29
47
  }
48
+
49
+ cancelAnimation(offset)
30
50
  offset.value = withTiming(0, { duration, easing })
31
51
  basic.value = 'auto'
32
52
  }
@@ -40,51 +60,55 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
40
60
  useEffect(() => {
41
61
  let subscriptions: EmitterSubscription[] = []
42
62
 
43
- if (isIOS) {
44
- subscriptions = [
45
- Keyboard.addListener('keyboardWillShow', (evt: any) => {
46
- if (!keyboardAvoid?.current) return
47
- const { endCoordinates } = evt
48
- const { ref, cursorSpacing = 0 } = keyboardAvoid.current
49
- setTimeout(() => {
50
- ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
63
+ function keybaordAvoding(evt: any) {
64
+ if (!keyboardAvoid?.current || isShow.current) {
65
+ return
66
+ }
67
+
68
+ isShow.current = true
69
+
70
+ const { endCoordinates } = evt
71
+ const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow } = keyboardAvoid.current
72
+ keyboardAvoid.current.keyboardHeight = endCoordinates.height
73
+ onKeyboardShow?.()
74
+ if (adjustPosition) {
75
+ // 默认沿用旧版本逻辑,在 android 原生关闭键盘避让的情况下应该将该配置设置为 false,走 mpx 的键盘避让逻辑,否则bundle内的所有input都会无法避让键盘
76
+ const enableNativeKeyboardAvoiding = mpxGlobal?.__mpx?.config?.rnConfig?.enableNativeKeyboardAvoiding ?? true
77
+ const callback = () => {
78
+ ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
79
+ function calculateOffset() {
80
+ // enableNativeKeyboardAvoding 默认开启
81
+ if (enableNativeKeyboardAvoiding && isAndroid) {
82
+ const aboveOffset = pageY + height - endCoordinates.screenY
83
+ const belowOffset = endCoordinates.height - aboveOffset
84
+ const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
85
+ const belowValue = Math.min(belowOffset, cursorSpacing)
86
+ return aboveOffset > 0 ? belowValue : aboveValue
87
+ }
88
+
51
89
  const aboveOffset = offset.value + pageY + height - endCoordinates.screenY
52
90
  const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
53
91
  const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
54
- const value = aboveOffset > 0 ? belowValue : aboveValue
55
- offset.value = withTiming(value, { duration, easing }, (finished) => {
56
- if (finished) {
57
- // Set flexBasic after animation to trigger re-layout and reset layout information
58
- basic.value = '99.99%'
59
- }
60
- })
61
- })
62
- })
63
- }),
64
- Keyboard.addListener('keyboardWillHide', resetKeyboard)
65
- ]
66
- } else {
67
- subscriptions = [
68
- Keyboard.addListener('keyboardDidShow', (evt: any) => {
69
- if (!keyboardAvoid?.current) return
70
- const { endCoordinates } = evt
71
- const { ref, cursorSpacing = 0 } = keyboardAvoid.current
72
- ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
73
- const aboveOffset = pageY + height - endCoordinates.screenY
74
- const belowOffset = endCoordinates.height - aboveOffset
75
- const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
76
- const belowValue = Math.min(belowOffset, cursorSpacing)
77
- const value = aboveOffset > 0 ? belowValue : aboveValue
78
- offset.value = withTiming(value, { duration, easing }, (finished) => {
92
+ return aboveOffset > 0 ? belowValue : aboveValue
93
+ }
94
+
95
+ cancelAnimation(offset)
96
+ offset.value = withTiming(calculateOffset(), { duration, easing }, finished => {
79
97
  if (finished) {
80
98
  // Set flexBasic after animation to trigger re-layout and reset layout information
81
99
  basic.value = '99.99%'
82
100
  }
83
101
  })
84
102
  })
85
- }),
86
- Keyboard.addListener('keyboardDidHide', resetKeyboard)
87
- ]
103
+ }
104
+ ;(isIOS ? () => setTimeout(callback) : callback)()
105
+ }
106
+ }
107
+
108
+ if (isIOS) {
109
+ subscriptions = [Keyboard.addListener('keyboardWillShow', keybaordAvoding), Keyboard.addListener('keyboardWillHide', resetKeyboard)]
110
+ } else {
111
+ subscriptions = [Keyboard.addListener('keyboardDidShow', keybaordAvoding), Keyboard.addListener('keyboardDidHide', resetKeyboard)]
88
112
  }
89
113
 
90
114
  return () => {
@@ -93,15 +117,8 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
93
117
  }, [keyboardAvoid])
94
118
 
95
119
  return (
96
- <View style={style} onTouchEnd={onTouchEnd}>
97
- <Animated.View
98
- style={[
99
- contentContainerStyle,
100
- animatedStyle
101
- ]}
102
- >
103
- {children}
104
- </Animated.View>
120
+ <View style={style} onTouchEnd={onTouchEnd} onTouchMove={onTouchEnd}>
121
+ <Animated.View style={[contentContainerStyle, animatedStyle]}>{children}</Animated.View>
105
122
  </View>
106
123
  )
107
124
  }
@@ -0,0 +1,155 @@
1
+ /* eslint-disable space-before-function-paren */
2
+ import { useState, useMemo, memo } from 'react'
3
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
4
+ import { StatusBar, processColor, TouchableWithoutFeedback, Image, View, StyleSheet, Text } from 'react-native'
5
+
6
+ function convertToHex(color?: string) {
7
+ try {
8
+ const intColor = processColor(color) as number | null | undefined
9
+ if (intColor === null || intColor === undefined) {
10
+ return null
11
+ }
12
+ // 将32位整数颜色值转换为RGBA
13
+ const r = (intColor >> 16) & 255
14
+ const g = (intColor >> 8) & 255
15
+ const b = intColor & 255
16
+ // 转换为十六进制
17
+ const hexR = r.toString(16).padStart(2, '0')
18
+ const hexG = g.toString(16).padStart(2, '0')
19
+ const hexB = b.toString(16).padStart(2, '0')
20
+ return `#${hexR}${hexG}${hexB}`
21
+ } catch (error) {
22
+ return null
23
+ }
24
+ }
25
+
26
+ const titleHeight = 44
27
+ export function useInnerHeaderHeight(pageConfig: PageConfig) {
28
+ const safeArea = useSafeAreaInsets()
29
+ if (pageConfig.navigationStyle === 'custom') {
30
+ return 0
31
+ } else {
32
+ const safeAreaTop = safeArea?.top || 0
33
+ const headerHeight = safeAreaTop + titleHeight
34
+ return headerHeight
35
+ }
36
+ }
37
+
38
+ const styles = StyleSheet.create({
39
+ header: {
40
+ elevation: 3
41
+ },
42
+ headerContent: {
43
+ flexDirection: 'row',
44
+ alignItems: 'center',
45
+ justifyContent: 'center'
46
+ },
47
+ backButton: {
48
+ position: 'absolute',
49
+ height: '100%',
50
+ width: 40,
51
+ left: 0,
52
+ top: 0,
53
+ alignItems: 'center',
54
+ justifyContent: 'center'
55
+ },
56
+ backButtonImage: {
57
+ width: 22,
58
+ height: 22
59
+ },
60
+ title: {
61
+ fontSize: 17,
62
+ fontWeight: 600,
63
+ width: '60%',
64
+ textAlign: 'center'
65
+ }
66
+ })
67
+ const NavColor = {
68
+ White: '#ffffff',
69
+ Black: '#000000'
70
+ }
71
+ // navigationBarTextStyle 只支持黑白 'white'/'black
72
+ const validBarTextStyle = (textStyle?: string) => {
73
+ const textStyleColor = convertToHex(textStyle)
74
+ if (textStyle && textStyleColor && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
75
+ return textStyleColor
76
+ } else {
77
+ return NavColor.White
78
+ }
79
+ }
80
+
81
+ export interface MpxNavProps {
82
+ pageConfig: PageConfig
83
+ navigation: any
84
+ }
85
+
86
+ const BACK_ICON =
87
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg=='
88
+
89
+ const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
90
+ const [innerPageConfig, setPageConfig] = useState<PageConfig>(pageConfig || {})
91
+ const safeAreaTop = useSafeAreaInsets()?.top || 0
92
+
93
+ navigation.setPageConfig = (config: PageConfig) => {
94
+ setPageConfig(Object.assign({}, innerPageConfig, config))
95
+ }
96
+ const isCustom = innerPageConfig.navigationStyle === 'custom'
97
+ const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
98
+ // 状态栏的颜色
99
+ const statusBarElement = (
100
+ <StatusBar
101
+ translucent
102
+ backgroundColor='transparent'
103
+ barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
104
+ )
105
+
106
+ if (isCustom) return statusBarElement
107
+ // 假设是栈导航,获取栈的长度
108
+ const stackLength = navigation.getState()?.routes?.length
109
+ const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack
110
+ const isHandleStackTopBack = typeof onStackTopBack === 'function'
111
+
112
+ // 回退按钮与图标
113
+ // prettier-ignore
114
+ const backElement = stackLength > 1 || isHandleStackTopBack
115
+ ? (
116
+ <TouchableWithoutFeedback
117
+ onPress={() => {
118
+ if (stackLength <= 1 && isHandleStackTopBack) {
119
+ onStackTopBack()
120
+ return
121
+ }
122
+ navigation.goBack()
123
+ }}>
124
+ <View style={[styles.backButton]}>
125
+ <Image style={[styles.backButtonImage, { tintColor: navigationBarTextStyle }]} source={{ uri: BACK_ICON }}></Image>
126
+ </View>
127
+ </TouchableWithoutFeedback>
128
+ )
129
+ : null
130
+
131
+ return (
132
+ <View
133
+ style={[
134
+ styles.header,
135
+ {
136
+ paddingTop: safeAreaTop,
137
+ backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
138
+ }
139
+ ]}>
140
+ {statusBarElement}
141
+ {/* TODO: 确定 height 的有效性 */}
142
+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
143
+ {/* @ts-expect-error */}
144
+ <View style={styles.headerContent} height={titleHeight}>
145
+ {backElement}
146
+ <Text style={[styles.title, { color: navigationBarTextStyle }]} numberOfLines={1}>
147
+ {innerPageConfig.navigationBarTitleText?.trim() || ''}
148
+ </Text>
149
+ </View>
150
+ </View>
151
+ )
152
+ })
153
+
154
+ MpxNav.displayName = 'MpxNav'
155
+ export default MpxNav
@@ -33,6 +33,7 @@ interface PickerViewProps {
33
33
  style?: {
34
34
  [key: string]: any
35
35
  }
36
+ 'enable-wheel-animation'?: boolean
36
37
  'indicator-style'?: Record<string, any>,
37
38
  'mask-style'?: Record<string, any>,
38
39
  'enable-var'?: boolean
@@ -69,6 +70,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
69
70
  value = [],
70
71
  bindchange,
71
72
  style,
73
+ 'enable-wheel-animation': enableWheelAnimation = true,
72
74
  'indicator-style': indicatorStyle = {},
73
75
  'mask-style': pickerMaskStyle = {},
74
76
  'enable-var': enableVar,
@@ -168,7 +170,7 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
168
170
  columnData,
169
171
  ref: cloneRef,
170
172
  columnIndex: index,
171
- key: `pick-view-${index}`,
173
+ key: `pick-view-${index}-${columnData.length}`,
172
174
  wrapperStyle: {
173
175
  height: normalStyle?.height || DefaultPickerItemH,
174
176
  itemHeight: indicatorH || DefaultPickerItemH
@@ -176,7 +178,8 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
176
178
  onSelectChange: onSelectChange.bind(null, index),
177
179
  initialIndex,
178
180
  pickerIndicatorStyle,
179
- pickerMaskStyle
181
+ pickerMaskStyle,
182
+ enableWheelAnimation
180
183
  }
181
184
  )
182
185
  const realElement = React.cloneElement(child, wrappedProps)
@@ -5,7 +5,8 @@ import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAn
5
5
  import useNodesRef, { HandlerRef } from '../useNodesRef'
6
6
  import PickerIndicator from './pickerViewIndicator'
7
7
  import PickerMask from './pickerViewMask'
8
- import MpxPickerVIewColumnItem from './pickerViewColumnItem'
8
+ import MpxPickerViewColumnItem from './pickerViewColumnItem'
9
+ import MpxPickerViewColumnItemLite from './pickerViewColumnItemLite'
9
10
  import { PickerViewColumnAnimationContext } from '../mpx-picker-view/pickerVIewContext'
10
11
  import { calcHeightOffsets } from './pickerViewFaces'
11
12
 
@@ -25,6 +26,7 @@ interface ColumnProps {
25
26
  }
26
27
  pickerMaskStyle: Record<string, any>
27
28
  pickerIndicatorStyle: Record<string, any>
29
+ enableWheelAnimation?: boolean
28
30
  }
29
31
 
30
32
  const visibleCount = 5
@@ -39,6 +41,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
39
41
  wrapperStyle,
40
42
  pickerMaskStyle,
41
43
  pickerIndicatorStyle,
44
+ enableWheelAnimation = true,
42
45
  'enable-var': enableVar,
43
46
  'external-var-context': externalVarContext
44
47
  } = props
@@ -95,6 +98,11 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
95
98
  return [{ paddingVertical: paddingHeight }]
96
99
  }, [paddingHeight])
97
100
 
101
+ const initialContentOffsetY = useMemo(
102
+ () => initialIndex * itemRawH,
103
+ [initialIndex, itemRawH]
104
+ )
105
+
98
106
  const getIndex = useCallback((y: number) => {
99
107
  const calc = Math.round(y / itemRawH)
100
108
  return Math.max(0, Math.min(calc, maxIndex))
@@ -152,17 +160,6 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
152
160
  }, isIOS ? 0 : 200)
153
161
  }, [itemRawH, maxIndex, initialIndex])
154
162
 
155
- const onContentSizeChange = useCallback((_w: number, h: number) => {
156
- const y = initialIndex * itemRawH
157
- if (y <= h) {
158
- clearTimerScrollTo()
159
- timerScrollTo.current = setTimeout(() => {
160
- scrollViewRef.current?.scrollTo({ x: 0, y, animated: false })
161
- activeIndex.current = initialIndex
162
- }, 0)
163
- }
164
- }, [itemRawH, initialIndex])
165
-
166
163
  const onItemLayout = useCallback((e: LayoutChangeEvent) => {
167
164
  const { height: rawH } = e.nativeEvent.layout
168
165
  const roundedH = Math.round(rawH)
@@ -287,8 +284,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
287
284
 
288
285
  const renderInnerchild = () =>
289
286
  columnData.map((item: React.ReactElement, index: number) => {
290
- return (
291
- <MpxPickerVIewColumnItem
287
+ return enableWheelAnimation
288
+ ? (<MpxPickerViewColumnItem
292
289
  key={index}
293
290
  item={item}
294
291
  index={index}
@@ -297,8 +294,16 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
297
294
  textProps={textProps}
298
295
  visibleCount={visibleCount}
299
296
  onItemLayout={onItemLayout}
300
- />
301
- )
297
+ />)
298
+ : (<MpxPickerViewColumnItemLite
299
+ key={index}
300
+ item={item}
301
+ index={index}
302
+ itemHeight={itemHeight}
303
+ textStyle={textStyle}
304
+ textProps={textProps}
305
+ onItemLayout={onItemLayout}
306
+ />)
302
307
  })
303
308
 
304
309
  const renderScollView = () => {
@@ -320,8 +325,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
320
325
  onScrollEndDrag,
321
326
  onMomentumScrollBegin,
322
327
  onMomentumScrollEnd,
323
- onContentSizeChange,
324
- contentContainerStyle
328
+ contentContainerStyle,
329
+ contentOffset: { x: 0, y: initialContentOffsetY }
325
330
  }) as React.ComponentProps<typeof Reanimated.ScrollView>
326
331
 
327
332
  return createElement(
@@ -351,9 +356,9 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
351
356
 
352
357
  return (
353
358
  <View style={[styles.wrapper, normalStyle]}>
354
- {renderScollView()}
355
- {renderMask()}
356
- {renderIndicator()}
359
+ {renderScollView()}
360
+ {renderMask()}
361
+ {renderIndicator()}
357
362
  </View>
358
363
  )
359
364
  })
@@ -1,6 +1,6 @@
1
- import React, { useEffect } from 'react'
1
+ import React, { useMemo } from 'react'
2
2
  import { LayoutChangeEvent } from 'react-native'
3
- import Reanimated, { Extrapolation, interpolate, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
3
+ import Reanimated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated'
4
4
  import { extendObject } from '../utils'
5
5
  import { createFaces } from './pickerViewFaces'
6
6
  import { usePickerViewColumnAnimationContext, usePickerViewStyleContext } from '../mpx-picker-view/pickerVIewContext'
@@ -28,20 +28,16 @@ const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
28
28
  }) => {
29
29
  const textStyleFromAncestor = usePickerViewStyleContext()
30
30
  const offsetYShared = usePickerViewColumnAnimationContext()
31
- const facesShared = useSharedValue(createFaces(itemHeight, visibleCount))
32
-
33
- useEffect(() => {
34
- facesShared.value = createFaces(itemHeight, visibleCount)
35
- }, [itemHeight])
31
+ const facesShared = useMemo(() => createFaces(itemHeight, visibleCount), [itemHeight, visibleCount])
36
32
 
37
33
  const animatedStyles = useAnimatedStyle(() => {
38
- const inputRange = facesShared.value.map((f) => itemHeight * (index + f.index))
34
+ const inputRange = facesShared.map((f) => itemHeight * (index + f.index))
39
35
  return {
40
- opacity: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.opacity), Extrapolation.CLAMP),
36
+ opacity: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.opacity), Extrapolation.CLAMP),
41
37
  transform: [
42
- { translateY: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.offsetY), Extrapolation.EXTEND) },
43
- { rotateX: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
44
- { scale: interpolate(offsetYShared.value, inputRange, facesShared.value.map((x) => x.scale), Extrapolation.EXTEND) }
38
+ { translateY: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.offsetY), Extrapolation.EXTEND) },
39
+ { rotateX: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.deg), Extrapolation.CLAMP) + 'deg' },
40
+ { scale: interpolate(offsetYShared.value, inputRange, facesShared.map((x) => x.scale), Extrapolation.EXTEND) }
45
41
  ]
46
42
  }
47
43
  })
@@ -0,0 +1,55 @@
1
+ import React from 'react'
2
+ import { LayoutChangeEvent, View } from 'react-native'
3
+ import { extendObject } from '../utils'
4
+ import { usePickerViewStyleContext } from '../mpx-picker-view/pickerVIewContext'
5
+
6
+ interface PickerColumnItemProps {
7
+ item: React.ReactElement
8
+ index: number
9
+ itemHeight: number
10
+ itemWidth?: number | '100%'
11
+ textStyle: Record<string, any>
12
+ textProps?: any
13
+ onItemLayout?: (e: LayoutChangeEvent) => void
14
+ }
15
+
16
+ const PickerViewColumnItem: React.FC<PickerColumnItemProps> = ({
17
+ item,
18
+ index,
19
+ itemHeight,
20
+ itemWidth = '100%',
21
+ textStyle,
22
+ textProps,
23
+ onItemLayout
24
+ }) => {
25
+ const textStyleFromAncestor = usePickerViewStyleContext()
26
+ const strKey = `picker-column-item-${index}`
27
+ const restProps = index === 0 ? { onLayout: onItemLayout } : {}
28
+ const itemProps = extendObject(
29
+ {
30
+ style: extendObject(
31
+ { height: itemHeight, width: '100%' },
32
+ textStyleFromAncestor,
33
+ textStyle,
34
+ item.props.style
35
+ )
36
+ },
37
+ textProps,
38
+ restProps
39
+ )
40
+ const realItem = React.cloneElement(item, itemProps)
41
+
42
+ return (
43
+ <View
44
+ key={strKey}
45
+ style={[
46
+ { height: itemHeight, width: itemWidth, pointerEvents: 'none' }
47
+ ]}
48
+ >
49
+ {realItem}
50
+ </View>
51
+ )
52
+ }
53
+
54
+ PickerViewColumnItem.displayName = 'MpxPickerViewColumnItem'
55
+ export default PickerViewColumnItem
@@ -1,19 +1,25 @@
1
1
  import { ReactNode, useContext, useEffect, useRef } from 'react'
2
- import { PortalContext, RouteContext, VarContext } from '../context'
2
+ import { PortalContext, ProviderContext, RouteContext, VarContext } from '../context'
3
3
  import PortalHost, { portal } from './portal-host'
4
4
 
5
5
  export type PortalProps = {
6
6
  children?: ReactNode
7
7
  }
8
8
 
9
- const Portal = ({ children }:PortalProps): null => {
9
+ const Portal = ({ children }: PortalProps): null => {
10
10
  const manager = useContext(PortalContext)
11
11
  const keyRef = useRef<any>(null)
12
12
  const { pageId } = useContext(RouteContext) || {}
13
13
  const varContext = useContext(VarContext)
14
+ const parentProvides = useContext(ProviderContext)
15
+
14
16
  if (varContext) {
15
17
  children = (<VarContext.Provider value={varContext} key='varContextWrap'>{children}</VarContext.Provider>)
16
18
  }
19
+ if (parentProvides) {
20
+ children = (<ProviderContext.Provider value={parentProvides} key='providerContextWrap'>{children}</ProviderContext.Provider>)
21
+ }
22
+
17
23
  useEffect(() => {
18
24
  manager.update(keyRef.current, children)
19
25
  }, [children])
@@ -130,6 +130,6 @@ const _RichText = forwardRef<HandlerRef<View, _RichTextProps>, _RichTextProps>((
130
130
  return finalComponent
131
131
  })
132
132
 
133
- _RichText.displayName = 'mpx-rich-text'
133
+ _RichText.displayName = 'MpxRichText'
134
134
 
135
135
  export default _RichText
@@ -159,9 +159,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
159
159
  const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
160
160
  const waitForHandlers = flatGesture(waitFor)
161
161
 
162
- const snapScrollTop = useRef(0)
163
- const snapScrollLeft = useRef(0)
164
-
165
162
  const [refreshing, setRefreshing] = useState(false)
166
163
 
167
164
  const [enableScroll, setEnableScroll] = useState(true)
@@ -268,16 +265,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
268
265
  warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion')
269
266
  }
270
267
  useEffect(() => {
271
- if (
272
- snapScrollTop.current !== scrollTop || snapScrollLeft.current !== scrollLeft
273
- ) {
274
- initialTimeout.current = setTimeout(() => {
275
- scrollToOffset(scrollLeft, scrollTop)
276
- }, 0)
277
-
278
- return () => {
279
- initialTimeout.current && clearTimeout(initialTimeout.current)
280
- }
268
+ initialTimeout.current = setTimeout(() => {
269
+ scrollToOffset(scrollLeft, scrollTop)
270
+ }, 0)
271
+
272
+ return () => {
273
+ initialTimeout.current && clearTimeout(initialTimeout.current)
281
274
  }
282
275
  }, [scrollTop, scrollLeft])
283
276
 
@@ -481,10 +474,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
481
474
  function scrollToOffset (x = 0, y = 0, animated = scrollWithAnimation) {
482
475
  if (scrollViewRef.current) {
483
476
  scrollViewRef.current.scrollTo({ x, y, animated })
484
- scrollOptions.current.scrollLeft = x
485
- scrollOptions.current.scrollTop = y
486
- snapScrollLeft.current = x
487
- snapScrollTop.current = y
488
477
  }
489
478
  }
490
479