@wordpress/components 25.14.0 → 25.15.1-next.79a6196f.0

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 (568) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/CONTRIBUTING.md +57 -115
  3. package/LICENSE.md +1 -1
  4. package/build/base-control/index.js +17 -13
  5. package/build/base-control/index.js.map +1 -1
  6. package/build/border-box-control/border-box-control-linked-button/component.js +1 -1
  7. package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  8. package/build/border-control/border-control-style-picker/component.js +1 -1
  9. package/build/border-control/border-control-style-picker/component.js.map +1 -1
  10. package/build/box-control/index.js +1 -1
  11. package/build/box-control/index.js.map +1 -1
  12. package/build/box-control/linked-button.js +1 -1
  13. package/build/box-control/linked-button.js.map +1 -1
  14. package/build/button/index.js +1 -1
  15. package/build/button/index.js.map +1 -1
  16. package/build/color-palette/index.native.js +11 -7
  17. package/build/color-palette/index.native.js.map +1 -1
  18. package/build/color-picker/color-copy-button.js +1 -1
  19. package/build/color-picker/color-copy-button.js.map +1 -1
  20. package/build/context/wordpress-component.js.map +1 -1
  21. package/build/custom-select-control-v2/index.js +11 -10
  22. package/build/custom-select-control-v2/index.js.map +1 -1
  23. package/build/date-time/date/styles.js +8 -8
  24. package/build/date-time/date/styles.js.map +1 -1
  25. package/build/dropdown-menu-v2/index.js +205 -159
  26. package/build/dropdown-menu-v2/index.js.map +1 -1
  27. package/build/dropdown-menu-v2/styles.js +86 -77
  28. package/build/dropdown-menu-v2/styles.js.map +1 -1
  29. package/build/dropdown-menu-v2/types.js.map +1 -1
  30. package/build/duotone-picker/duotone-picker.js +4 -3
  31. package/build/duotone-picker/duotone-picker.js.map +1 -1
  32. package/build/font-size-picker/index.js +4 -2
  33. package/build/font-size-picker/index.js.map +1 -1
  34. package/build/font-size-picker/index.native.js +6 -3
  35. package/build/font-size-picker/index.native.js.map +1 -1
  36. package/build/form-token-field/index.js +10 -5
  37. package/build/form-token-field/index.js.map +1 -1
  38. package/build/form-token-field/token.js +1 -0
  39. package/build/form-token-field/token.js.map +1 -1
  40. package/build/gradient-picker/index.js +3 -2
  41. package/build/gradient-picker/index.js.map +1 -1
  42. package/build/index.native.js +20 -3
  43. package/build/index.native.js.map +1 -1
  44. package/build/input-control/styles/input-control-styles.js +32 -29
  45. package/build/input-control/styles/input-control-styles.js.map +1 -1
  46. package/build/input-control/types.js.map +1 -1
  47. package/build/lock-unlock.js +18 -0
  48. package/build/lock-unlock.js.map +1 -0
  49. package/build/mobile/bottom-sheet/index.native.js +8 -0
  50. package/build/mobile/bottom-sheet/index.native.js.map +1 -1
  51. package/build/mobile/color-settings/palette.screen.native.js +8 -4
  52. package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
  53. package/build/mobile/global-styles-context/utils.native.js +26 -13
  54. package/build/mobile/global-styles-context/utils.native.js.map +1 -1
  55. package/build/mobile/image/constants.js +12 -0
  56. package/build/mobile/image/constants.js.map +1 -0
  57. package/build/mobile/image/index.native.js +26 -18
  58. package/build/mobile/image/index.native.js.map +1 -1
  59. package/build/mobile/keyboard-aware-flat-list/index.android.js +40 -8
  60. package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  61. package/build/mobile/keyboard-aware-flat-list/index.ios.js +44 -68
  62. package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  63. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +39 -0
  64. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js.map +1 -0
  65. package/build/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +22 -29
  66. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -0
  67. package/build/mobile/keyboard-aware-flat-list/use-scroll.native.js +93 -0
  68. package/build/mobile/keyboard-aware-flat-list/use-scroll.native.js.map +1 -0
  69. package/build/mobile/utils/get-px-from-css-unit.native.js +302 -0
  70. package/build/mobile/utils/get-px-from-css-unit.native.js.map +1 -0
  71. package/build/modal/index.js +18 -13
  72. package/build/modal/index.js.map +1 -1
  73. package/build/navigation/menu/menu-title.js +1 -1
  74. package/build/navigation/menu/menu-title.js.map +1 -1
  75. package/build/navigator/navigator-provider/component.js +13 -15
  76. package/build/navigator/navigator-provider/component.js.map +1 -1
  77. package/build/navigator/navigator-screen/component.js +23 -63
  78. package/build/navigator/navigator-screen/component.js.map +1 -1
  79. package/build/navigator/styles.js +52 -0
  80. package/build/navigator/styles.js.map +1 -0
  81. package/build/number-control/index.js +4 -8
  82. package/build/number-control/index.js.map +1 -1
  83. package/build/number-control/types.js.map +1 -1
  84. package/build/palette-edit/index.js +15 -54
  85. package/build/palette-edit/index.js.map +1 -1
  86. package/build/private-apis.js +11 -26
  87. package/build/private-apis.js.map +1 -1
  88. package/build/private-apis.native.js +21 -0
  89. package/build/private-apis.native.js.map +1 -0
  90. package/build/radio-control/index.js +1 -0
  91. package/build/radio-control/index.js.map +1 -1
  92. package/build/range-control/index.js +1 -1
  93. package/build/range-control/index.js.map +1 -1
  94. package/build/select-control/styles/select-control-styles.js +15 -25
  95. package/build/select-control/styles/select-control-styles.js.map +1 -1
  96. package/build/slot-fill/index.js +3 -2
  97. package/build/slot-fill/index.js.map +1 -1
  98. package/build/slot-fill/types.js.map +1 -1
  99. package/build/snackbar/types.js.map +1 -1
  100. package/build/tabs/styles.js +3 -3
  101. package/build/tabs/styles.js.map +1 -1
  102. package/build/tabs/tabpanel.js +9 -7
  103. package/build/tabs/tabpanel.js.map +1 -1
  104. package/build/toggle-group-control/toggle-group-control/component.js +4 -4
  105. package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
  106. package/build/toggle-group-control/toggle-group-control/styles.js +29 -15
  107. package/build/toggle-group-control/toggle-group-control/styles.js.map +1 -1
  108. package/build/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
  109. package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  110. package/build/tools-panel/tools-panel/component.js +3 -1
  111. package/build/tools-panel/tools-panel/component.js.map +1 -1
  112. package/build/tools-panel/tools-panel-header/component.js +9 -8
  113. package/build/tools-panel/tools-panel-header/component.js.map +1 -1
  114. package/build/tools-panel/types.js.map +1 -1
  115. package/build/tooltip/index.js +34 -10
  116. package/build/tooltip/index.js.map +1 -1
  117. package/build/tooltip/types.js.map +1 -1
  118. package/build/truncate/hook.js +10 -4
  119. package/build/truncate/hook.js.map +1 -1
  120. package/build/truncate/types.js.map +1 -1
  121. package/build/unit-control/index.js +1 -1
  122. package/build/unit-control/index.js.map +1 -1
  123. package/build/utils/strings.js +34 -3
  124. package/build/utils/strings.js.map +1 -1
  125. package/build-module/base-control/index.js +16 -12
  126. package/build-module/base-control/index.js.map +1 -1
  127. package/build-module/border-box-control/border-box-control-linked-button/component.js +1 -1
  128. package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  129. package/build-module/border-control/border-control-style-picker/component.js +1 -1
  130. package/build-module/border-control/border-control-style-picker/component.js.map +1 -1
  131. package/build-module/box-control/index.js +1 -1
  132. package/build-module/box-control/index.js.map +1 -1
  133. package/build-module/box-control/linked-button.js +1 -1
  134. package/build-module/box-control/linked-button.js.map +1 -1
  135. package/build-module/button/index.js +1 -1
  136. package/build-module/button/index.js.map +1 -1
  137. package/build-module/color-palette/index.native.js +11 -7
  138. package/build-module/color-palette/index.native.js.map +1 -1
  139. package/build-module/color-picker/color-copy-button.js +1 -1
  140. package/build-module/color-picker/color-copy-button.js.map +1 -1
  141. package/build-module/context/wordpress-component.js.map +1 -1
  142. package/build-module/custom-select-control-v2/index.js +11 -10
  143. package/build-module/custom-select-control-v2/index.js.map +1 -1
  144. package/build-module/date-time/date/styles.js +8 -8
  145. package/build-module/date-time/date/styles.js.map +1 -1
  146. package/build-module/dropdown-menu-v2/index.js +201 -154
  147. package/build-module/dropdown-menu-v2/index.js.map +1 -1
  148. package/build-module/dropdown-menu-v2/styles.js +68 -61
  149. package/build-module/dropdown-menu-v2/styles.js.map +1 -1
  150. package/build-module/dropdown-menu-v2/types.js.map +1 -1
  151. package/build-module/duotone-picker/duotone-picker.js +4 -3
  152. package/build-module/duotone-picker/duotone-picker.js.map +1 -1
  153. package/build-module/font-size-picker/index.js +4 -2
  154. package/build-module/font-size-picker/index.js.map +1 -1
  155. package/build-module/font-size-picker/index.native.js +5 -2
  156. package/build-module/font-size-picker/index.native.js.map +1 -1
  157. package/build-module/form-token-field/index.js +10 -5
  158. package/build-module/form-token-field/index.js.map +1 -1
  159. package/build-module/form-token-field/token.js +1 -0
  160. package/build-module/form-token-field/token.js.map +1 -1
  161. package/build-module/gradient-picker/index.js +3 -2
  162. package/build-module/gradient-picker/index.js.map +1 -1
  163. package/build-module/index.native.js +6 -1
  164. package/build-module/index.native.js.map +1 -1
  165. package/build-module/input-control/styles/input-control-styles.js +31 -29
  166. package/build-module/input-control/styles/input-control-styles.js.map +1 -1
  167. package/build-module/input-control/types.js.map +1 -1
  168. package/build-module/lock-unlock.js +9 -0
  169. package/build-module/lock-unlock.js.map +1 -0
  170. package/build-module/mobile/bottom-sheet/index.native.js +9 -1
  171. package/build-module/mobile/bottom-sheet/index.native.js.map +1 -1
  172. package/build-module/mobile/color-settings/palette.screen.native.js +8 -4
  173. package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
  174. package/build-module/mobile/global-styles-context/utils.native.js +25 -13
  175. package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
  176. package/build-module/mobile/image/constants.js +5 -0
  177. package/build-module/mobile/image/constants.js.map +1 -0
  178. package/build-module/mobile/image/index.native.js +25 -16
  179. package/build-module/mobile/image/index.native.js.map +1 -1
  180. package/build-module/mobile/keyboard-aware-flat-list/index.android.js +40 -6
  181. package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  182. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +46 -68
  183. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  184. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +33 -0
  185. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js.map +1 -0
  186. package/build-module/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +21 -27
  187. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -0
  188. package/build-module/mobile/keyboard-aware-flat-list/use-scroll.native.js +86 -0
  189. package/build-module/mobile/keyboard-aware-flat-list/use-scroll.native.js.map +1 -0
  190. package/build-module/mobile/utils/get-px-from-css-unit.native.js +294 -0
  191. package/build-module/mobile/utils/get-px-from-css-unit.native.js.map +1 -0
  192. package/build-module/modal/index.js +18 -13
  193. package/build-module/modal/index.js.map +1 -1
  194. package/build-module/navigation/menu/menu-title.js +1 -1
  195. package/build-module/navigation/menu/menu-title.js.map +1 -1
  196. package/build-module/navigator/navigator-provider/component.js +3 -16
  197. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  198. package/build-module/navigator/navigator-screen/component.js +16 -70
  199. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  200. package/build-module/navigator/styles.js +47 -0
  201. package/build-module/navigator/styles.js.map +1 -0
  202. package/build-module/number-control/index.js +4 -8
  203. package/build-module/number-control/index.js.map +1 -1
  204. package/build-module/number-control/types.js.map +1 -1
  205. package/build-module/palette-edit/index.js +15 -51
  206. package/build-module/palette-edit/index.js.map +1 -1
  207. package/build-module/private-apis.js +10 -23
  208. package/build-module/private-apis.js.map +1 -1
  209. package/build-module/private-apis.native.js +14 -0
  210. package/build-module/private-apis.native.js.map +1 -0
  211. package/build-module/radio-control/index.js +1 -0
  212. package/build-module/radio-control/index.js.map +1 -1
  213. package/build-module/range-control/index.js +1 -1
  214. package/build-module/range-control/index.js.map +1 -1
  215. package/build-module/select-control/styles/select-control-styles.js +15 -25
  216. package/build-module/select-control/styles/select-control-styles.js.map +1 -1
  217. package/build-module/slot-fill/index.js +3 -2
  218. package/build-module/slot-fill/index.js.map +1 -1
  219. package/build-module/slot-fill/types.js.map +1 -1
  220. package/build-module/snackbar/types.js.map +1 -1
  221. package/build-module/tabs/styles.js +3 -3
  222. package/build-module/tabs/styles.js.map +1 -1
  223. package/build-module/tabs/tabpanel.js +9 -7
  224. package/build-module/tabs/tabpanel.js.map +1 -1
  225. package/build-module/toggle-group-control/toggle-group-control/component.js +4 -4
  226. package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
  227. package/build-module/toggle-group-control/toggle-group-control/styles.js +29 -15
  228. package/build-module/toggle-group-control/toggle-group-control/styles.js.map +1 -1
  229. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
  230. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  231. package/build-module/tools-panel/tools-panel/component.js +3 -1
  232. package/build-module/tools-panel/tools-panel/component.js.map +1 -1
  233. package/build-module/tools-panel/tools-panel-header/component.js +9 -8
  234. package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
  235. package/build-module/tools-panel/types.js.map +1 -1
  236. package/build-module/tooltip/index.js +34 -12
  237. package/build-module/tooltip/index.js.map +1 -1
  238. package/build-module/tooltip/types.js.map +1 -1
  239. package/build-module/truncate/hook.js +10 -4
  240. package/build-module/truncate/hook.js.map +1 -1
  241. package/build-module/truncate/types.js.map +1 -1
  242. package/build-module/unit-control/index.js +1 -1
  243. package/build-module/unit-control/index.js.map +1 -1
  244. package/build-module/utils/strings.js +32 -2
  245. package/build-module/utils/strings.js.map +1 -1
  246. package/build-style/style-rtl.css +29 -5
  247. package/build-style/style.css +29 -5
  248. package/build-types/base-control/index.d.ts +3 -27
  249. package/build-types/base-control/index.d.ts.map +1 -1
  250. package/build-types/base-control/stories/index.story.d.ts +4 -1
  251. package/build-types/base-control/stories/index.story.d.ts.map +1 -1
  252. package/build-types/border-box-control/border-box-control/hook.d.ts +4 -4
  253. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +6 -6
  254. package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +4 -4
  255. package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +4 -4
  256. package/build-types/border-box-control/stories/index.story.d.ts +1 -1
  257. package/build-types/border-control/border-control/hook.d.ts +4 -4
  258. package/build-types/border-control/border-control-dropdown/hook.d.ts +4 -4
  259. package/build-types/border-control/border-control-style-picker/hook.d.ts +4 -4
  260. package/build-types/border-control/stories/index.story.d.ts +6 -6
  261. package/build-types/box-control/stories/index.story.d.ts +42 -42
  262. package/build-types/box-control/styles/box-control-styles.d.ts +1 -1
  263. package/build-types/button/deprecated.d.ts +3 -3
  264. package/build-types/card/card/hook.d.ts +4 -4
  265. package/build-types/card/card-body/hook.d.ts +4 -4
  266. package/build-types/card/card-divider/hook.d.ts +4 -4
  267. package/build-types/card/card-footer/hook.d.ts +4 -4
  268. package/build-types/card/card-header/hook.d.ts +4 -4
  269. package/build-types/card/card-media/hook.d.ts +4 -4
  270. package/build-types/color-palette/styles.d.ts +2 -2
  271. package/build-types/color-picker/component.d.ts +2 -2
  272. package/build-types/color-picker/stories/index.story.d.ts +1 -1
  273. package/build-types/color-picker/stories/index.story.d.ts.map +1 -1
  274. package/build-types/color-picker/styles.d.ts +3 -3
  275. package/build-types/composite/test/index.d.ts.map +1 -0
  276. package/build-types/context/wordpress-component.d.ts +3 -3
  277. package/build-types/context/wordpress-component.d.ts.map +1 -1
  278. package/build-types/custom-select-control-v2/index.d.ts +3 -2
  279. package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
  280. package/build-types/custom-select-control-v2/stories/index.story.d.ts +4 -3
  281. package/build-types/custom-select-control-v2/stories/index.story.d.ts.map +1 -1
  282. package/build-types/date-time/date/styles.d.ts +3 -3
  283. package/build-types/date-time/date-time/styles.d.ts +1 -1
  284. package/build-types/date-time/time/styles.d.ts +4 -4
  285. package/build-types/dropdown/index.d.ts +1 -1
  286. package/build-types/dropdown/index.d.ts.map +1 -1
  287. package/build-types/dropdown/stories/index.story.d.ts +3 -3
  288. package/build-types/dropdown/stories/index.story.d.ts.map +1 -1
  289. package/build-types/dropdown-menu/index.d.ts +1 -1
  290. package/build-types/dropdown-menu/index.d.ts.map +1 -1
  291. package/build-types/dropdown-menu/stories/index.story.d.ts +2 -2
  292. package/build-types/dropdown-menu/stories/index.story.d.ts.map +1 -1
  293. package/build-types/dropdown-menu-v2/index.d.ts +18 -15
  294. package/build-types/dropdown-menu-v2/index.d.ts.map +1 -1
  295. package/build-types/dropdown-menu-v2/stories/index.story.d.ts +7 -2
  296. package/build-types/dropdown-menu-v2/stories/index.story.d.ts.map +1 -1
  297. package/build-types/dropdown-menu-v2/styles.d.ts +77 -23
  298. package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -1
  299. package/build-types/dropdown-menu-v2/types.d.ts +89 -173
  300. package/build-types/dropdown-menu-v2/types.d.ts.map +1 -1
  301. package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -1
  302. package/build-types/elevation/hook.d.ts +4 -4
  303. package/build-types/flex/flex/hook.d.ts +4 -4
  304. package/build-types/flex/flex-block/hook.d.ts +4 -4
  305. package/build-types/flex/flex-item/hook.d.ts +4 -4
  306. package/build-types/focal-point-picker/stories/index.story.d.ts +4 -4
  307. package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +1 -1
  308. package/build-types/font-size-picker/index.d.ts.map +1 -1
  309. package/build-types/font-size-picker/styles.d.ts +1 -1
  310. package/build-types/form-token-field/index.d.ts.map +1 -1
  311. package/build-types/form-token-field/token.d.ts.map +1 -1
  312. package/build-types/grid/hook.d.ts +4 -4
  313. package/build-types/h-stack/hook.d.ts +4 -4
  314. package/build-types/heading/component.d.ts +1 -1
  315. package/build-types/heading/hook.d.ts +4 -4
  316. package/build-types/input-control/styles/input-control-styles.d.ts +11 -0
  317. package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
  318. package/build-types/input-control/types.d.ts +1 -1
  319. package/build-types/input-control/types.d.ts.map +1 -1
  320. package/build-types/item-group/item/hook.d.ts +4 -4
  321. package/build-types/item-group/item-group/hook.d.ts +4 -4
  322. package/build-types/lock-unlock.d.ts +3 -0
  323. package/build-types/lock-unlock.d.ts.map +1 -0
  324. package/build-types/menu-item/index.d.ts +1 -1
  325. package/build-types/menu-item/stories/index.story.d.ts +4 -4
  326. package/build-types/mobile/image/constants.d.ts +5 -0
  327. package/build-types/mobile/image/constants.d.ts.map +1 -0
  328. package/build-types/modal/index.d.ts.map +1 -1
  329. package/build-types/navigation/styles/navigation-styles.d.ts +3 -3
  330. package/build-types/navigator/navigator-back-button/hook.d.ts +6 -6
  331. package/build-types/navigator/navigator-button/hook.d.ts +6 -6
  332. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  333. package/build-types/navigator/navigator-screen/component.d.ts +1 -7
  334. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  335. package/build-types/navigator/styles.d.ts +9 -0
  336. package/build-types/navigator/styles.d.ts.map +1 -0
  337. package/build-types/number-control/index.d.ts +1 -1
  338. package/build-types/number-control/index.d.ts.map +1 -1
  339. package/build-types/number-control/stories/index.story.d.ts +1 -1
  340. package/build-types/number-control/types.d.ts +1 -1
  341. package/build-types/palette-edit/index.d.ts +3 -8
  342. package/build-types/palette-edit/index.d.ts.map +1 -1
  343. package/build-types/palette-edit/styles.d.ts +3 -3
  344. package/build-types/popover/index.d.ts +1 -1
  345. package/build-types/popover/index.d.ts.map +1 -1
  346. package/build-types/popover/stories/e2e/index.story.d.ts +1 -1
  347. package/build-types/private-apis.d.ts +0 -1
  348. package/build-types/private-apis.d.ts.map +1 -1
  349. package/build-types/radio-control/index.d.ts.map +1 -1
  350. package/build-types/range-control/index.d.ts +1 -1
  351. package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
  352. package/build-types/resizable-box/index.d.ts +1 -1
  353. package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
  354. package/build-types/resizable-box/stories/index.story.d.ts +2 -2
  355. package/build-types/scrollable/hook.d.ts +4 -4
  356. package/build-types/search-control/index.d.ts +1 -1
  357. package/build-types/search-control/stories/index.story.d.ts +2 -2
  358. package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
  359. package/build-types/slot-fill/index.d.ts +1 -1
  360. package/build-types/slot-fill/index.d.ts.map +1 -1
  361. package/build-types/slot-fill/types.d.ts +4 -0
  362. package/build-types/slot-fill/types.d.ts.map +1 -1
  363. package/build-types/snackbar/index.d.ts +2 -2
  364. package/build-types/snackbar/stories/index.story.d.ts +0 -3
  365. package/build-types/snackbar/stories/index.story.d.ts.map +1 -1
  366. package/build-types/snackbar/types.d.ts +1 -1
  367. package/build-types/snackbar/types.d.ts.map +1 -1
  368. package/build-types/spacer/hook.d.ts +4 -4
  369. package/build-types/surface/hook.d.ts +4 -4
  370. package/build-types/tabs/styles.d.ts.map +1 -1
  371. package/build-types/tabs/tabpanel.d.ts +1 -1
  372. package/build-types/tabs/tabpanel.d.ts.map +1 -1
  373. package/build-types/text/hook.d.ts +4 -4
  374. package/build-types/text-control/index.d.ts +1 -1
  375. package/build-types/textarea-control/index.d.ts +1 -1
  376. package/build-types/toggle-control/stories/index.story.d.ts +2 -2
  377. package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts +1 -1
  378. package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts +1 -1
  379. package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
  380. package/build-types/toggle-group-control/toggle-group-control/styles.d.ts +2 -2
  381. package/build-types/toggle-group-control/toggle-group-control/styles.d.ts.map +1 -1
  382. package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts +1 -1
  383. package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts +1 -1
  384. package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
  385. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
  386. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +1 -1
  387. package/build-types/toolbar/toolbar-button/index.d.ts +3 -3
  388. package/build-types/tools-panel/tools-panel/component.d.ts.map +1 -1
  389. package/build-types/tools-panel/tools-panel/hook.d.ts +5 -4
  390. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  391. package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
  392. package/build-types/tools-panel/tools-panel-header/hook.d.ts +5 -4
  393. package/build-types/tools-panel/tools-panel-header/hook.d.ts.map +1 -1
  394. package/build-types/tools-panel/tools-panel-item/hook.d.ts +4 -4
  395. package/build-types/tools-panel/types.d.ts +9 -0
  396. package/build-types/tools-panel/types.d.ts.map +1 -1
  397. package/build-types/tooltip/index.d.ts +1 -1
  398. package/build-types/tooltip/index.d.ts.map +1 -1
  399. package/build-types/tooltip/stories/index.story.d.ts +10 -1
  400. package/build-types/tooltip/stories/index.story.d.ts.map +1 -1
  401. package/build-types/tooltip/types.d.ts +3 -0
  402. package/build-types/tooltip/types.d.ts.map +1 -1
  403. package/build-types/truncate/hook.d.ts +5 -5
  404. package/build-types/truncate/hook.d.ts.map +1 -1
  405. package/build-types/truncate/types.d.ts +4 -0
  406. package/build-types/truncate/types.d.ts.map +1 -1
  407. package/build-types/unit-control/index.d.ts +1 -1
  408. package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
  409. package/build-types/utils/strings.d.ts +14 -2
  410. package/build-types/utils/strings.d.ts.map +1 -1
  411. package/build-types/v-stack/hook.d.ts +4 -4
  412. package/build-types/v-stack/stories/index.story.d.ts +1 -1
  413. package/package.json +20 -21
  414. package/src/alignment-matrix-control/test/index.tsx +10 -16
  415. package/src/base-control/index.tsx +21 -16
  416. package/src/border-box-control/border-box-control-linked-button/component.tsx +1 -1
  417. package/src/border-control/border-control-style-picker/component.tsx +1 -1
  418. package/src/box-control/index.tsx +1 -1
  419. package/src/box-control/linked-button.tsx +1 -1
  420. package/src/button/README.md +32 -6
  421. package/src/button/index.tsx +1 -1
  422. package/src/button-group/README.md +0 -6
  423. package/src/card/card/README.md +1 -1
  424. package/src/checkbox-control/README.md +1 -9
  425. package/src/color-palette/index.native.js +18 -7
  426. package/src/color-picker/color-copy-button.tsx +1 -1
  427. package/src/combobox-control/README.md +0 -6
  428. package/src/composite/test/index.tsx +576 -0
  429. package/src/context/wordpress-component.ts +11 -6
  430. package/src/custom-select-control/README.md +0 -6
  431. package/src/custom-select-control-v2/index.tsx +13 -12
  432. package/src/date-time/date/styles.ts +3 -3
  433. package/src/dropdown-menu/README.md +0 -5
  434. package/src/dropdown-menu-v2/README.md +75 -136
  435. package/src/dropdown-menu-v2/index.tsx +321 -231
  436. package/src/dropdown-menu-v2/stories/index.story.tsx +522 -126
  437. package/src/dropdown-menu-v2/styles.ts +226 -151
  438. package/src/dropdown-menu-v2/test/index.tsx +480 -188
  439. package/src/dropdown-menu-v2/types.ts +98 -184
  440. package/src/duotone-picker/duotone-picker.tsx +7 -3
  441. package/src/font-size-picker/index.native.js +8 -2
  442. package/src/font-size-picker/index.tsx +4 -2
  443. package/src/form-toggle/README.md +0 -6
  444. package/src/form-token-field/index.tsx +11 -7
  445. package/src/form-token-field/test/index.tsx +97 -0
  446. package/src/form-token-field/token.tsx +1 -0
  447. package/src/gradient-picker/index.tsx +2 -2
  448. package/src/index.native.js +6 -1
  449. package/src/input-control/styles/input-control-styles.tsx +10 -8
  450. package/src/input-control/types.ts +1 -1
  451. package/src/lock-unlock.js +10 -0
  452. package/src/menu-group/README.md +0 -8
  453. package/src/menu-items-choice/README.md +0 -7
  454. package/src/mobile/bottom-sheet/index.native.js +15 -1
  455. package/src/mobile/color-settings/palette.screen.native.js +7 -5
  456. package/src/mobile/global-styles-context/test/fixtures/theme.native.js +0 -20
  457. package/src/mobile/global-styles-context/utils.native.js +28 -19
  458. package/src/mobile/image/constants.js +1 -0
  459. package/src/mobile/image/index.native.js +55 -18
  460. package/src/mobile/image/style.native.scss +35 -9
  461. package/src/mobile/keyboard-aware-flat-list/index.android.js +50 -5
  462. package/src/mobile/keyboard-aware-flat-list/index.ios.js +65 -91
  463. package/src/mobile/keyboard-aware-flat-list/test/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +27 -25
  464. package/src/mobile/keyboard-aware-flat-list/test/use-scroll.native.js +71 -0
  465. package/src/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +41 -0
  466. package/src/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +22 -27
  467. package/src/mobile/keyboard-aware-flat-list/use-scroll.native.js +100 -0
  468. package/src/mobile/utils/get-px-from-css-unit.native.js +329 -0
  469. package/src/mobile/utils/test/get-px-from-css-unit.native.js +172 -0
  470. package/src/modal/README.md +0 -6
  471. package/src/modal/index.tsx +18 -16
  472. package/src/modal/test/index.tsx +90 -1
  473. package/src/navigation/menu/menu-title.tsx +1 -1
  474. package/src/navigator/navigator-provider/component.tsx +3 -4
  475. package/src/navigator/navigator-screen/component.tsx +15 -93
  476. package/src/navigator/styles.ts +71 -0
  477. package/src/navigator/test/index.tsx +0 -64
  478. package/src/notice/README.md +0 -6
  479. package/src/number-control/README.md +2 -2
  480. package/src/number-control/index.tsx +4 -8
  481. package/src/number-control/types.ts +1 -1
  482. package/src/palette-edit/index.tsx +15 -58
  483. package/src/palette-edit/test/index.tsx +1 -75
  484. package/src/panel/README.md +0 -6
  485. package/src/private-apis.native.js +13 -0
  486. package/src/private-apis.ts +12 -37
  487. package/src/radio-control/README.md +0 -6
  488. package/src/radio-control/index.tsx +4 -1
  489. package/src/radio-control/style.scss +29 -2
  490. package/src/radio-group/README.md +0 -6
  491. package/src/range-control/README.md +1 -9
  492. package/src/range-control/index.tsx +1 -1
  493. package/src/search-control/README.md +0 -6
  494. package/src/select-control/README.md +0 -6
  495. package/src/select-control/styles/select-control-styles.ts +10 -28
  496. package/src/slot-fill/index.tsx +5 -2
  497. package/src/slot-fill/types.ts +5 -0
  498. package/src/snackbar/README.md +0 -6
  499. package/src/snackbar/stories/index.story.tsx +7 -5
  500. package/src/snackbar/style.scss +4 -3
  501. package/src/snackbar/types.ts +2 -1
  502. package/src/spacer/README.md +0 -2
  503. package/src/tab-panel/README.md +0 -5
  504. package/src/tab-panel/test/index.tsx +39 -56
  505. package/src/tabs/styles.ts +7 -1
  506. package/src/tabs/tabpanel.tsx +7 -6
  507. package/src/tabs/test/index.tsx +56 -0
  508. package/src/text-control/README.md +0 -6
  509. package/src/textarea-control/README.md +0 -6
  510. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +12 -16
  511. package/src/toggle-group-control/test/index.tsx +58 -45
  512. package/src/toggle-group-control/toggle-group-control/component.tsx +5 -4
  513. package/src/toggle-group-control/toggle-group-control/styles.ts +13 -19
  514. package/src/toggle-group-control/toggle-group-control-option/README.md +1 -1
  515. package/src/toggle-group-control/toggle-group-control-option-base/README.md +1 -1
  516. package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +3 -2
  517. package/src/toggle-group-control/toggle-group-control-option-icon/README.md +1 -1
  518. package/src/toolbar/toolbar/README.md +0 -6
  519. package/src/tools-panel/test/index.tsx +12 -20
  520. package/src/tools-panel/tools-panel/README.md +7 -0
  521. package/src/tools-panel/tools-panel/component.tsx +2 -0
  522. package/src/tools-panel/tools-panel-header/README.md +7 -0
  523. package/src/tools-panel/tools-panel-header/component.tsx +20 -13
  524. package/src/tools-panel/types.ts +9 -0
  525. package/src/tooltip/README.md +4 -0
  526. package/src/tooltip/index.tsx +48 -10
  527. package/src/tooltip/stories/index.story.tsx +18 -1
  528. package/src/tooltip/test/index.tsx +404 -254
  529. package/src/tooltip/types.ts +4 -0
  530. package/src/tree-grid/README.md +0 -4
  531. package/src/truncate/README.md +8 -0
  532. package/src/truncate/hook.ts +17 -10
  533. package/src/truncate/test/index.tsx +54 -27
  534. package/src/truncate/types.ts +4 -0
  535. package/src/unit-control/index.tsx +1 -1
  536. package/src/utils/strings.ts +30 -2
  537. package/src/utils/test/strings.js +96 -1
  538. package/tsconfig.tsbuildinfo +1 -1
  539. package/build/dropdown-menu-v2-ariakit/index.js +0 -256
  540. package/build/dropdown-menu-v2-ariakit/index.js.map +0 -1
  541. package/build/dropdown-menu-v2-ariakit/styles.js +0 -180
  542. package/build/dropdown-menu-v2-ariakit/styles.js.map +0 -1
  543. package/build/dropdown-menu-v2-ariakit/types.js +0 -6
  544. package/build/dropdown-menu-v2-ariakit/types.js.map +0 -1
  545. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +0 -1
  546. package/build-module/dropdown-menu-v2-ariakit/index.js +0 -237
  547. package/build-module/dropdown-menu-v2-ariakit/index.js.map +0 -1
  548. package/build-module/dropdown-menu-v2-ariakit/styles.js +0 -165
  549. package/build-module/dropdown-menu-v2-ariakit/styles.js.map +0 -1
  550. package/build-module/dropdown-menu-v2-ariakit/types.js +0 -2
  551. package/build-module/dropdown-menu-v2-ariakit/types.js.map +0 -1
  552. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +0 -1
  553. package/build-types/dropdown-menu-v2-ariakit/index.d.ts +0 -20
  554. package/build-types/dropdown-menu-v2-ariakit/index.d.ts.map +0 -1
  555. package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts +0 -16
  556. package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts.map +0 -1
  557. package/build-types/dropdown-menu-v2-ariakit/styles.d.ts +0 -96
  558. package/build-types/dropdown-menu-v2-ariakit/styles.d.ts.map +0 -1
  559. package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts.map +0 -1
  560. package/build-types/dropdown-menu-v2-ariakit/types.d.ts +0 -168
  561. package/build-types/dropdown-menu-v2-ariakit/types.d.ts.map +0 -1
  562. package/src/dropdown-menu-v2-ariakit/README.md +0 -331
  563. package/src/dropdown-menu-v2-ariakit/index.tsx +0 -383
  564. package/src/dropdown-menu-v2-ariakit/stories/index.story.tsx +0 -617
  565. package/src/dropdown-menu-v2-ariakit/styles.ts +0 -345
  566. package/src/dropdown-menu-v2-ariakit/test/index.tsx +0 -1108
  567. package/src/dropdown-menu-v2-ariakit/types.ts +0 -179
  568. /package/build-types/{dropdown-menu-v2-ariakit → composite}/test/index.d.ts +0 -0
