@wordpress/components 23.7.0 → 23.9.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.
- package/CHANGELOG.md +52 -6
- package/build/checkbox-control/index.js +2 -2
- package/build/checkbox-control/index.js.map +1 -1
- package/build/color-palette/index.native.js +12 -0
- package/build/color-palette/index.native.js.map +1 -1
- package/build/custom-gradient-picker/index.native.js +3 -1
- package/build/custom-gradient-picker/index.native.js.map +1 -1
- package/build/custom-gradient-picker/serializer.js +0 -4
- package/build/custom-gradient-picker/serializer.js.map +1 -1
- package/build/draggable/index.js +6 -1
- package/build/draggable/index.js.map +1 -1
- package/build/drop-zone/index.js +8 -8
- package/build/drop-zone/index.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/mobile/bottom-sheet/cell.native.js +6 -6
- package/build/mobile/bottom-sheet/cell.native.js.map +1 -1
- package/build/mobile/color-settings/palette.screen.native.js +0 -8
- package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build/mobile/global-styles-context/utils.native.js +21 -4
- package/build/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/index.android.js +0 -4
- package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/index.ios.js +100 -55
- package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +82 -0
- package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +85 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +44 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +53 -0
- package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
- package/build/mobile/segmented-control/index.native.js +4 -2
- package/build/mobile/segmented-control/index.native.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +4 -2
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +4 -3
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/popover/index.js +1 -8
- package/build/popover/index.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/query-controls/author-select.js +2 -1
- package/build/query-controls/author-select.js.map +1 -1
- package/build/query-controls/category-select.js +3 -1
- package/build/query-controls/category-select.js.map +1 -1
- package/build/query-controls/index.js +7 -1
- package/build/query-controls/index.js.map +1 -1
- package/build/sandbox/index.native.js +55 -29
- package/build/sandbox/index.native.js.map +1 -1
- package/build/slot-fill/index.js +20 -7
- package/build/slot-fill/index.js.map +1 -1
- package/build/spinner/styles.js +4 -4
- package/build/spinner/styles.js.map +1 -1
- package/build/tree-grid/index.js +3 -3
- package/build/tree-grid/index.js.map +1 -1
- package/build/view/component.js +1 -2
- package/build/view/component.js.map +1 -1
- package/build-module/checkbox-control/index.js +2 -2
- package/build-module/checkbox-control/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +13 -1
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/custom-gradient-picker/index.native.js +3 -1
- package/build-module/custom-gradient-picker/index.native.js.map +1 -1
- package/build-module/custom-gradient-picker/serializer.js +0 -4
- package/build-module/custom-gradient-picker/serializer.js.map +1 -1
- package/build-module/draggable/index.js +6 -1
- package/build-module/draggable/index.js.map +1 -1
- package/build-module/drop-zone/index.js +8 -8
- package/build-module/drop-zone/index.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/mobile/bottom-sheet/cell.native.js +6 -5
- package/build-module/mobile/bottom-sheet/cell.native.js.map +1 -1
- package/build-module/mobile/color-settings/palette.screen.native.js +0 -8
- package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build-module/mobile/global-styles-context/utils.native.js +21 -3
- package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/index.android.js +0 -4
- package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +97 -54
- package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +73 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +76 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +33 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +40 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
- package/build-module/mobile/segmented-control/index.native.js +4 -2
- package/build-module/mobile/segmented-control/index.native.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +4 -2
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +4 -3
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/popover/index.js +1 -8
- package/build-module/popover/index.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/query-controls/author-select.js +2 -1
- package/build-module/query-controls/author-select.js.map +1 -1
- package/build-module/query-controls/category-select.js +3 -1
- package/build-module/query-controls/category-select.js.map +1 -1
- package/build-module/query-controls/index.js +7 -2
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/sandbox/index.native.js +56 -31
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/slot-fill/index.js +16 -6
- package/build-module/slot-fill/index.js.map +1 -1
- package/build-module/spinner/styles.js +4 -4
- package/build-module/spinner/styles.js.map +1 -1
- package/build-module/tree-grid/index.js +3 -3
- package/build-module/tree-grid/index.js.map +1 -1
- package/build-module/view/component.js +1 -2
- package/build-module/view/component.js.map +1 -1
- package/build-style/style-rtl.css +26 -16
- package/build-style/style.css +26 -16
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +2 -2
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +2 -2
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +2 -2
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +2 -2
- package/build-types/border-control/border-control/hook.d.ts +2 -2
- package/build-types/border-control/border-control-dropdown/hook.d.ts +2 -2
- package/build-types/border-control/border-control-style-picker/hook.d.ts +2 -2
- package/build-types/box-control/styles/box-control-styles.d.ts +5 -5
- package/build-types/button/deprecated.d.ts +8 -8
- package/build-types/card/card/hook.d.ts +2 -2
- package/build-types/card/card-body/hook.d.ts +2 -2
- package/build-types/card/card-divider/hook.d.ts +2 -2
- package/build-types/card/card-footer/hook.d.ts +2 -2
- package/build-types/card/card-header/hook.d.ts +2 -2
- package/build-types/card/card-media/hook.d.ts +2 -2
- package/build-types/checkbox-control/index.d.ts.map +1 -1
- package/build-types/color-palette/styles.d.ts +1 -1
- package/build-types/color-picker/styles.d.ts +7 -7
- package/build-types/combobox-control/styles.d.ts +1 -1
- package/build-types/custom-gradient-picker/serializer.d.ts +1 -5
- package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/types.d.ts +0 -2
- package/build-types/custom-gradient-picker/types.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +2 -2
- package/build-types/date-time/date-time/styles.d.ts +1 -1
- package/build-types/date-time/time/styles.d.ts +8 -8
- package/build-types/draggable/index.d.ts +1 -1
- package/build-types/draggable/index.d.ts.map +1 -1
- package/build-types/draggable/stories/index.d.ts +8 -0
- package/build-types/draggable/stories/index.d.ts.map +1 -1
- package/build-types/draggable/types.d.ts +7 -0
- package/build-types/draggable/types.d.ts.map +1 -1
- package/build-types/drop-zone/index.d.ts.map +1 -1
- package/build-types/elevation/hook.d.ts +2 -2
- package/build-types/external-link/styles/external-link-styles.d.ts +1 -1
- package/build-types/flex/flex/hook.d.ts +2 -2
- package/build-types/flex/flex-block/hook.d.ts +2 -2
- package/build-types/flex/flex-item/hook.d.ts +2 -2
- package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +2 -2
- package/build-types/form-token-field/styles.d.ts +1 -1
- package/build-types/grid/hook.d.ts +2 -2
- package/build-types/h-stack/hook.d.ts +2 -2
- package/build-types/heading/hook.d.ts +2 -2
- package/build-types/index.d.ts +129 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/input-control/styles/input-control-styles.d.ts +2 -2
- package/build-types/item-group/item/hook.d.ts +2 -2
- package/build-types/item-group/item-group/hook.d.ts +2 -2
- package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
- package/build-types/navigator/navigator-back-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +3 -3
- package/build-types/navigator/navigator-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +3 -3
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-to-parent-button/component.d.ts +1 -1
- package/build-types/navigator/stories/index.d.ts +1 -0
- package/build-types/navigator/stories/index.d.ts.map +1 -1
- package/build-types/navigator/types.d.ts +2 -2
- package/build-types/navigator/types.d.ts.map +1 -1
- package/build-types/number-control/index.d.ts +2 -2
- package/build-types/number-control/stories/index.d.ts +2 -2
- package/build-types/palette-edit/styles.d.ts +18 -12
- package/build-types/palette-edit/styles.d.ts.map +1 -1
- package/build-types/popover/index.d.ts +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/popover/stories/e2e/index.d.ts +1 -1
- package/build-types/private-apis.d.ts +2 -3
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/query-controls/author-select.d.ts.map +1 -1
- package/build-types/query-controls/category-select.d.ts.map +1 -1
- package/build-types/query-controls/index.d.ts.map +1 -1
- package/build-types/range-control/index.d.ts +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts +2 -2
- package/build-types/resizable-box/index.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
- package/build-types/resizable-box/stories/index.d.ts +2 -2
- package/build-types/scrollable/hook.d.ts +2 -2
- package/build-types/search-control/index.d.ts +1 -1
- package/build-types/search-control/stories/index.d.ts +2 -2
- package/build-types/slot-fill/index.d.ts +13 -1
- package/build-types/slot-fill/index.d.ts.map +1 -1
- package/build-types/spacer/hook.d.ts +2 -2
- package/build-types/spinner/index.d.ts +1 -1
- package/build-types/spinner/styles.d.ts.map +1 -1
- package/build-types/surface/hook.d.ts +2 -2
- package/build-types/text/hook.d.ts +2 -2
- package/build-types/text-control/index.d.ts +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +8 -8
- package/build-types/tools-panel/tools-panel/hook.d.ts +2 -2
- package/build-types/tools-panel/tools-panel-header/hook.d.ts +2 -2
- package/build-types/tools-panel/tools-panel-item/hook.d.ts +2 -2
- package/build-types/tree-grid/index.d.ts.map +1 -1
- package/build-types/truncate/hook.d.ts +2 -2
- package/build-types/ui/context/wordpress-component.d.ts +1 -1
- package/build-types/ui/context/wordpress-component.d.ts.map +1 -1
- package/build-types/ui/control-group/hook.d.ts +2 -2
- package/build-types/ui/control-label/hook.d.ts +2 -2
- package/build-types/ui/form-group/form-group.d.ts +2 -2
- package/build-types/ui/form-group/use-form-group.d.ts +2 -2
- package/build-types/unit-control/index.d.ts +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts +2 -2
- package/build-types/v-stack/hook.d.ts +2 -2
- package/build-types/view/component.d.ts +1 -1
- package/build-types/view/component.d.ts.map +1 -1
- package/package.json +22 -22
- package/src/autocomplete/README.md +4 -2
- package/src/checkbox-control/index.tsx +6 -2
- package/src/color-palette/index.native.js +20 -1
- package/src/color-picker/test/index.tsx +99 -99
- package/src/custom-gradient-picker/index.native.js +1 -1
- package/src/custom-gradient-picker/serializer.ts +2 -6
- package/src/custom-gradient-picker/types.ts +0 -18
- package/src/dimension-control/README.md +1 -1
- package/src/draggable/README.md +8 -1
- package/src/draggable/index.tsx +6 -1
- package/src/draggable/stories/index.tsx +69 -33
- package/src/draggable/types.ts +7 -0
- package/src/drop-zone/index.tsx +12 -8
- package/src/drop-zone/style.scss +1 -1
- package/src/{index.js → index.ts} +1 -0
- package/src/mobile/bottom-sheet/cell.native.js +4 -5
- package/src/mobile/color-settings/palette.screen.native.js +0 -7
- package/src/mobile/global-styles-context/utils.native.js +18 -3
- package/src/mobile/keyboard-aware-flat-list/index.android.js +0 -4
- package/src/mobile/keyboard-aware-flat-list/index.ios.js +118 -67
- package/src/mobile/keyboard-aware-flat-list/test/use-keyboard-offset.native.js +203 -0
- package/src/mobile/keyboard-aware-flat-list/test/use-scroll-to-text-input.native.js +140 -0
- package/src/mobile/keyboard-aware-flat-list/test/use-text-input-caret-position.native.js +82 -0
- package/src/mobile/keyboard-aware-flat-list/test/use-text-input-offset.native.js +147 -0
- package/src/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +87 -0
- package/src/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +105 -0
- package/src/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +36 -0
- package/src/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +54 -0
- package/src/mobile/segmented-control/index.native.js +2 -2
- package/src/modal/style.scss +20 -12
- package/src/navigator/navigator-provider/component.tsx +2 -0
- package/src/navigator/navigator-screen/component.tsx +5 -2
- package/src/navigator/stories/index.tsx +68 -0
- package/src/navigator/test/index.tsx +52 -0
- package/src/navigator/types.ts +2 -1
- package/src/popover/index.tsx +2 -15
- package/src/{private-apis.js → private-apis.ts} +2 -0
- package/src/query-controls/author-select.tsx +1 -0
- package/src/query-controls/category-select.tsx +1 -0
- package/src/query-controls/index.tsx +4 -2
- package/src/sandbox/index.native.js +78 -37
- package/src/slot-fill/index.js +14 -6
- package/src/snackbar/style.scss +2 -1
- package/src/spinner/styles.ts +2 -0
- package/src/tree-grid/index.tsx +7 -2
- package/src/ui/context/wordpress-component.ts +1 -1
- package/src/view/component.tsx +2 -2
- package/tsconfig.json +3 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -9,14 +9,20 @@ exports.default = exports.KeyboardAwareFlatList = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _reactNativeKeyboardAwareScrollView = require("react-native-keyboard-aware-scroll-view");
|
|
13
|
-
|
|
14
12
|
var _reactNative = require("react-native");
|
|
15
13
|
|
|
16
|
-
var _es = _interopRequireDefault(require("fast-deep-equal/es6"));
|
|
17
|
-
|
|
18
14
|
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
19
15
|
|
|
16
|
+
var _compose = require("@wordpress/compose");
|
|
17
|
+
|
|
18
|
+
var _useTextInputOffset = _interopRequireDefault(require("./use-text-input-offset"));
|
|
19
|
+
|
|
20
|
+
var _useKeyboardOffset = _interopRequireDefault(require("./use-keyboard-offset"));
|
|
21
|
+
|
|
22
|
+
var _useScrollToTextInput = _interopRequireDefault(require("./use-scroll-to-text-input"));
|
|
23
|
+
|
|
24
|
+
var _useTextInputCaretPosition = _interopRequireDefault(require("./use-text-input-caret-position"));
|
|
25
|
+
|
|
20
26
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
27
|
|
|
22
28
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -28,82 +34,121 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
28
34
|
/**
|
|
29
35
|
* WordPress dependencies
|
|
30
36
|
*/
|
|
31
|
-
const List = (0, _element.memo)(_reactNative.FlatList, _es.default);
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Internal dependencies
|
|
40
|
+
*/
|
|
41
|
+
const AnimatedScrollView = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.ScrollView);
|
|
42
|
+
/**
|
|
43
|
+
* React component that provides a FlatList that is aware of the keyboard state and can scroll
|
|
44
|
+
* to the currently focused TextInput.
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} props Component props.
|
|
47
|
+
* @param {number} props.extraScrollHeight Extra scroll height for the content.
|
|
48
|
+
* @param {Function} props.innerRef Function to pass the ScrollView ref to the parent component.
|
|
49
|
+
* @param {Function} props.onScroll Function to be called when the list is scrolled.
|
|
50
|
+
* @param {boolean} props.scrollEnabled Whether the list can be scrolled.
|
|
51
|
+
* @param {Object} props.scrollViewStyle Additional style for the ScrollView component.
|
|
52
|
+
* @param {boolean} props.shouldPreventAutomaticScroll Whether to prevent scrolling when there's a Keyboard offset set.
|
|
53
|
+
* @param {Object} props... Other props to pass to the FlatList component.
|
|
54
|
+
* @return {WPComponent} KeyboardAwareFlatList component.
|
|
55
|
+
*/
|
|
56
|
+
|
|
34
57
|
|
|
35
58
|
const KeyboardAwareFlatList = _ref => {
|
|
36
59
|
let {
|
|
37
60
|
extraScrollHeight,
|
|
38
|
-
shouldPreventAutomaticScroll,
|
|
39
61
|
innerRef,
|
|
40
|
-
autoScroll,
|
|
41
|
-
scrollViewStyle,
|
|
42
|
-
inputAccessoryViewHeight,
|
|
43
62
|
onScroll,
|
|
44
|
-
|
|
63
|
+
scrollEnabled,
|
|
64
|
+
scrollViewStyle,
|
|
65
|
+
shouldPreventAutomaticScroll,
|
|
66
|
+
...props
|
|
45
67
|
} = _ref;
|
|
46
68
|
const scrollViewRef = (0, _element.useRef)();
|
|
47
|
-
const
|
|
48
|
-
const
|
|
69
|
+
const scrollViewMeasurements = (0, _element.useRef)();
|
|
70
|
+
const scrollViewYOffset = (0, _reactNativeReanimated.useSharedValue)(-1);
|
|
71
|
+
const {
|
|
72
|
+
height: windowHeight,
|
|
73
|
+
width: windowWidth
|
|
74
|
+
} = (0, _reactNative.useWindowDimensions)();
|
|
75
|
+
const isLandscape = windowWidth >= windowHeight;
|
|
76
|
+
const [keyboardOffset] = (0, _useKeyboardOffset.default)(scrollEnabled, shouldPreventAutomaticScroll);
|
|
77
|
+
const [currentCaretData] = (0, _useTextInputCaretPosition.default)(scrollEnabled);
|
|
78
|
+
const [getTextInputOffset] = (0, _useTextInputOffset.default)(scrollEnabled, scrollViewRef);
|
|
79
|
+
const [scrollToTextInputOffset] = (0, _useScrollToTextInput.default)(extraScrollHeight, keyboardOffset, scrollEnabled, scrollViewMeasurements, scrollViewRef, scrollViewYOffset);
|
|
80
|
+
const onScrollToTextInput = (0, _compose.useThrottle)((0, _element.useCallback)(async caret => {
|
|
81
|
+
const textInputOffset = await getTextInputOffset(caret);
|
|
82
|
+
const hasTextInputOffset = textInputOffset !== null;
|
|
83
|
+
|
|
84
|
+
if (hasTextInputOffset) {
|
|
85
|
+
scrollToTextInputOffset(caret, textInputOffset);
|
|
86
|
+
}
|
|
87
|
+
}, [getTextInputOffset, scrollToTextInputOffset]), 200, {
|
|
88
|
+
leading: false
|
|
89
|
+
});
|
|
90
|
+
(0, _element.useEffect)(() => {
|
|
91
|
+
onScrollToTextInput(currentCaretData);
|
|
92
|
+
}, [currentCaretData, onScrollToTextInput]); // When the orientation changes, the ScrollView measurements
|
|
93
|
+
// need to be re-calculated.
|
|
94
|
+
|
|
95
|
+
(0, _element.useEffect)(() => {
|
|
96
|
+
scrollViewMeasurements.current = null;
|
|
97
|
+
}, [isLandscape]);
|
|
49
98
|
const scrollHandler = (0, _reactNativeReanimated.useAnimatedScrollHandler)({
|
|
50
99
|
onScroll: event => {
|
|
51
100
|
const {
|
|
52
101
|
contentOffset
|
|
53
102
|
} = event;
|
|
54
|
-
|
|
103
|
+
scrollViewYOffset.value = contentOffset.y;
|
|
55
104
|
onScroll(event);
|
|
56
105
|
}
|
|
57
106
|
});
|
|
107
|
+
const measureScrollView = (0, _element.useCallback)(() => {
|
|
108
|
+
if (scrollViewRef.current) {
|
|
109
|
+
const scrollRef = scrollViewRef.current.getNativeScrollRef();
|
|
110
|
+
scrollRef.measureInWindow((_x, y, width, height) => {
|
|
111
|
+
scrollViewMeasurements.current = {
|
|
112
|
+
y,
|
|
113
|
+
width,
|
|
114
|
+
height
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}, []);
|
|
119
|
+
const onContentSizeChange = (0, _element.useCallback)(() => {
|
|
120
|
+
onScrollToTextInput(currentCaretData); // Sets the first values when the content size changes.
|
|
121
|
+
|
|
122
|
+
if (!scrollViewMeasurements.current) {
|
|
123
|
+
measureScrollView();
|
|
124
|
+
}
|
|
125
|
+
}, [measureScrollView, onScrollToTextInput, currentCaretData]);
|
|
58
126
|
const getRef = (0, _element.useCallback)(ref => {
|
|
59
127
|
scrollViewRef.current = ref;
|
|
60
128
|
innerRef(ref);
|
|
61
|
-
}, [innerRef]);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, 50);
|
|
74
|
-
}, [latestContentOffsetY, shouldPreventAutomaticScroll]);
|
|
75
|
-
const onKeyboardWillShow = (0, _element.useCallback)(() => {
|
|
76
|
-
keyboardWillShowIndicator.current = true;
|
|
77
|
-
}, []);
|
|
78
|
-
return (0, _element.createElement)(AnimatedKeyboardAwareScrollView, {
|
|
79
|
-
style: [{
|
|
80
|
-
flex: 1
|
|
81
|
-
}, scrollViewStyle],
|
|
82
|
-
keyboardDismissMode: "none",
|
|
83
|
-
enableResetScrollToCoords: false,
|
|
129
|
+
}, [innerRef]); // Adds content insets when the keyboard is opened to have
|
|
130
|
+
// extra padding at the bottom.
|
|
131
|
+
|
|
132
|
+
const contentInset = {
|
|
133
|
+
bottom: keyboardOffset
|
|
134
|
+
};
|
|
135
|
+
const style = [{
|
|
136
|
+
flex: 1
|
|
137
|
+
}, scrollViewStyle];
|
|
138
|
+
return (0, _element.createElement)(AnimatedScrollView, {
|
|
139
|
+
automaticallyAdjustContentInsets: false,
|
|
140
|
+
contentInset: contentInset,
|
|
84
141
|
keyboardShouldPersistTaps: "handled",
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
inputAccessoryViewHeight: inputAccessoryViewHeight,
|
|
88
|
-
enableAutomaticScroll: autoScroll === undefined ? false : autoScroll,
|
|
142
|
+
onContentSizeChange: onContentSizeChange,
|
|
143
|
+
onScroll: scrollHandler,
|
|
89
144
|
ref: getRef,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
onScroll: scrollHandler
|
|
95
|
-
}, (0, _element.createElement)(List, listProps));
|
|
145
|
+
scrollEnabled: scrollEnabled,
|
|
146
|
+
scrollEventThrottle: 16,
|
|
147
|
+
style: style
|
|
148
|
+
}, (0, _element.createElement)(_reactNative.FlatList, props));
|
|
96
149
|
};
|
|
97
150
|
|
|
98
151
|
exports.KeyboardAwareFlatList = KeyboardAwareFlatList;
|
|
99
|
-
|
|
100
|
-
KeyboardAwareFlatList.handleCaretVerticalPositionChange = (scrollView, targetId, caretY, previousCaretY) => {
|
|
101
|
-
if (previousCaretY) {
|
|
102
|
-
// If this is not the first tap.
|
|
103
|
-
scrollView.refreshScrollForField(targetId);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
152
|
var _default = KeyboardAwareFlatList;
|
|
108
153
|
exports.default = _default;
|
|
109
154
|
//# sourceMappingURL=index.ios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/mobile/keyboard-aware-flat-list/index.ios.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/mobile/keyboard-aware-flat-list/index.ios.js"],"names":["AnimatedScrollView","Animated","createAnimatedComponent","ScrollView","KeyboardAwareFlatList","extraScrollHeight","innerRef","onScroll","scrollEnabled","scrollViewStyle","shouldPreventAutomaticScroll","props","scrollViewRef","scrollViewMeasurements","scrollViewYOffset","height","windowHeight","width","windowWidth","isLandscape","keyboardOffset","currentCaretData","getTextInputOffset","scrollToTextInputOffset","onScrollToTextInput","caret","textInputOffset","hasTextInputOffset","leading","current","scrollHandler","event","contentOffset","value","y","measureScrollView","scrollRef","getNativeScrollRef","measureInWindow","_x","onContentSizeChange","getRef","ref","contentInset","bottom","style","flex"],"mappings":";;;;;;;;;AAaA;;AATA;;AACA;;AASA;;AAKA;;AACA;;AACA;;AACA;;;;;;AAtBA;AACA;AACA;;AAQA;AACA;AACA;;AAIA;AACA;AACA;AAMA,MAAMA,kBAAkB,GAAGC,+BAASC,uBAAT,CAAkCC,uBAAlC,CAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;A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F,IAAW;AACV9B,IAAAA,aAAa,CAACiB,OAAd,GAAwBa,GAAxB;AACApC,IAAAA,QAAQ,CAAEoC,GAAF,CAAR;AACA,GAJa,EAKd,CAAEpC,QAAF,CALc,CAAf,CAlFM,CA0FN;AACA;;AACA,QAAMqC,YAAY,GAAG;AAAEC,IAAAA,MAAM,EAAExB;AAAV,GAArB;AAEA,QAAMyB,KAAK,GAAG,CAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAAF,EAAerC,eAAf,CAAd;AAEA,SACC,4BAAC,kBAAD;AACC,IAAA,gCAAgC,EAAG,KADpC;AAEC,IAAA,YAAY,EAAGkC,YAFhB;AAGC,IAAA,yBAAyB,EAAC,SAH3B;AAIC,IAAA,mBAAmB,EAAGH,mBAJvB;AAKC,IAAA,QAAQ,EAAGV,aALZ;AAMC,IAAA,GAAG,EAAGW,MANP;AAOC,IAAA,aAAa,EAAGjC,aAPjB;AAQC,IAAA,mBAAmB,EAAG,EARvB;AASC,IAAA,KAAK,EAAGqC;AATT,KAWC,4BAAC,qBAAD,EAAelC,KAAf,CAXD,CADD;AAeA,CAvHM;;;eAyHQP,qB","sourcesContent":["/**\n * External dependencies\n */\n\nimport { ScrollView, FlatList, useWindowDimensions } from 'react-native';\nimport Animated, {\n\tuseAnimatedScrollHandler,\n\tuseSharedValue,\n} from 'react-native-reanimated';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useThrottle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useTextInputOffset from './use-text-input-offset';\nimport useKeyboardOffset from './use-keyboard-offset';\nimport useScrollToTextInput from './use-scroll-to-text-input';\nimport useTextInputCaretPosition from './use-text-input-caret-position';\n\nconst AnimatedScrollView = Animated.createAnimatedComponent( ScrollView );\n\n/**\n * React component that provides a FlatList that is aware of the keyboard state and can scroll\n * to the currently focused TextInput.\n *\n * @param {Object} props Component props.\n * @param {number} props.extraScrollHeight Extra scroll height for the content.\n * @param {Function} props.innerRef Function to pass the ScrollView ref to the parent component.\n * @param {Function} props.onScroll Function to be called when the list is scrolled.\n * @param {boolean} props.scrollEnabled Whether the list can be scrolled.\n * @param {Object} props.scrollViewStyle Additional style for the ScrollView component.\n * @param {boolean} props.shouldPreventAutomaticScroll Whether to prevent scrolling when there's a Keyboard offset set.\n * @param {Object} props... Other props to pass to the FlatList component.\n * @return {WPComponent} KeyboardAwareFlatList component.\n */\nexport const KeyboardAwareFlatList = ( {\n\textraScrollHeight,\n\tinnerRef,\n\tonScroll,\n\tscrollEnabled,\n\tscrollViewStyle,\n\tshouldPreventAutomaticScroll,\n\t...props\n} ) => {\n\tconst scrollViewRef = useRef();\n\tconst scrollViewMeasurements = useRef();\n\tconst scrollViewYOffset = useSharedValue( -1 );\n\n\tconst { height: windowHeight, width: windowWidth } = useWindowDimensions();\n\tconst isLandscape = windowWidth >= windowHeight;\n\n\tconst [ keyboardOffset ] = useKeyboardOffset(\n\t\tscrollEnabled,\n\t\tshouldPreventAutomaticScroll\n\t);\n\n\tconst [ currentCaretData ] = useTextInputCaretPosition( scrollEnabled );\n\n\tconst [ getTextInputOffset ] = useTextInputOffset(\n\t\tscrollEnabled,\n\t\tscrollViewRef\n\t);\n\n\tconst [ scrollToTextInputOffset ] = useScrollToTextInput(\n\t\textraScrollHeight,\n\t\tkeyboardOffset,\n\t\tscrollEnabled,\n\t\tscrollViewMeasurements,\n\t\tscrollViewRef,\n\t\tscrollViewYOffset\n\t);\n\n\tconst onScrollToTextInput = useThrottle(\n\t\tuseCallback(\n\t\t\tasync ( caret ) => {\n\t\t\t\tconst textInputOffset = await getTextInputOffset( caret );\n\t\t\t\tconst hasTextInputOffset = textInputOffset !== null;\n\n\t\t\t\tif ( hasTextInputOffset ) {\n\t\t\t\t\tscrollToTextInputOffset( caret, textInputOffset );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ getTextInputOffset, scrollToTextInputOffset ]\n\t\t),\n\t\t200,\n\t\t{ leading: false }\n\t);\n\n\tuseEffect( () => {\n\t\tonScrollToTextInput( currentCaretData );\n\t}, [ currentCaretData, onScrollToTextInput ] );\n\n\t// When the orientation changes, the ScrollView measurements\n\t// need to be re-calculated.\n\tuseEffect( () => {\n\t\tscrollViewMeasurements.current = null;\n\t}, [ isLandscape ] );\n\n\tconst scrollHandler = useAnimatedScrollHandler( {\n\t\tonScroll: ( event ) => {\n\t\t\tconst { contentOffset } = event;\n\t\t\tscrollViewYOffset.value = contentOffset.y;\n\t\t\tonScroll( event );\n\t\t},\n\t} );\n\n\tconst measureScrollView = useCallback( () => {\n\t\tif ( scrollViewRef.current ) {\n\t\t\tconst scrollRef = scrollViewRef.current.getNativeScrollRef();\n\n\t\t\tscrollRef.measureInWindow( ( _x, y, width, height ) => {\n\t\t\t\tscrollViewMeasurements.current = { y, width, height };\n\t\t\t} );\n\t\t}\n\t}, [] );\n\n\tconst onContentSizeChange = useCallback( () => {\n\t\tonScrollToTextInput( currentCaretData );\n\n\t\t// Sets the first values when the content size changes.\n\t\tif ( ! scrollViewMeasurements.current ) {\n\t\t\tmeasureScrollView();\n\t\t}\n\t}, [ measureScrollView, onScrollToTextInput, currentCaretData ] );\n\n\tconst getRef = useCallback(\n\t\t( ref ) => {\n\t\t\tscrollViewRef.current = ref;\n\t\t\tinnerRef( ref );\n\t\t},\n\t\t[ innerRef ]\n\t);\n\n\t// Adds content insets when the keyboard is opened to have\n\t// extra padding at the bottom.\n\tconst contentInset = { bottom: keyboardOffset };\n\n\tconst style = [ { flex: 1 }, scrollViewStyle ];\n\n\treturn (\n\t\t<AnimatedScrollView\n\t\t\tautomaticallyAdjustContentInsets={ false }\n\t\t\tcontentInset={ contentInset }\n\t\t\tkeyboardShouldPersistTaps=\"handled\"\n\t\t\tonContentSizeChange={ onContentSizeChange }\n\t\t\tonScroll={ scrollHandler }\n\t\t\tref={ getRef }\n\t\t\tscrollEnabled={ scrollEnabled }\n\t\t\tscrollEventThrottle={ 16 }\n\t\t\tstyle={ style }\n\t\t>\n\t\t\t<FlatList { ...props } />\n\t\t</AnimatedScrollView>\n\t);\n};\n\nexport default KeyboardAwareFlatList;\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useKeyboardOffset;
|
|
7
|
+
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* External dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hook that adds Keyboard listeners to get the offset space
|
|
22
|
+
* when the keyboard is opened, taking into account focused AztecViews.
|
|
23
|
+
*
|
|
24
|
+
* @param {boolean} scrollEnabled Whether the scroll is enabled or not.
|
|
25
|
+
* @param {Function} shouldPreventAutomaticScroll Whether to prevent scrolling when there's a Keyboard offset set.
|
|
26
|
+
* @return {[number]} Keyboard offset.
|
|
27
|
+
*/
|
|
28
|
+
function useKeyboardOffset(scrollEnabled, shouldPreventAutomaticScroll) {
|
|
29
|
+
const [keyboardOffset, setKeyboardOffset] = (0, _element.useState)(0);
|
|
30
|
+
const timeoutRef = (0, _element.useRef)();
|
|
31
|
+
const onKeyboardDidHide = (0, _element.useCallback)(() => {
|
|
32
|
+
if (shouldPreventAutomaticScroll()) {
|
|
33
|
+
clearTimeout(timeoutRef.current);
|
|
34
|
+
return;
|
|
35
|
+
} // A timeout is being used to delay resetting the offset in cases
|
|
36
|
+
// where the focus is changed to a different TextInput.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
clearTimeout(timeoutRef.current);
|
|
40
|
+
timeoutRef.current = setTimeout(() => {
|
|
41
|
+
setKeyboardOffset(0);
|
|
42
|
+
}, 200);
|
|
43
|
+
}, [shouldPreventAutomaticScroll]);
|
|
44
|
+
const onKeyboardDidShow = (0, _element.useCallback)(_ref => {
|
|
45
|
+
let {
|
|
46
|
+
endCoordinates
|
|
47
|
+
} = _ref;
|
|
48
|
+
clearTimeout(timeoutRef.current);
|
|
49
|
+
setKeyboardOffset(endCoordinates.height);
|
|
50
|
+
}, []);
|
|
51
|
+
const onKeyboardWillShow = (0, _element.useCallback)(() => {
|
|
52
|
+
clearTimeout(timeoutRef.current);
|
|
53
|
+
}, []);
|
|
54
|
+
(0, _element.useEffect)(() => {
|
|
55
|
+
let willShowSubscription;
|
|
56
|
+
let showSubscription;
|
|
57
|
+
let hideSubscription;
|
|
58
|
+
|
|
59
|
+
if (scrollEnabled) {
|
|
60
|
+
willShowSubscription = _reactNative.Keyboard.addListener('keyboardWillShow', onKeyboardWillShow);
|
|
61
|
+
showSubscription = _reactNative.Keyboard.addListener('keyboardDidShow', onKeyboardDidShow);
|
|
62
|
+
hideSubscription = _reactNative.Keyboard.addListener('keyboardDidHide', onKeyboardDidHide);
|
|
63
|
+
} else {
|
|
64
|
+
var _willShowSubscription, _showSubscription, _hideSubscription;
|
|
65
|
+
|
|
66
|
+
(_willShowSubscription = willShowSubscription) === null || _willShowSubscription === void 0 ? void 0 : _willShowSubscription.remove();
|
|
67
|
+
(_showSubscription = showSubscription) === null || _showSubscription === void 0 ? void 0 : _showSubscription.remove();
|
|
68
|
+
(_hideSubscription = hideSubscription) === null || _hideSubscription === void 0 ? void 0 : _hideSubscription.remove();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return () => {
|
|
72
|
+
var _willShowSubscription2, _showSubscription2, _hideSubscription2;
|
|
73
|
+
|
|
74
|
+
clearTimeout(timeoutRef.current);
|
|
75
|
+
(_willShowSubscription2 = willShowSubscription) === null || _willShowSubscription2 === void 0 ? void 0 : _willShowSubscription2.remove();
|
|
76
|
+
(_showSubscription2 = showSubscription) === null || _showSubscription2 === void 0 ? void 0 : _showSubscription2.remove();
|
|
77
|
+
(_hideSubscription2 = hideSubscription) === null || _hideSubscription2 === void 0 ? void 0 : _hideSubscription2.remove();
|
|
78
|
+
};
|
|
79
|
+
}, [onKeyboardDidHide, onKeyboardDidShow, onKeyboardWillShow, scrollEnabled]);
|
|
80
|
+
return [keyboardOffset];
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=use-keyboard-offset.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js"],"names":["useKeyboardOffset","scrollEnabled","shouldPreventAutomaticScroll","keyboardOffset","setKeyboardOffset","timeoutRef","onKeyboardDidHide","clearTimeout","current","setTimeout","onKeyboardDidShow","endCoordinates","height","onKeyboardWillShow","willShowSubscription","showSubscription","hideSubscription","Keyboard","addListener","remove"],"mappings":";;;;;;;AAIA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,iBAAT,CACdC,aADc,EAEdC,4BAFc,EAGb;AACD,QAAM,CAAEC,cAAF,EAAkBC,iBAAlB,IAAwC,uBAAU,CAAV,CAA9C;AACA,QAAMC,UAAU,GAAG,sBAAnB;AAEA,QAAMC,iBAAiB,GAAG,0BAAa,MAAM;AAC5C,QAAKJ,4BAA4B,EAAjC,EAAsC;AACrCK,MAAAA,YAAY,CAAEF,UAAU,CAACG,OAAb,CAAZ;AACA;AACA,KAJ2C,CAM5C;AACA;;;AACAD,IAAAA,YAAY,CAAEF,UAAU,CAACG,OAAb,CAAZ;AACAH,IAAAA,UAAU,CAACG,OAAX,GAAqBC,UAAU,CAAE,MAAM;AACtCL,MAAAA,iBAAiB,CAAE,CAAF,CAAjB;AACA,KAF8B,EAE5B,GAF4B,CAA/B;AAGA,GAZyB,EAYvB,CAAEF,4BAAF,CAZuB,CAA1B;AAcA,QAAMQ,iBAAiB,GAAG,0BAAa,QAA0B;AAAA,QAA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dependencies\n */\nimport { useEffect, useCallback, useState, useRef } from '@wordpress/element';\n\n/**\n * Hook that adds Keyboard listeners to get the offset space\n * when the keyboard is opened, taking into account focused AztecViews.\n *\n * @param {boolean} scrollEnabled Whether the scroll is enabled or not.\n * @param {Function} shouldPreventAutomaticScroll Whether to prevent scrolling when there's a Keyboard offset set.\n * @return {[number]} Keyboard offset.\n */\nexport default function useKeyboardOffset(\n\tscrollEnabled,\n\tshouldPreventAutomaticScroll\n) {\n\tconst [ keyboardOffset, setKeyboardOffset ] = useState( 0 );\n\tconst timeoutRef = useRef();\n\n\tconst onKeyboardDidHide = useCallback( () => {\n\t\tif ( shouldPreventAutomaticScroll() ) {\n\t\t\tclearTimeout( timeoutRef.current );\n\t\t\treturn;\n\t\t}\n\n\t\t// A timeout is being used to delay resetting the offset in cases\n\t\t// where the focus is changed to a different TextInput.\n\t\tclearTimeout( timeoutRef.current );\n\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\tsetKeyboardOffset( 0 );\n\t\t}, 200 );\n\t}, [ shouldPreventAutomaticScroll ] );\n\n\tconst onKeyboardDidShow = useCallback( ( { endCoordinates } ) => {\n\t\tclearTimeout( timeoutRef.current );\n\t\tsetKeyboardOffset( endCoordinates.height );\n\t}, [] );\n\n\tconst onKeyboardWillShow = useCallback( () => {\n\t\tclearTimeout( timeoutRef.current );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tlet willShowSubscription;\n\t\tlet showSubscription;\n\t\tlet hideSubscription;\n\n\t\tif ( scrollEnabled ) {\n\t\t\twillShowSubscription = Keyboard.addListener(\n\t\t\t\t'keyboardWillShow',\n\t\t\t\tonKeyboardWillShow\n\t\t\t);\n\t\t\tshowSubscription = Keyboard.addListener(\n\t\t\t\t'keyboardDidShow',\n\t\t\t\tonKeyboardDidShow\n\t\t\t);\n\t\t\thideSubscription = Keyboard.addListener(\n\t\t\t\t'keyboardDidHide',\n\t\t\t\tonKeyboardDidHide\n\t\t\t);\n\t\t} else {\n\t\t\twillShowSubscription?.remove();\n\t\t\tshowSubscription?.remove();\n\t\t\thideSubscription?.remove();\n\t\t}\n\n\t\treturn () => {\n\t\t\tclearTimeout( timeoutRef.current );\n\t\t\twillShowSubscription?.remove();\n\t\t\tshowSubscription?.remove();\n\t\t\thideSubscription?.remove();\n\t\t};\n\t}, [\n\t\tonKeyboardDidHide,\n\t\tonKeyboardDidShow,\n\t\tonKeyboardWillShow,\n\t\tscrollEnabled,\n\t] );\n\treturn [ keyboardOffset ];\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useScrollToTextInput;
|
|
7
|
+
|
|
8
|
+
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* External dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_FONT_SIZE = 16;
|
|
20
|
+
/** @typedef {import('@wordpress/element').RefObject} RefObject */
|
|
21
|
+
|
|
22
|
+
/** @typedef {import('react-native-reanimated').SharedValue} SharedValue */
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Hook to scroll to the currently focused TextInput
|
|
26
|
+
* depending on where the caret is placed taking into
|
|
27
|
+
* account the Keyboard and the Header.
|
|
28
|
+
*
|
|
29
|
+
* @param {number} extraScrollHeight Extra space to not overlap the content.
|
|
30
|
+
* @param {number} keyboardOffset Keyboard space offset.
|
|
31
|
+
* @param {boolean} scrollEnabled Whether the scroll is enabled or not.
|
|
32
|
+
* @param {RefObject} scrollViewMeasurements ScrollView Layout measurements.
|
|
33
|
+
* @param {RefObject} scrollViewRef ScrollView reference.
|
|
34
|
+
* @param {SharedValue} scrollViewYOffset Current offset position of the ScrollView.
|
|
35
|
+
* @return {Function[]} Function to scroll to the current TextInput's offset.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
function useScrollToTextInput(extraScrollHeight, keyboardOffset, scrollEnabled, scrollViewMeasurements, scrollViewRef, scrollViewYOffset) {
|
|
39
|
+
const {
|
|
40
|
+
top,
|
|
41
|
+
bottom
|
|
42
|
+
} = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
|
|
43
|
+
const insets = top + bottom;
|
|
44
|
+
/**
|
|
45
|
+
* Function to scroll to the current TextInput's offset.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} caret The caret position data of the currently focused TextInput.
|
|
48
|
+
* @param {number} caret.caretHeight The height of the caret.
|
|
49
|
+
* @param {number} textInputOffset The offset calculated with the caret's Y coordinate + the
|
|
50
|
+
* TextInput's Y coord or height value.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const scrollToTextInputOffset = (0, _element.useCallback)((caret, textInputOffset) => {
|
|
54
|
+
const {
|
|
55
|
+
caretHeight = DEFAULT_FONT_SIZE
|
|
56
|
+
} = caret !== null && caret !== void 0 ? caret : {};
|
|
57
|
+
|
|
58
|
+
if (!scrollViewRef.current || !scrollEnabled || !scrollViewMeasurements.current) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const currentScrollViewYOffset = Math.max(0, scrollViewYOffset.value); // Scroll up.
|
|
63
|
+
|
|
64
|
+
if (textInputOffset < currentScrollViewYOffset) {
|
|
65
|
+
scrollViewRef.current.scrollTo({
|
|
66
|
+
y: textInputOffset,
|
|
67
|
+
animated: true
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const availableScreenSpace = Math.abs(Math.floor(scrollViewMeasurements.current.height - (keyboardOffset + extraScrollHeight + caretHeight)));
|
|
73
|
+
const maxOffset = Math.floor(currentScrollViewYOffset + availableScreenSpace);
|
|
74
|
+
const isAtTheTop = textInputOffset < scrollViewMeasurements.current.y + insets; // Scroll down.
|
|
75
|
+
|
|
76
|
+
if (textInputOffset > maxOffset && !isAtTheTop) {
|
|
77
|
+
scrollViewRef.current.scrollTo({
|
|
78
|
+
y: textInputOffset - availableScreenSpace,
|
|
79
|
+
animated: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, [extraScrollHeight, insets, keyboardOffset, scrollEnabled, scrollViewMeasurements, scrollViewRef, scrollViewYOffset]);
|
|
83
|
+
return [scrollToTextInputOffset];
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=use-scroll-to-text-input.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js"],"names":["DEFAULT_FONT_SIZE","useScrollToTextInput","extraScrollHeight","keyboardOffset","scrollEnabled","scrollViewMeasurements","scrollViewRef","scrollViewYOffset","top","bottom","insets","scrollToTextInputOffset","caret","textInputOffset","caretHeight","current","currentScrollViewYOffset","Math","max","value","scrollTo","y","animated","availableScreenSpace","abs","floor","height","maxOffset","isAtTheTop"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAGA,MAAMA,iBAAiB,GAAG,EAA1B;AAEA;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,oBAAT,CACdC,iBADc,EAEdC,cAFc,EAGdC,aAHc,EAIdC,sBAJc,EAKdC,aALc,EAMdC,iBANc,EAOb;AACD,QAAM;AAAEC,IAAAA,GAAF;AAAOC,IAAAA;AAAP,MAAkB,oDAAxB;AACA,QAAMC,MAAM,GAAGF,GAAG,GAAGC,MAArB;AAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,QAAME,uBAAuB,GAAG,0BAC/B,CAAEC,KAAF,EAASC,eAAT,KAA8B;AAC7B,UAAM;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BAAF,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\n\nconst DEFAULT_FONT_SIZE = 16;\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n/** @typedef {import('react-native-reanimated').SharedValue} SharedValue */\n/**\n * Hook to scroll to the currently focused TextInput\n * depending on where the caret is placed taking into\n * account the Keyboard and the Header.\n *\n * @param {number} extraScrollHeight Extra space to not overlap the content.\n * @param {number} keyboardOffset Keyboard space offset.\n * @param {boolean} scrollEnabled Whether the scroll is enabled or not.\n * @param {RefObject} scrollViewMeasurements ScrollView Layout measurements.\n * @param {RefObject} scrollViewRef ScrollView reference.\n * @param {SharedValue} scrollViewYOffset Current offset position of the ScrollView.\n * @return {Function[]} Function to scroll to the current TextInput's offset.\n */\nexport default function useScrollToTextInput(\n\textraScrollHeight,\n\tkeyboardOffset,\n\tscrollEnabled,\n\tscrollViewMeasurements,\n\tscrollViewRef,\n\tscrollViewYOffset\n) {\n\tconst { top, bottom } = useSafeAreaInsets();\n\tconst insets = top + bottom;\n\n\t/**\n\t * Function to scroll to the current TextInput's offset.\n\t *\n\t * @param {Object} caret The caret position data of the currently focused TextInput.\n\t * @param {number} caret.caretHeight The height of the caret.\n\t * @param {number} textInputOffset The offset calculated with the caret's Y coordinate + the\n\t * TextInput's Y coord or height value.\n\t */\n\tconst scrollToTextInputOffset = useCallback(\n\t\t( caret, textInputOffset ) => {\n\t\t\tconst { caretHeight = DEFAULT_FONT_SIZE } = caret ?? {};\n\n\t\t\tif (\n\t\t\t\t! scrollViewRef.current ||\n\t\t\t\t! scrollEnabled ||\n\t\t\t\t! scrollViewMeasurements.current\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst currentScrollViewYOffset = Math.max(\n\t\t\t\t0,\n\t\t\t\tscrollViewYOffset.value\n\t\t\t);\n\n\t\t\t// Scroll up.\n\t\t\tif ( textInputOffset < currentScrollViewYOffset ) {\n\t\t\t\tscrollViewRef.current.scrollTo( {\n\t\t\t\t\ty: textInputOffset,\n\t\t\t\t\tanimated: true,\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst availableScreenSpace = Math.abs(\n\t\t\t\tMath.floor(\n\t\t\t\t\tscrollViewMeasurements.current.height -\n\t\t\t\t\t\t( keyboardOffset + extraScrollHeight + caretHeight )\n\t\t\t\t)\n\t\t\t);\n\t\t\tconst maxOffset = Math.floor(\n\t\t\t\tcurrentScrollViewYOffset + availableScreenSpace\n\t\t\t);\n\n\t\t\tconst isAtTheTop =\n\t\t\t\ttextInputOffset < scrollViewMeasurements.current.y + insets;\n\n\t\t\t// Scroll down.\n\t\t\tif ( textInputOffset > maxOffset && ! isAtTheTop ) {\n\t\t\t\tscrollViewRef.current.scrollTo( {\n\t\t\t\t\ty: textInputOffset - availableScreenSpace,\n\t\t\t\t\tanimated: true,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\textraScrollHeight,\n\t\t\tinsets,\n\t\t\tkeyboardOffset,\n\t\t\tscrollEnabled,\n\t\t\tscrollViewMeasurements,\n\t\t\tscrollViewRef,\n\t\t\tscrollViewYOffset,\n\t\t]\n\t);\n\n\treturn [ scrollToTextInputOffset ];\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useTextInputCaretPosition;
|
|
9
|
+
|
|
10
|
+
var _reactNativeAztec = _interopRequireDefault(require("@wordpress/react-native-aztec"));
|
|
11
|
+
|
|
12
|
+
var _element = require("@wordpress/element");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hook that listens to caret changes from AztecView TextInputs.
|
|
20
|
+
*
|
|
21
|
+
* @param {boolean} scrollEnabled Whether the scroll is enabled or not.
|
|
22
|
+
* @return {[number]} Current caret's data.
|
|
23
|
+
*/
|
|
24
|
+
function useTextInputCaretPosition(scrollEnabled) {
|
|
25
|
+
const [currentCaretData, setCurrentCaretData] = (0, _element.useState)();
|
|
26
|
+
const onCaretChange = (0, _element.useCallback)(caret => {
|
|
27
|
+
setCurrentCaretData(caret);
|
|
28
|
+
}, []);
|
|
29
|
+
(0, _element.useEffect)(() => {
|
|
30
|
+
if (scrollEnabled) {
|
|
31
|
+
_reactNativeAztec.default.InputState.addCaretChangeListener(onCaretChange);
|
|
32
|
+
} else {
|
|
33
|
+
_reactNativeAztec.default.InputState.removeCaretChangeListener(onCaretChange);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
if (scrollEnabled) {
|
|
38
|
+
_reactNativeAztec.default.InputState.removeCaretChangeListener(onCaretChange);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, [scrollEnabled, onCaretChange]);
|
|
42
|
+
return [currentCaretData];
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=use-text-input-caret-position.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js"],"names":["useTextInputCaretPosition","scrollEnabled","currentCaretData","setCurrentCaretData","onCaretChange","caret","RCTAztecView","InputState","addCaretChangeListener","removeCaretChangeListener"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,yBAAT,CAAoCC,aAApC,EAAoD;AAClE,QAAM,CAAEC,gBAAF,EAAoBC,mBAApB,IAA4C,wBAAlD;AAEA,QAAMC,aAAa,GAAG,0BAAeC,KAAF,IAAa;AAC/CF,IAAAA,mBAAmB,CAAEE,KAAF,CAAnB;AACA,GAFqB,EAEnB,EAFmB,CAAtB;AAIA,0BAAW,MAAM;AAChB,QAAKJ,aAAL,EAAqB;AACpBK,gCAAaC,UAAb,CAAwBC,sBAAxB,CAAgDJ,aAAhD;AACA,KAFD,MAEO;AACNE,gCAAaC,UAAb,CAAwBE,yBAAxB,CAAmDL,aAAnD;AACA;;AAED,WAAO,MAAM;AACZ,UAAKH,aAAL,EAAqB;AACpBK,kCAAaC,UAAb,CAAwBE,yBAAxB,CACCL,aADD;AAGA;AACD,KAND;AAOA,GAdD,EAcG,CAAEH,aAAF,EAAiBG,aAAjB,CAdH;AAeA,SAAO,CAAEF,gBAAF,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport RCTAztecView from '@wordpress/react-native-aztec';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\n\n/**\n * Hook that listens to caret changes from AztecView TextInputs.\n *\n * @param {boolean} scrollEnabled Whether the scroll is enabled or not.\n * @return {[number]} Current caret's data.\n */\nexport default function useTextInputCaretPosition( scrollEnabled ) {\n\tconst [ currentCaretData, setCurrentCaretData ] = useState();\n\n\tconst onCaretChange = useCallback( ( caret ) => {\n\t\tsetCurrentCaretData( caret );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( scrollEnabled ) {\n\t\t\tRCTAztecView.InputState.addCaretChangeListener( onCaretChange );\n\t\t} else {\n\t\t\tRCTAztecView.InputState.removeCaretChangeListener( onCaretChange );\n\t\t}\n\n\t\treturn () => {\n\t\t\tif ( scrollEnabled ) {\n\t\t\t\tRCTAztecView.InputState.removeCaretChangeListener(\n\t\t\t\t\tonCaretChange\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, [ scrollEnabled, onCaretChange ] );\n\treturn [ currentCaretData ];\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useTextInputOffset;
|
|
9
|
+
|
|
10
|
+
var _reactNativeAztec = _interopRequireDefault(require("@wordpress/react-native-aztec"));
|
|
11
|
+
|
|
12
|
+
var _element = require("@wordpress/element");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('@wordpress/element').RefObject} RefObject */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hook that calculates the currently focused TextInput's current
|
|
22
|
+
* caret Y coordinate position.
|
|
23
|
+
*
|
|
24
|
+
* @param {boolean} scrollEnabled Whether the scroll is enabled or not.
|
|
25
|
+
* @param {RefObject} scrollViewRef ScrollView reference.
|
|
26
|
+
* @return {[Function]} Function to get the current TextInput's offset.
|
|
27
|
+
*/
|
|
28
|
+
function useTextInputOffset(scrollEnabled, scrollViewRef) {
|
|
29
|
+
const getTextInputOffset = (0, _element.useCallback)(async caret => {
|
|
30
|
+
const {
|
|
31
|
+
caretY = null
|
|
32
|
+
} = caret !== null && caret !== void 0 ? caret : {};
|
|
33
|
+
|
|
34
|
+
const textInput = _reactNativeAztec.default.InputState.getCurrentFocusedElement();
|
|
35
|
+
|
|
36
|
+
return new Promise(resolve => {
|
|
37
|
+
if (scrollViewRef.current && textInput && scrollEnabled && caretY !== null) {
|
|
38
|
+
textInput.measureLayout(scrollViewRef.current, (_x, y, _width, height) => {
|
|
39
|
+
const caretYOffset = // For cases where the caretY value is -1
|
|
40
|
+
// we use the y + height value, e.g the current
|
|
41
|
+
// character index is not valid or out of bounds
|
|
42
|
+
// see https://github.com/wordpress-mobile/AztecEditor-iOS/blob/4d0522d67b0056ac211466caaa76936cc5b4f947/Aztec/Classes/TextKit/TextView.swift#L762
|
|
43
|
+
caretY >= 0 && caretY < height ? y + caretY : y + height;
|
|
44
|
+
resolve(Math.round(Math.abs(caretYOffset)));
|
|
45
|
+
}, () => resolve(null));
|
|
46
|
+
} else {
|
|
47
|
+
resolve(null);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}, [scrollEnabled, scrollViewRef]);
|
|
51
|
+
return [getTextInputOffset];
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=use-text-input-offset.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js"],"names":["useTextInputOffset","scrollEnabled","scrollViewRef","getTextInputOffset","caret","caretY","textInput","RCTAztecView","InputState","getCurrentFocusedElement","Promise","resolve","current","measureLayout","_x","y","_width","height","caretYOffset","Math","round","abs"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,kBAAT,CAA6BC,aAA7B,EAA4CC,aAA5C,EAA4D;AAC1E,QAAMC,kBAAkB,GAAG,0BAC1B,MAAQC,KAAR,IAAmB;AAClB,UAAM;AAAEC,MAAAA,MAAM,GAAG;AAAX,QAAoBD,KAApB,aAAoBA,KAApB,cAAoBA,KAApB,GAA6B,EAAnC;;AACA,UAAME,SAAS,GACdC,0BAAaC,UAAb,CAAwBC,wBAAxB,EADD;;AAGA,WAAO,IAAIC,OAAJ,CAAeC,OAAF,IAAe;AAClC,UACCT,aAAa,CAACU,OAAd,IACAN,SADA,IAEAL,aAFA,IAGAI,MAAM,KAAK,IAJZ,EAKE;AACDC,QAAAA,SAAS,CAACO,aAAV,CACCX,aAAa,CAACU,OADf,EAEC,CAAEE,EAAF,EAAMC,CAAN,EAASC,MAAT,EAAiBC,MAAjB,KAA6B;AAC5B,gBAAMC,YAAY,GACjB;AACA;AACA;AACA;AACAb,UAAAA,MAAM,IAAI,CAAV,IAAeA,MAAM,GAAGY,MAAxB,GACGF,CAAC,GAAGV,MADP,GAEGU,CAAC,GAAGE,MAPR;AAQAN,UAAAA,OAAO,CAAEQ,IAAI,CAACC,KAAL,CAAYD,IAAI,CAACE,GAAL,CAAUH,YAAV,CAAZ,CAAF,CAAP;AACA,SAZF,EAaC,MAAMP,OAAO,CAAE,IAAF,CAbd;AAeA,OArBD,MAqBO;AACNA,QAAAA,OAAO,CAAE,IAAF,CAAP;AACA;AACD,KAzBM,CAAP;AA0BA,GAhCyB,EAiC1B,CAAEV,aAAF,EAAiBC,aAAjB,CAjC0B,CAA3B;AAoCA,SAAO,CAAEC,kBAAF,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport RCTAztecView from '@wordpress/react-native-aztec';\nimport { useCallback } from '@wordpress/element';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n/**\n * Hook that calculates the currently focused TextInput's current\n * caret Y coordinate position.\n *\n * @param {boolean} scrollEnabled Whether the scroll is enabled or not.\n * @param {RefObject} scrollViewRef ScrollView reference.\n * @return {[Function]} Function to get the current TextInput's offset.\n */\nexport default function useTextInputOffset( scrollEnabled, scrollViewRef ) {\n\tconst getTextInputOffset = useCallback(\n\t\tasync ( caret ) => {\n\t\t\tconst { caretY = null } = caret ?? {};\n\t\t\tconst textInput =\n\t\t\t\tRCTAztecView.InputState.getCurrentFocusedElement();\n\n\t\t\treturn new Promise( ( resolve ) => {\n\t\t\t\tif (\n\t\t\t\t\tscrollViewRef.current &&\n\t\t\t\t\ttextInput &&\n\t\t\t\t\tscrollEnabled &&\n\t\t\t\t\tcaretY !== null\n\t\t\t\t) {\n\t\t\t\t\ttextInput.measureLayout(\n\t\t\t\t\t\tscrollViewRef.current,\n\t\t\t\t\t\t( _x, y, _width, height ) => {\n\t\t\t\t\t\t\tconst caretYOffset =\n\t\t\t\t\t\t\t\t// For cases where the caretY value is -1\n\t\t\t\t\t\t\t\t// we use the y + height value, e.g the current\n\t\t\t\t\t\t\t\t// character index is not valid or out of bounds\n\t\t\t\t\t\t\t\t// see https://github.com/wordpress-mobile/AztecEditor-iOS/blob/4d0522d67b0056ac211466caaa76936cc5b4f947/Aztec/Classes/TextKit/TextView.swift#L762\n\t\t\t\t\t\t\t\tcaretY >= 0 && caretY < height\n\t\t\t\t\t\t\t\t\t? y + caretY\n\t\t\t\t\t\t\t\t\t: y + height;\n\t\t\t\t\t\t\tresolve( Math.round( Math.abs( caretYOffset ) ) );\n\t\t\t\t\t\t},\n\t\t\t\t\t\t() => resolve( null )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tresolve( null );\n\t\t\t\t}\n\t\t\t} );\n\t\t},\n\t\t[ scrollEnabled, scrollViewRef ]\n\t);\n\n\treturn [ getTextInputOffset ];\n}\n"]}
|
|
@@ -60,6 +60,8 @@ const Segment = _ref => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const SegmentedControls = _ref2 => {
|
|
63
|
+
var _segmentsDimensions$a, _segmentsDimensions$a2;
|
|
64
|
+
|
|
63
65
|
let {
|
|
64
66
|
segments,
|
|
65
67
|
segmentHandler,
|
|
@@ -130,8 +132,8 @@ const SegmentedControls = _ref2 => {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
const selectedStyle = (0, _compose.usePreferredColorSchemeStyle)(_style.default.selected, _style.default.selectedDark);
|
|
133
|
-
const width = segmentsDimensions[activeSegmentIndex].width;
|
|
134
|
-
const height = segmentsDimensions[activeSegmentIndex].height;
|
|
135
|
+
const width = (_segmentsDimensions$a = segmentsDimensions[activeSegmentIndex]) === null || _segmentsDimensions$a === void 0 ? void 0 : _segmentsDimensions$a.width;
|
|
136
|
+
const height = (_segmentsDimensions$a2 = segmentsDimensions[activeSegmentIndex]) === null || _segmentsDimensions$a2 === void 0 ? void 0 : _segmentsDimensions$a2.height;
|
|
135
137
|
const outlineStyle = [_style.default.outline, isIOS && _style.default.outlineIOS];
|
|
136
138
|
return (0, _element.createElement)(_reactNative.View, {
|
|
137
139
|
style: _style.default.row
|