@@ -2,139 +2,104 @@
2
2
  * External dependencies
3
3
  */
4
4
 
5
- import { ScrollView, FlatList, useWindowDimensions } from 'react-native';
6
- import Animated, {
7
- useAnimatedScrollHandler,
8
- useSharedValue,
9
- } from 'react-native-reanimated';
5
+ import { ScrollView, FlatList } from 'react-native';
6
+ import Animated from 'react-native-reanimated';
10
7
 
11
8
  /**
12
9
  * WordPress dependencies
13
10
  */
14
- import { useCallback, useEffect, useRef } from '@wordpress/element';
11
+ import {
12
+ useCallback,
13
+ useEffect,
14
+ forwardRef,
15
+ useImperativeHandle,
16
+ } from '@wordpress/element';
15
17
  import { useThrottle } from '@wordpress/compose';
16
18
 
17
19
  /**
18
20
  * Internal dependencies
19
21
  */
22
+ import useScroll from './use-scroll';
20
23
  import useTextInputOffset from './use-text-input-offset';
21
- import useKeyboardOffset from './use-keyboard-offset';
22
- import useScrollToTextInput from './use-scroll-to-text-input';
23
24
  import useTextInputCaretPosition from './use-text-input-caret-position';
24
25
 
26
+ const DEFAULT_FONT_SIZE = 16;
25
27
  const AnimatedScrollView = Animated.createAnimatedComponent( ScrollView );
26
28
 
29
+ /** @typedef {import('@wordpress/element').RefObject} RefObject */
27
30
  /**
28
31
  * React component that provides a FlatList that is aware of the keyboard state and can scroll
29
32
  * to the currently focused TextInput.
30
33
  *
31
- * @param {Object} props Component props.
32
- * @param {number} props.extraScrollHeight Extra scroll height for the content.
33
- * @param {Function} props.innerRef Function to pass the ScrollView ref to the parent component.
34
- * @param {Function} props.onScroll Function to be called when the list is scrolled.
35
- * @param {boolean} props.scrollEnabled Whether the list can be scrolled.
36
- * @param {Object} props.scrollViewStyle Additional style for the ScrollView component.
37
- * @param {boolean} props.shouldPreventAutomaticScroll Whether to prevent scrolling when there's a Keyboard offset set.
38
- * @param {Object} props... Other props to pass to the FlatList component.
34
+ * @param {Object} props Component props.
35
+ * @param {number} props.extraScrollHeight Extra scroll height for the content.
36
+ * @param {Function} props.onScroll Function to be called when the list is scrolled.
37
+ * @param {boolean} props.scrollEnabled Whether the list can be scrolled.
38
+ * @param {Object} props.scrollViewStyle Additional style for the ScrollView component.
39
+ * @param {boolean} props.shouldPreventAutomaticScroll Whether to prevent scrolling when there's a Keyboard offset set.
40
+ * @param {Object} props... Other props to pass to the FlatList component.
41
+ * @param {RefObject} ref
39
42
  * @return {Component} KeyboardAwareFlatList component.
40
43
  */
41
- export const KeyboardAwareFlatList = ( {
42
- extraScrollHeight,
43
- innerRef,
44
- onScroll,
45
- scrollEnabled,
46
- scrollViewStyle,
47
- shouldPreventAutomaticScroll,
48
- ...props
49
- } ) => {
50
- const scrollViewRef = useRef();
51
- const scrollViewMeasurements = useRef();
52
- const scrollViewYOffset = useSharedValue( -1 );
53
-
54
- const { height: windowHeight, width: windowWidth } = useWindowDimensions();
55
- const isLandscape = windowWidth >= windowHeight;
56
-
57
- const [ keyboardOffset ] = useKeyboardOffset(
44
+ export const KeyboardAwareFlatList = (
45
+ {
46
+ extraScrollHeight,
47
+ onScroll,
58
48
  scrollEnabled,
59
- shouldPreventAutomaticScroll
60
- );
61
-
62
- const [ currentCaretData ] = useTextInputCaretPosition( scrollEnabled );
49
+ scrollViewStyle,
50
+ shouldPreventAutomaticScroll,
51
+ ...props
52
+ },
53
+ ref
54
+ ) => {
55
+ const {
56
+ scrollViewRef,
57
+ scrollHandler,
58
+ keyboardOffset,
59
+ scrollToSection,
60
+ scrollToElement,
61
+ onContentSizeChange,
62
+ lastScrollTo,
63
+ } = useScroll( {
64
+ scrollEnabled,
65
+ shouldPreventAutomaticScroll,
66
+ extraScrollHeight,
67
+ onScroll,
68
+ onSizeChange,
69
+ } );
63
70
 
64
71
  const [ getTextInputOffset ] = useTextInputOffset(
65
72
  scrollEnabled,
66
73
  scrollViewRef
67
74
  );
68
75
 
69
- const [ scrollToTextInputOffset ] = useScrollToTextInput(
70
- extraScrollHeight,
71
- keyboardOffset,
72
- scrollEnabled,
73
- scrollViewMeasurements,
74
- scrollViewRef,
75
- scrollViewYOffset
76
- );
77
-
78
76
  const onScrollToTextInput = useThrottle(
79
77
  useCallback(
80
78
  async ( caret ) => {
79
+ const { caretHeight = DEFAULT_FONT_SIZE } = caret ?? {};
81
80
  const textInputOffset = await getTextInputOffset( caret );
82
81
  const hasTextInputOffset = textInputOffset !== null;
83
82
 
84
83
  if ( hasTextInputOffset ) {
85
- scrollToTextInputOffset( caret, textInputOffset );
84
+ scrollToSection( textInputOffset, caretHeight );
86
85
  }
87
86
  },
88
- [ getTextInputOffset, scrollToTextInputOffset ]
87
+ [ getTextInputOffset, scrollToSection ]
89
88
  ),
90
89
  200,
91
90
  { leading: false }
92
91
  );
93
92
 
94
- useEffect( () => {
95
- onScrollToTextInput( currentCaretData );
96
- }, [ currentCaretData, onScrollToTextInput ] );
97
-
98
- // When the orientation changes, the ScrollView measurements
99
- // need to be re-calculated.
100
- useEffect( () => {
101
- scrollViewMeasurements.current = null;
102
- }, [ isLandscape ] );
103
-
104
- const scrollHandler = useAnimatedScrollHandler( {
105
- onScroll: ( event ) => {
106
- const { contentOffset } = event;
107
- scrollViewYOffset.value = contentOffset.y;
108
- onScroll( event );
109
- },
110
- } );
111
-
112
- const measureScrollView = useCallback( () => {
113
- if ( scrollViewRef.current ) {
114
- const scrollRef = scrollViewRef.current.getNativeScrollRef();
93
+ const [ currentCaretData ] = useTextInputCaretPosition( scrollEnabled );
115
94
 
116
- scrollRef.measureInWindow( ( _x, y, width, height ) => {
117
- scrollViewMeasurements.current = { y, width, height };
118
- } );
119
- }
120
- }, [] );
95
+ const onSizeChange = useCallback(
96
+ () => onScrollToTextInput( currentCaretData ),
97
+ [ currentCaretData, onScrollToTextInput ]
98
+ );
121
99
 
122
- const onContentSizeChange = useCallback( () => {
100
+ useEffect( () => {
123
101
  onScrollToTextInput( currentCaretData );
124
-
125
- // Sets the first values when the content size changes.
126
- if ( ! scrollViewMeasurements.current ) {
127
- measureScrollView();
128
- }
129
- }, [ measureScrollView, onScrollToTextInput, currentCaretData ] );
130
-
131
- const getRef = useCallback(
132
- ( ref ) => {
133
- scrollViewRef.current = ref;
134
- innerRef( ref );
135
- },
136
- [ innerRef ]
137
- );
102
+ }, [ currentCaretData, onScrollToTextInput ] );
138
103
 
139
104
  // Adds content insets when the keyboard is opened to have
140
105
  // extra padding at the bottom.
@@ -142,6 +107,15 @@ export const KeyboardAwareFlatList = ( {
142
107
 
143
108
  const style = [ { flex: 1 }, scrollViewStyle ];
144
109
 
110
+ useImperativeHandle( ref, () => {
111
+ return {
112
+ scrollViewRef: scrollViewRef.current,
113
+ scrollToSection,
114
+ scrollToElement,
115
+ lastScrollTo,
116
+ };
117
+ } );
118
+
145
119
  return (
146
120
  <AnimatedScrollView
147
121
  automaticallyAdjustContentInsets={ false }
@@ -149,7 +123,7 @@ export const KeyboardAwareFlatList = ( {
149
123
  keyboardShouldPersistTaps="handled"
150
124
  onContentSizeChange={ onContentSizeChange }
151
125
  onScroll={ scrollHandler }
152
- ref={ getRef }
126
+ ref={ scrollViewRef }
153
127
  scrollEnabled={ scrollEnabled }
154
128
  scrollEventThrottle={ 16 }
155
129
  style={ style }
@@ -159,4 +133,4 @@ export const KeyboardAwareFlatList = ( {
159
133
  );
160
134
  };
161
135
 
162
- export default KeyboardAwareFlatList;
136
+ export default forwardRef( KeyboardAwareFlatList );
@@ -7,22 +7,23 @@ import { renderHook } from '@testing-library/react-native';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
- import useScrollToTextInput from '../use-scroll-to-text-input';
10
+ import useScrollToSection from '../use-scroll-to-section';
11
11
 
12
- describe( 'useScrollToTextInput', () => {
13
- it( 'scrolls up to the current TextInput offset', () => {
12
+ describe( 'useScrollToSection', () => {
13
+ it( 'scrolls up to the section', () => {
14
14
  // Arrange
15
- const currentCaretData = { caretHeight: 10 };
15
+ const sectionY = 50;
16
+ const sectionHeight = 10;
17
+
16
18
  const extraScrollHeight = 50;
17
19
  const keyboardOffset = 100;
18
20
  const scrollEnabled = true;
19
21
  const scrollViewRef = { current: { scrollTo: jest.fn() } };
20
22
  const scrollViewMeasurements = { current: { height: 600 } };
21
23
  const scrollViewYOffset = { value: 150 };
22
- const textInputOffset = 50;
23
24
 
24
25
  const { result } = renderHook( () =>
25
- useScrollToTextInput(
26
+ useScrollToSection(
26
27
  extraScrollHeight,
27
28
  keyboardOffset,
28
29
  scrollEnabled,
@@ -33,28 +34,29 @@ describe( 'useScrollToTextInput', () => {
33
34
  );
34
35
 
35
36
  // Act
36
- result.current[ 0 ]( currentCaretData, textInputOffset );
37
+ result.current[ 0 ]( sectionY, sectionHeight );
37
38
 
38
39
  // Assert
39
40
  expect( scrollViewRef.current.scrollTo ).toHaveBeenCalledWith( {
40
- y: textInputOffset,
41
+ y: sectionY,
41
42
  animated: true,
42
43
  } );
43
44
  } );
44
45
 
45
- it( 'scrolls down to the current TextInput offset', () => {
46
+ it( 'scrolls down to the section', () => {
46
47
  // Arrange
47
- const currentCaretData = { caretHeight: 10 };
48
+ const sectionY = 750;
49
+ const sectionHeight = 10;
50
+
48
51
  const extraScrollHeight = 50;
49
52
  const keyboardOffset = 100;
50
53
  const scrollEnabled = true;
51
54
  const scrollViewRef = { current: { scrollTo: jest.fn() } };
52
55
  const scrollViewMeasurements = { current: { height: 600 } };
53
56
  const scrollViewYOffset = { value: 250 };
54
- const textInputOffset = 750;
55
57
 
56
58
  const { result } = renderHook( () =>
57
- useScrollToTextInput(
59
+ useScrollToSection(
58
60
  extraScrollHeight,
59
61
  keyboardOffset,
60
62
  scrollEnabled,
@@ -65,15 +67,13 @@ describe( 'useScrollToTextInput', () => {
65
67
  );
66
68
 
67
69
  // Act
68
- result.current[ 0 ]( currentCaretData, textInputOffset );
70
+ result.current[ 0 ]( sectionY, sectionHeight );
69
71
 
70
72
  // Assert
71
73
  const expectedYOffset =
72
- textInputOffset -
74
+ sectionY -
73
75
  ( scrollViewMeasurements.current.height -
74
- ( keyboardOffset +
75
- extraScrollHeight +
76
- currentCaretData.caretHeight ) );
76
+ ( keyboardOffset + extraScrollHeight + sectionHeight ) );
77
77
  expect( scrollViewRef.current.scrollTo ).toHaveBeenCalledWith( {
78
78
  y: expectedYOffset,
79
79
  animated: true,
@@ -82,17 +82,18 @@ describe( 'useScrollToTextInput', () => {
82
82
 
83
83
  it( 'does not scroll when the ScrollView ref is not available', () => {
84
84
  // Arrange
85
- const currentCaretData = { caretHeight: 10 };
85
+ const sectionY = 50;
86
+ const sectionHeight = 10;
87
+
86
88
  const extraScrollHeight = 50;
87
89
  const keyboardOffset = 100;
88
90
  const scrollEnabled = true;
89
91
  const scrollViewRef = { current: null };
90
92
  const scrollViewMeasurements = { current: { height: 600 } };
91
93
  const scrollViewYOffset = { value: 0 };
92
- const textInputOffset = 50;
93
94
 
94
95
  const { result } = renderHook( () =>
95
- useScrollToTextInput(
96
+ useScrollToSection(
96
97
  extraScrollHeight,
97
98
  keyboardOffset,
98
99
  scrollEnabled,
@@ -103,7 +104,7 @@ describe( 'useScrollToTextInput', () => {
103
104
  );
104
105
 
105
106
  // Act
106
- result.current[ 0 ]( currentCaretData, textInputOffset );
107
+ result.current[ 0 ]( sectionY, sectionHeight );
107
108
 
108
109
  // Assert
109
110
  expect( scrollViewRef.current ).toBeNull();
@@ -111,17 +112,18 @@ describe( 'useScrollToTextInput', () => {
111
112
 
112
113
  it( 'does not scroll when the scroll is not enabled', () => {
113
114
  // Arrange
114
- const currentCaretData = { caretHeight: 10 };
115
+ const sectionY = 50;
116
+ const sectionHeight = 10;
117
+
115
118
  const extraScrollHeight = 50;
116
119
  const keyboardOffset = 100;
117
120
  const scrollEnabled = false;
118
121
  const scrollViewRef = { current: { scrollTo: jest.fn() } };
119
122
  const scrollViewMeasurements = { current: { height: 600 } };
120
123
  const scrollViewYOffset = { value: 0 };
121
- const textInputOffset = 50;
122
124
 
123
125
  const { result } = renderHook( () =>
124
- useScrollToTextInput(
126
+ useScrollToSection(
125
127
  extraScrollHeight,
126
128
  keyboardOffset,
127
129
  scrollEnabled,
@@ -132,7 +134,7 @@ describe( 'useScrollToTextInput', () => {
132
134
  );
133
135
 
134
136
  // Act
135
- result.current[ 0 ]( currentCaretData, textInputOffset );
137
+ result.current[ 0 ]( sectionY, sectionHeight );
136
138
 
137
139
  // Assert
138
140
  expect( scrollViewRef.current.scrollTo ).not.toHaveBeenCalled();
@@ -0,0 +1,71 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+
5
+ import { renderHook } from 'test/helpers';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import useScroll from '../use-scroll';
11
+
12
+ // Mock Reanimated with default mock
13
+ jest.mock( 'react-native-reanimated', () => ( {
14
+ ...require( 'react-native-reanimated/mock' ),
15
+ useAnimatedScrollHandler: jest.fn( ( args ) => args ),
16
+ } ) );
17
+
18
+ describe( 'useScroll', () => {
19
+ it( 'scrolls using current scroll position', () => {
20
+ const sectionY = 50;
21
+ const sectionHeight = 10;
22
+ const scrollViewMeasurements = { x: 0, y: 0, width: 0, height: 600 };
23
+ const extraScrollHeight = 50;
24
+ const scrollEnabled = true;
25
+ const shouldPreventAutomaticScroll = false;
26
+
27
+ const scrollTo = jest.fn();
28
+ const measureInWindow = jest.fn( ( callback ) =>
29
+ callback( ...Object.values( scrollViewMeasurements ) )
30
+ );
31
+ const scrollRef = { scrollTo, measureInWindow };
32
+ const onScroll = jest.fn();
33
+ const onSizeChange = jest.fn();
34
+
35
+ const { result } = renderHook( () =>
36
+ useScroll( {
37
+ scrollEnabled,
38
+ shouldPreventAutomaticScroll,
39
+ onScroll,
40
+ onSizeChange,
41
+ extraScrollHeight,
42
+ } )
43
+ );
44
+ const {
45
+ scrollViewRef,
46
+ onContentSizeChange,
47
+ scrollHandler,
48
+ scrollToSection,
49
+ } = result.current;
50
+
51
+ // Assign ref
52
+ scrollViewRef.current = scrollRef;
53
+
54
+ // Check content size changes
55
+ onContentSizeChange();
56
+ expect( measureInWindow ).toHaveBeenCalled();
57
+ expect( onSizeChange ).toHaveBeenCalled();
58
+
59
+ // Set up initial scroll offset
60
+ scrollHandler.onScroll( { contentOffset: { y: 150 } } );
61
+
62
+ // Scroll to section
63
+ scrollToSection( sectionY, sectionHeight );
64
+
65
+ // Assert
66
+ expect( scrollTo ).toHaveBeenCalledWith( {
67
+ y: sectionY,
68
+ animated: true,
69
+ } );
70
+ } );
71
+ } );
@@ -0,0 +1,41 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useCallback } from '@wordpress/element';
5
+
6
+ /** @typedef {import('@wordpress/element').RefObject} RefObject */
7
+ /**
8
+ * Hook to scroll to a specified element by taking into account the Keyboard
9
+ * and the Header.
10
+ *
11
+ * @param {RefObject} scrollViewRef Scroll view reference.
12
+ * @param {Function} scrollToSection Function to scroll.
13
+ * @return {Function[]} Function to scroll to an element.
14
+ */
15
+ export default function useScrollToElement( scrollViewRef, scrollToSection ) {
16
+ /**
17
+ * Function to scroll to an element.
18
+ *
19
+ * @param {RefObject} elementRef Ref of the element.
20
+ */
21
+ const scrollToElement = useCallback(
22
+ ( elementRef ) => {
23
+ if ( ! scrollViewRef.current || ! elementRef ) {
24
+ return;
25
+ }
26
+
27
+ elementRef.current.measureLayout(
28
+ scrollViewRef.current,
29
+ ( _x, y, _width, height ) => {
30
+ if ( height || y ) {
31
+ scrollToSection( Math.round( y ), height );
32
+ }
33
+ },
34
+ () => {}
35
+ );
36
+ },
37
+ [ scrollViewRef, scrollToSection ]
38
+ );
39
+
40
+ return [ scrollToElement ];
41
+ }
@@ -8,24 +8,21 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
8
8
  */
9
9
  import { useCallback } from '@wordpress/element';
10
10
 
11
- const DEFAULT_FONT_SIZE = 16;
12
-
13
11
  /** @typedef {import('@wordpress/element').RefObject} RefObject */
14
12
  /** @typedef {import('react-native-reanimated').SharedValue} SharedValue */
15
13
  /**
16
- * Hook to scroll to the currently focused TextInput
17
- * depending on where the caret is placed taking into
18
- * account the Keyboard and the Header.
14
+ * Hook to scroll to a specified section by taking into account the Keyboard
15
+ * and the Header.
19
16
  *
20
17
  * @param {number} extraScrollHeight Extra space to not overlap the content.
21
18
  * @param {number} keyboardOffset Keyboard space offset.
22
19
  * @param {boolean} scrollEnabled Whether the scroll is enabled or not.
23
20
  * @param {RefObject} scrollViewMeasurements ScrollView Layout measurements.
24
- * @param {RefObject} scrollViewRef ScrollView reference.
21
+ * @param {RefObject} scrollViewRef Scroll view reference.
25
22
  * @param {SharedValue} scrollViewYOffset Current offset position of the ScrollView.
26
- * @return {Function[]} Function to scroll to the current TextInput's offset.
23
+ * @return {Function[]} Function to scroll to a section.
27
24
  */
28
- export default function useScrollToTextInput(
25
+ export default function useScrollToSection(
29
26
  extraScrollHeight,
30
27
  keyboardOffset,
31
28
  scrollEnabled,
@@ -37,33 +34,31 @@ export default function useScrollToTextInput(
37
34
  const insets = top + bottom;
38
35
 
39
36
  /**
40
- * Function to scroll to the current TextInput's offset.
37
+ * Function to scroll to a section.
41
38
  *
42
- * @param {Object} caret The caret position data of the currently focused TextInput.
43
- * @param {number} caret.caretHeight The height of the caret.
44
- * @param {number} textInputOffset The offset calculated with the caret's Y coordinate + the
45
- * TextInput's Y coord or height value.
39
+ * @param {Object} section Section data to scroll to.
40
+ * @param {number} section.y Y-coordinate of of the section.
41
+ * @param {number} section.height Height of the section.
46
42
  */
47
- const scrollToTextInputOffset = useCallback(
48
- ( caret, textInputOffset ) => {
49
- const { caretHeight = DEFAULT_FONT_SIZE } = caret ?? {};
50
-
43
+ const scrollToSection = useCallback(
44
+ ( sectionY, sectionHeight ) => {
51
45
  if (
52
46
  ! scrollViewRef.current ||
53
47
  ! scrollEnabled ||
54
- ! scrollViewMeasurements.current
48
+ ! scrollViewMeasurements
55
49
  ) {
56
50
  return;
57
51
  }
52
+
58
53
  const currentScrollViewYOffset = Math.max(
59
54
  0,
60
55
  scrollViewYOffset.value
61
56
  );
62
57
 
63
- // Scroll up.
64
- if ( textInputOffset < currentScrollViewYOffset ) {
58
+ // Scroll to the top of the section.
59
+ if ( sectionY < currentScrollViewYOffset ) {
65
60
  scrollViewRef.current.scrollTo( {
66
- y: textInputOffset,
61
+ y: sectionY,
67
62
  animated: true,
68
63
  } );
69
64
  return;
@@ -72,7 +67,7 @@ export default function useScrollToTextInput(
72
67
  const availableScreenSpace = Math.abs(
73
68
  Math.floor(
74
69
  scrollViewMeasurements.current.height -
75
- ( keyboardOffset + extraScrollHeight + caretHeight )
70
+ ( keyboardOffset + extraScrollHeight + sectionHeight )
76
71
  )
77
72
  );
78
73
  const maxOffset = Math.floor(
@@ -80,12 +75,12 @@ export default function useScrollToTextInput(
80
75
  );
81
76
 
82
77
  const isAtTheTop =
83
- textInputOffset < scrollViewMeasurements.current.y + insets;
78
+ sectionY < scrollViewMeasurements.current.y + insets;
84
79
 
85
- // Scroll down.
86
- if ( textInputOffset > maxOffset && ! isAtTheTop ) {
80
+ // Scroll to the bottom of the section.
81
+ if ( sectionY > maxOffset && ! isAtTheTop ) {
87
82
  scrollViewRef.current.scrollTo( {
88
- y: textInputOffset - availableScreenSpace,
83
+ y: sectionY - availableScreenSpace,
89
84
  animated: true,
90
85
  } );
91
86
  }
@@ -101,5 +96,5 @@ export default function useScrollToTextInput(
101
96
  ]
102
97
  );
103
98
 
104
- return [ scrollToTextInputOffset ];
99
+ return [ scrollToSection ];
105
100
  }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+
5
+ import { useWindowDimensions } from 'react-native';
6
+ import {
7
+ useAnimatedScrollHandler,
8
+ useSharedValue,
9
+ } from 'react-native-reanimated';
10
+
11
+ /**
12
+ * WordPress dependencies
13
+ */
14
+ import { useCallback, useEffect, useRef } from '@wordpress/element';
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ import useKeyboardOffset from './use-keyboard-offset';
20
+ import useScrollToSection from './use-scroll-to-section';
21
+ import useScrollToElement from './use-scroll-to-element';
22
+
23
+ export default function useScroll( {
24
+ scrollEnabled,
25
+ shouldPreventAutomaticScroll,
26
+ onScroll,
27
+ onSizeChange,
28
+ extraScrollHeight,
29
+ } ) {
30
+ const scrollViewRef = useRef();
31
+ const scrollViewMeasurements = useRef();
32
+ const scrollViewYOffset = useSharedValue( -1 );
33
+ const lastScrollTo = useRef( {
34
+ clientId: null,
35
+ } );
36
+
37
+ const { height: windowHeight, width: windowWidth } = useWindowDimensions();
38
+ const isLandscape = windowWidth >= windowHeight;
39
+
40
+ const [ keyboardOffset ] = useKeyboardOffset(
41
+ scrollEnabled,
42
+ shouldPreventAutomaticScroll
43
+ );
44
+
45
+ const scrollHandler = useAnimatedScrollHandler( {
46
+ onScroll: ( event ) => {
47
+ const { contentOffset } = event;
48
+ scrollViewYOffset.value = contentOffset.y;
49
+ onScroll( event );
50
+ },
51
+ } );
52
+
53
+ // When the orientation changes, the ScrollView measurements
54
+ // need to be re-calculated.
55
+ useEffect( () => {
56
+ scrollViewMeasurements.current = null;
57
+ }, [ isLandscape ] );
58
+
59
+ const [ scrollToSection ] = useScrollToSection(
60
+ extraScrollHeight,
61
+ keyboardOffset,
62
+ scrollEnabled,
63
+ scrollViewMeasurements,
64
+ scrollViewRef,
65
+ scrollViewYOffset
66
+ );
67
+ const [ scrollToElement ] = useScrollToElement(
68
+ scrollViewRef,
69
+ scrollToSection
70
+ );
71
+
72
+ const measureScrollView = useCallback( () => {
73
+ if ( scrollViewRef.current ) {
74
+ scrollViewRef.current.measureInWindow( ( _x, y, width, height ) => {
75
+ scrollViewMeasurements.current = { y, width, height };
76
+ } );
77
+ }
78
+ }, [ scrollViewRef ] );
79
+
80
+ const onContentSizeChange = useCallback( () => {
81
+ if ( onSizeChange ) {
82
+ onSizeChange();
83
+ }
84
+
85
+ // Sets the first values when the content size changes.
86
+ if ( ! scrollViewMeasurements.current ) {
87
+ measureScrollView();
88
+ }
89
+ }, [ measureScrollView, onSizeChange ] );
90
+
91
+ return {
92
+ scrollViewRef,
93
+ scrollHandler,
94
+ keyboardOffset,
95
+ scrollToSection,
96
+ scrollToElement,
97
+ onContentSizeChange,
98
+ lastScrollTo,
99
+ };
100
+ }