@amazon-devices/vega-carousel 0.1.3
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/LICENSE +7 -0
- package/README.md +0 -0
- package/dist/Carousel/Carousel.d.ts +16 -0
- package/dist/Carousel/Carousel.js +102 -0
- package/dist/Carousel/Utils.d.ts +4 -0
- package/dist/Carousel/Utils.js +35 -0
- package/dist/Carousel/index.d.ts +7 -0
- package/dist/Carousel/index.js +23 -0
- package/dist/Carousel/types.d.ts +406 -0
- package/dist/Carousel/types.js +2 -0
- package/dist/CarouselData/CarouselDataAdapter.d.ts +141 -0
- package/dist/CarouselData/CarouselDataAdapter.js +67 -0
- package/dist/CarouselData/CarouselDataResolver.d.ts +100 -0
- package/dist/CarouselData/CarouselDataResolver.js +224 -0
- package/dist/CarouselData/CarouselDataTypes.d.ts +280 -0
- package/dist/CarouselData/CarouselDataTypes.js +84 -0
- package/dist/CarouselData/index.d.ts +3 -0
- package/dist/CarouselData/index.js +24 -0
- package/dist/CarouselScrollable/CarouselScrollable.d.ts +67 -0
- package/dist/CarouselScrollable/CarouselScrollable.js +77 -0
- package/dist/CarouselScrollable/CarouselScrollableProps.d.ts +499 -0
- package/dist/CarouselScrollable/CarouselScrollableProps.js +211 -0
- package/dist/CarouselScrollable/CarouselScrollableRef.d.ts +80 -0
- package/dist/CarouselScrollable/CarouselScrollableRef.js +7 -0
- package/dist/CarouselScrollable/CarouselScrollableTypes.d.ts +224 -0
- package/dist/CarouselScrollable/CarouselScrollableTypes.js +116 -0
- package/dist/CarouselScrollable/CarouselSimple.d.ts +71 -0
- package/dist/CarouselScrollable/CarouselSimple.js +111 -0
- package/dist/CarouselScrollable/CarouselSimpleProps.d.ts +29 -0
- package/dist/CarouselScrollable/CarouselSimpleProps.js +7 -0
- package/dist/CarouselScrollable/index.d.ts +6 -0
- package/dist/CarouselScrollable/index.js +27 -0
- package/dist/CarouselScrollable/native/CarouselNativeHostComponent.d.ts +109 -0
- package/dist/CarouselScrollable/native/CarouselNativeHostComponent.js +82 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemHostComponent.d.ts +94 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemHostComponent.js +42 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemWrapper.d.ts +255 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemWrapper.js +276 -0
- package/dist/CarouselScrollable/native/CarouselNativeLogic.d.ts +209 -0
- package/dist/CarouselScrollable/native/CarouselNativeLogic.js +349 -0
- package/dist/CarouselScrollable/native/CarouselNativeWrapper.d.ts +68 -0
- package/dist/CarouselScrollable/native/CarouselNativeWrapper.js +164 -0
- package/dist/CarouselScrollable/native/index.d.ts +5 -0
- package/dist/CarouselScrollable/native/index.js +26 -0
- package/dist/CarouselScrollable/recyclerview/JSRecyclerViewList.d.ts +25 -0
- package/dist/CarouselScrollable/recyclerview/JSRecyclerViewList.js +150 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -0
- package/dist/kepler/aarch64-debug/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/aarch64-debug/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/aarch64-release/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/aarch64-release/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/armv7-debug/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/armv7-debug/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/armv7-release/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/armv7-release/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/tm-manifest.json +1 -0
- package/dist/kepler/x86_64-debug/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/x86_64-debug/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/x86_64-release/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/x86_64-release/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/utils/CarouselLogger.d.ts +295 -0
- package/dist/utils/CarouselLogger.js +370 -0
- package/dist/utils/CarouselReactNativeUtilities.d.ts +108 -0
- package/dist/utils/CarouselReactNativeUtilities.js +150 -0
- package/dist/utils/HelperTypes.d.ts +5 -0
- package/dist/utils/HelperTypes.js +7 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +24 -0
- package/package.json +1 -0
- package/react-native.config.js +22 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { HostComponent, StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import { ListOrientation, OnItemBindFunc, OnItemUnbindFunc, OnSelectionChangedCallback } from '../CarouselScrollableTypes';
|
|
3
|
+
import { CarouselNativeHostComponentSelectionChangedEvent, CarouselNativeHostComponentProps } from './CarouselNativeHostComponent';
|
|
4
|
+
import { CarouselDataAdapter, CarouselDataChange, CarouselResolvedDataValues, RenderItemFunc } from '../../CarouselData';
|
|
5
|
+
import { AnyValue } from '../../utils';
|
|
6
|
+
/**
|
|
7
|
+
* Auxiliary function use to invoke the `enableInputEvents` native function on
|
|
8
|
+
* the component's native layer.
|
|
9
|
+
*
|
|
10
|
+
* Although this function is simple enough that we could inline it in the
|
|
11
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
12
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
13
|
+
* us to write individual tests for it.
|
|
14
|
+
*
|
|
15
|
+
* For details about the native function itself, check the
|
|
16
|
+
* {@link CarouselScrollableRef.enableInputEvents} documentation.
|
|
17
|
+
*
|
|
18
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
19
|
+
* The `ref` object for the native component. It accepts the component or
|
|
20
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
21
|
+
* value.
|
|
22
|
+
* @param {boolean} enable Flag indicating if the list should handle input
|
|
23
|
+
* events or not.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link CarouselScrollableRef.enableInputEvents}
|
|
26
|
+
*/
|
|
27
|
+
export declare function callNativeEnableInputEvents(hostComponent: HostComponent<CarouselNativeHostComponentProps> | null, enable: boolean): void;
|
|
28
|
+
/**
|
|
29
|
+
* Auxiliary function use to invoke the `setSelectedItem` native function on
|
|
30
|
+
* the component's native layer.
|
|
31
|
+
*
|
|
32
|
+
* Although this function is simple enough that we could inline it in the
|
|
33
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
34
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
35
|
+
* us to write individual tests for it.
|
|
36
|
+
*
|
|
37
|
+
* For details about the native function itself, check the
|
|
38
|
+
* {@link CarouselScrollableRef.setSelectedItem} documentation.
|
|
39
|
+
*
|
|
40
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
41
|
+
* The `ref` object for the native component. It accepts the component or
|
|
42
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
43
|
+
* value.
|
|
44
|
+
* @param {number} index The data index of the item that should be selected
|
|
45
|
+
* after the scroll ends.
|
|
46
|
+
* @param {boolean} animated Optional flag indicating if the requested
|
|
47
|
+
* selection should be animated or not. It defaults to `false`.
|
|
48
|
+
|
|
49
|
+
*
|
|
50
|
+
* @see {@link CarouselScrollableRef.setSelectedItem}
|
|
51
|
+
*/
|
|
52
|
+
export declare function callNativeSetSelectedItem(hostComponent: HostComponent<CarouselNativeHostComponentProps> | null, index: number, animated?: boolean): void;
|
|
53
|
+
/**
|
|
54
|
+
* Auxiliary function use to invoke the `setOverflowItemsVisible` native
|
|
55
|
+
* function on the component's native layer.
|
|
56
|
+
*
|
|
57
|
+
* Although this function is simple enough that we could inline it in the
|
|
58
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
59
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
60
|
+
* us to write individual tests for it.
|
|
61
|
+
*
|
|
62
|
+
* For details about the native function itself, check the
|
|
63
|
+
* {@link CarouselScrollableRef.setOverflowItemsVisible} documentation.
|
|
64
|
+
*
|
|
65
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
66
|
+
* The `ref` object for the native component. It accepts the component or
|
|
67
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
68
|
+
* value.
|
|
69
|
+
* @param {boolean} visible Flag indicating if the _outer items_ should be
|
|
70
|
+
* hidden (`false`), or shown (`true`).
|
|
71
|
+
* @param {boolean} animated Indicates if the show/hide action should be
|
|
72
|
+
* animated or not.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link CarouselScrollableRef.setOverflowItemsVisible}
|
|
75
|
+
*/
|
|
76
|
+
export declare function callNativeSetOverflowItemsVisible(hostComponent: HostComponent<CarouselNativeHostComponentProps> | null, visible: boolean, animated?: boolean): void;
|
|
77
|
+
/**
|
|
78
|
+
* Auxiliary function use to invoke the `notifyDataChange` native function on
|
|
79
|
+
* the component's native layer.
|
|
80
|
+
*
|
|
81
|
+
* Although this function is simple enough that we could inline it in the
|
|
82
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
83
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
84
|
+
* us to write individual tests for it.
|
|
85
|
+
*
|
|
86
|
+
* For details about the native function itself, check the
|
|
87
|
+
* {@link CarouselScrollableRef.notifyDataChange} documentation.
|
|
88
|
+
*
|
|
89
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
90
|
+
* The `ref` object for the native component. It accepts the component or
|
|
91
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
92
|
+
* value.
|
|
93
|
+
* @param {Array<CarouselDataChange>} changes A list of all
|
|
94
|
+
* changes that happened to the backing data.
|
|
95
|
+
* @param {boolean} animated Flag indicating if the change operation should be
|
|
96
|
+
* animated or not.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link CarouselScrollableRef.notifyDataChange}
|
|
99
|
+
*/
|
|
100
|
+
export declare function callNativeNotifyDataChange(hostComponent: HostComponent<CarouselNativeHostComponentProps> | null, changes: Array<CarouselDataChange>, animated?: boolean): void;
|
|
101
|
+
export declare function callReset(hostComponent: HostComponent<CarouselNativeHostComponentProps> | null): void;
|
|
102
|
+
/**
|
|
103
|
+
* Helper function that can combine a base style object with a _row_ or _column_
|
|
104
|
+
* flex direction depending on the given `orientation`.
|
|
105
|
+
*
|
|
106
|
+
* @param {StyleProp<ViewStyle>} baseStyle The current style object to use as
|
|
107
|
+
* the base property.
|
|
108
|
+
* @param {ListOrientation} orientation The list component orientation used to
|
|
109
|
+
* define if we use a _row_ or a _column_ flex direction style.
|
|
110
|
+
*
|
|
111
|
+
* @return {StyleProp<ViewStyle>} Returns a combined style between the given
|
|
112
|
+
* `baseStyle` and a _row_ or _column_ flex direction.
|
|
113
|
+
*/
|
|
114
|
+
export declare function addFlexDirectionStyle(baseStyle: StyleProp<ViewStyle>, orientation: ListOrientation): StyleProp<ViewStyle>;
|
|
115
|
+
/**
|
|
116
|
+
* This function is the core logic to retrieve items on the {@link CarouselScrollable}
|
|
117
|
+
* initial render.
|
|
118
|
+
*
|
|
119
|
+
* It will try in different ways to get as many items as defined by the
|
|
120
|
+
* `dataLimit` argument.
|
|
121
|
+
*
|
|
122
|
+
* It only returns an array with fewer items than `dataLimit` if the given
|
|
123
|
+
* `adapter` does not have that many items.
|
|
124
|
+
*
|
|
125
|
+
* The overall workflow in this function is, as follows:
|
|
126
|
+
*
|
|
127
|
+
* 1. Get the item **at** the `initialIndex` position;
|
|
128
|
+
* 2. Get items **before** the `initialIndex` position so we have as many as
|
|
129
|
+
* `preferredBackCount`;
|
|
130
|
+
* 3. Get items **after** the `initialIndex` position until we have a total of
|
|
131
|
+
* `dataLimit` items, or the `adapter` has no more items;
|
|
132
|
+
* 4. If our array of items has fewer items than `dataLimit`, get items
|
|
133
|
+
* **before** the last item retrieved at step 2 until we have a total of
|
|
134
|
+
* `dataLimit` items, or the last item we retrieved was at position `0`;
|
|
135
|
+
*
|
|
136
|
+
* Internally, `getInitialData` uses the {@link resolveDataItems} function to
|
|
137
|
+
* guarantee that failed items are resolved (and accounted for) by the given
|
|
138
|
+
* adapter.
|
|
139
|
+
*
|
|
140
|
+
* @template ItemT The type of data items the list will use to render its items.
|
|
141
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
142
|
+
* or _stable IDs_) in the list;
|
|
143
|
+
*
|
|
144
|
+
* @param {CarouselDataAdapter<ItemT, KeyT>} adapter An object with the data access
|
|
145
|
+
* APIs that allow us to retrieve items from an external source.
|
|
146
|
+
* @param {RenderItemFunc<ItemT>} resolver
|
|
147
|
+
* @param {number} initialIndex
|
|
148
|
+
* @param {number} preferredBackCount
|
|
149
|
+
* @param {number} dataLimit
|
|
150
|
+
*/
|
|
151
|
+
export declare function getInitialData<ItemT, KeyT>(adapter: CarouselDataAdapter<ItemT, KeyT>, resolver: RenderItemFunc<ItemT>, initialIndex: number, preferredBackCount: number, dataLimit: number): Array<CarouselResolvedDataValues<KeyT>>;
|
|
152
|
+
/**
|
|
153
|
+
* Function to hoist the workflow logic used when the `onSelectionChanged` event
|
|
154
|
+
* happens.
|
|
155
|
+
*
|
|
156
|
+
* It checks if the required callback is present, and if it is, it will build
|
|
157
|
+
* the expected event out of the native one to pass it to the callback.
|
|
158
|
+
*
|
|
159
|
+
* @param {OnSelectionChangedCallback} callback The function to be called when
|
|
160
|
+
* the `onSelectionChanged` event happens.
|
|
161
|
+
* @param {CarouselNativeHostComponentSelectionChangedEvent} event The native
|
|
162
|
+
* event emitted by the native layer.
|
|
163
|
+
*/
|
|
164
|
+
export declare function triggerOnSelectionChangeCallback(callback: OnSelectionChangedCallback | undefined, event: CarouselNativeHostComponentSelectionChangedEvent): void;
|
|
165
|
+
/**
|
|
166
|
+
* Function to hoist the workflow logic used when the `onItemUnbind` event
|
|
167
|
+
* happens.
|
|
168
|
+
*
|
|
169
|
+
* It will provide a `storeData` function to the callback that can be used to
|
|
170
|
+
* save any arbitrary data for the outbound item that can be used again when
|
|
171
|
+
* the same item gets recycled back into the list.
|
|
172
|
+
*
|
|
173
|
+
* @template ItemT The type of the data object used as an _item_ in the list
|
|
174
|
+
* component.
|
|
175
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
176
|
+
* or _stable IDs_) in the list;
|
|
177
|
+
*
|
|
178
|
+
* @param {OnItemUnbindFunc<ItemT> | undefined} callback The function to be
|
|
179
|
+
* called when the `onItemUnbind` event happens.
|
|
180
|
+
* @param {CarouselDataAdapter<ItemT, KeyT>} adapter Data adapter to use to
|
|
181
|
+
* retrieve items and its stable ID.
|
|
182
|
+
* @param {Map<KeyT, any>} stateMap The map object that stores all the
|
|
183
|
+
* children's state on the list component.
|
|
184
|
+
* @param {number} itemIndex The data index for the item that is about to be
|
|
185
|
+
* unbound from its native frame.
|
|
186
|
+
*/
|
|
187
|
+
export declare function triggerOnItemUnbindCallback<ItemT, KeyT>(callback: OnItemUnbindFunc<ItemT> | undefined, adapter: CarouselDataAdapter<ItemT, KeyT>, stateMap: Map<KeyT, AnyValue>, itemIndex: number): void;
|
|
188
|
+
/**
|
|
189
|
+
* Function to hoist the workflow logic used when the `onItemBind` event
|
|
190
|
+
* happens.
|
|
191
|
+
*
|
|
192
|
+
* It will pass a previously stored item state to the callback if one was saved
|
|
193
|
+
* by calling the `storeState` function from the `onItemUnbind` event.
|
|
194
|
+
*
|
|
195
|
+
* @template ItemT The type of the data object used as an _item_ in the list
|
|
196
|
+
* component.
|
|
197
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
198
|
+
* or _stable IDs_) in the list;
|
|
199
|
+
*
|
|
200
|
+
* @param {OnItemBindFunc<ItemT> | undefined} callback The function to be called
|
|
201
|
+
* when the `onItemBind` event happens.
|
|
202
|
+
* @param {CarouselDataAdapter<ItemT, KeyT>} adapter Data adapter to use to
|
|
203
|
+
* retrieve items and its stable ID.
|
|
204
|
+
* @param {Map<KeyT, any>} stateMap The map object that stores all the
|
|
205
|
+
* children's state on the list component.
|
|
206
|
+
* @param {number} itemIndex The data index for the item that is about to be
|
|
207
|
+
* bound to its native frame.
|
|
208
|
+
*/
|
|
209
|
+
export declare function triggerOnItemBindCallback<ItemT, KeyT>(callback: OnItemBindFunc<ItemT> | undefined, adapter: CarouselDataAdapter<ItemT, KeyT>, stateMap: Map<KeyT, AnyValue>, itemIndex: number): void;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 - 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* PROPRIETARY/CONFIDENTIAL. USE IS SUBJECT TO LICENSE TERMS.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.triggerOnItemBindCallback = exports.triggerOnItemUnbindCallback = exports.triggerOnSelectionChangeCallback = exports.getInitialData = exports.addFlexDirectionStyle = exports.callReset = exports.callNativeNotifyDataChange = exports.callNativeSetOverflowItemsVisible = exports.callNativeSetSelectedItem = exports.callNativeEnableInputEvents = void 0;
|
|
9
|
+
const react_native_1 = require("react-native");
|
|
10
|
+
const CarouselScrollableTypes_1 = require("../CarouselScrollableTypes");
|
|
11
|
+
const CarouselNativeHostComponent_1 = require("./CarouselNativeHostComponent");
|
|
12
|
+
const CarouselData_1 = require("../../CarouselData");
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
/**
|
|
15
|
+
* Auxiliary function use to invoke the `enableInputEvents` native function on
|
|
16
|
+
* the component's native layer.
|
|
17
|
+
*
|
|
18
|
+
* Although this function is simple enough that we could inline it in the
|
|
19
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
20
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
21
|
+
* us to write individual tests for it.
|
|
22
|
+
*
|
|
23
|
+
* For details about the native function itself, check the
|
|
24
|
+
* {@link CarouselScrollableRef.enableInputEvents} documentation.
|
|
25
|
+
*
|
|
26
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
27
|
+
* The `ref` object for the native component. It accepts the component or
|
|
28
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
29
|
+
* value.
|
|
30
|
+
* @param {boolean} enable Flag indicating if the list should handle input
|
|
31
|
+
* events or not.
|
|
32
|
+
*
|
|
33
|
+
* @see {@link CarouselScrollableRef.enableInputEvents}
|
|
34
|
+
*/
|
|
35
|
+
function callNativeEnableInputEvents(hostComponent, enable) {
|
|
36
|
+
if (hostComponent) {
|
|
37
|
+
CarouselNativeHostComponent_1.CarouselNativeHostComponentCommands.enableInputEvents(hostComponent, enable);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.callNativeEnableInputEvents = callNativeEnableInputEvents;
|
|
41
|
+
/**
|
|
42
|
+
* Auxiliary function use to invoke the `setSelectedItem` native function on
|
|
43
|
+
* the component's native layer.
|
|
44
|
+
*
|
|
45
|
+
* Although this function is simple enough that we could inline it in the
|
|
46
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
47
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
48
|
+
* us to write individual tests for it.
|
|
49
|
+
*
|
|
50
|
+
* For details about the native function itself, check the
|
|
51
|
+
* {@link CarouselScrollableRef.setSelectedItem} documentation.
|
|
52
|
+
*
|
|
53
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
54
|
+
* The `ref` object for the native component. It accepts the component or
|
|
55
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
56
|
+
* value.
|
|
57
|
+
* @param {number} index The data index of the item that should be selected
|
|
58
|
+
* after the scroll ends.
|
|
59
|
+
* @param {boolean} animated Optional flag indicating if the requested
|
|
60
|
+
* selection should be animated or not. It defaults to `false`.
|
|
61
|
+
|
|
62
|
+
*
|
|
63
|
+
* @see {@link CarouselScrollableRef.setSelectedItem}
|
|
64
|
+
*/
|
|
65
|
+
function callNativeSetSelectedItem(hostComponent, index, animated) {
|
|
66
|
+
if (hostComponent) {
|
|
67
|
+
CarouselNativeHostComponent_1.CarouselNativeHostComponentCommands.setSelectedItem(hostComponent, index, animated === true);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.callNativeSetSelectedItem = callNativeSetSelectedItem;
|
|
71
|
+
/**
|
|
72
|
+
* Auxiliary function use to invoke the `setOverflowItemsVisible` native
|
|
73
|
+
* function on the component's native layer.
|
|
74
|
+
*
|
|
75
|
+
* Although this function is simple enough that we could inline it in the
|
|
76
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
77
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
78
|
+
* us to write individual tests for it.
|
|
79
|
+
*
|
|
80
|
+
* For details about the native function itself, check the
|
|
81
|
+
* {@link CarouselScrollableRef.setOverflowItemsVisible} documentation.
|
|
82
|
+
*
|
|
83
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
84
|
+
* The `ref` object for the native component. It accepts the component or
|
|
85
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
86
|
+
* value.
|
|
87
|
+
* @param {boolean} visible Flag indicating if the _outer items_ should be
|
|
88
|
+
* hidden (`false`), or shown (`true`).
|
|
89
|
+
* @param {boolean} animated Indicates if the show/hide action should be
|
|
90
|
+
* animated or not.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link CarouselScrollableRef.setOverflowItemsVisible}
|
|
93
|
+
*/
|
|
94
|
+
function callNativeSetOverflowItemsVisible(hostComponent, visible, animated) {
|
|
95
|
+
if (hostComponent) {
|
|
96
|
+
CarouselNativeHostComponent_1.CarouselNativeHostComponentCommands.setOverflowItemsVisible(hostComponent, visible, animated === true);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.callNativeSetOverflowItemsVisible = callNativeSetOverflowItemsVisible;
|
|
100
|
+
/**
|
|
101
|
+
* Auxiliary function use to invoke the `notifyDataChange` native function on
|
|
102
|
+
* the component's native layer.
|
|
103
|
+
*
|
|
104
|
+
* Although this function is simple enough that we could inline it in the
|
|
105
|
+
* {@link CarouselNativeWrapper} component function, we decided to externalize
|
|
106
|
+
* it with dependency inversion to make the component code cleaner, and to allow
|
|
107
|
+
* us to write individual tests for it.
|
|
108
|
+
*
|
|
109
|
+
* For details about the native function itself, check the
|
|
110
|
+
* {@link CarouselScrollableRef.notifyDataChange} documentation.
|
|
111
|
+
*
|
|
112
|
+
* @param {HostComponent<CarouselNativeHostComponentProps> | null} hostComponent
|
|
113
|
+
* The `ref` object for the native component. It accepts the component or
|
|
114
|
+
* `null` because such a `ref` is usually created with the `null` initial
|
|
115
|
+
* value.
|
|
116
|
+
* @param {Array<CarouselDataChange>} changes A list of all
|
|
117
|
+
* changes that happened to the backing data.
|
|
118
|
+
* @param {boolean} animated Flag indicating if the change operation should be
|
|
119
|
+
* animated or not.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link CarouselScrollableRef.notifyDataChange}
|
|
122
|
+
*/
|
|
123
|
+
function callNativeNotifyDataChange(hostComponent, changes, animated) {
|
|
124
|
+
if (hostComponent) {
|
|
125
|
+
CarouselNativeHostComponent_1.CarouselNativeHostComponentCommands.notifyDataChange(hostComponent, changes, animated === true);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.callNativeNotifyDataChange = callNativeNotifyDataChange;
|
|
129
|
+
function callReset(hostComponent) {
|
|
130
|
+
if (hostComponent) {
|
|
131
|
+
CarouselNativeHostComponent_1.CarouselNativeHostComponentCommands.reset(hostComponent);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.callReset = callReset;
|
|
135
|
+
/** Helper style containing a _row_ flex direction. */
|
|
136
|
+
const FlexDirectionRow = { flexDirection: 'row' };
|
|
137
|
+
/** Helper style containing a _column_ flex direction. */
|
|
138
|
+
const FlexDirectionColumn = { flexDirection: 'column' };
|
|
139
|
+
/**
|
|
140
|
+
* Helper function that can combine a base style object with a _row_ or _column_
|
|
141
|
+
* flex direction depending on the given `orientation`.
|
|
142
|
+
*
|
|
143
|
+
* @param {StyleProp<ViewStyle>} baseStyle The current style object to use as
|
|
144
|
+
* the base property.
|
|
145
|
+
* @param {ListOrientation} orientation The list component orientation used to
|
|
146
|
+
* define if we use a _row_ or a _column_ flex direction style.
|
|
147
|
+
*
|
|
148
|
+
* @return {StyleProp<ViewStyle>} Returns a combined style between the given
|
|
149
|
+
* `baseStyle` and a _row_ or _column_ flex direction.
|
|
150
|
+
*/
|
|
151
|
+
function addFlexDirectionStyle(baseStyle, orientation) {
|
|
152
|
+
return react_native_1.StyleSheet.compose(baseStyle, orientation === CarouselScrollableTypes_1.ListOrientation.HORIZONTAL
|
|
153
|
+
? FlexDirectionRow
|
|
154
|
+
: FlexDirectionColumn);
|
|
155
|
+
}
|
|
156
|
+
exports.addFlexDirectionStyle = addFlexDirectionStyle;
|
|
157
|
+
/**
|
|
158
|
+
* This function is the core logic to retrieve items on the {@link CarouselScrollable}
|
|
159
|
+
* initial render.
|
|
160
|
+
*
|
|
161
|
+
* It will try in different ways to get as many items as defined by the
|
|
162
|
+
* `dataLimit` argument.
|
|
163
|
+
*
|
|
164
|
+
* It only returns an array with fewer items than `dataLimit` if the given
|
|
165
|
+
* `adapter` does not have that many items.
|
|
166
|
+
*
|
|
167
|
+
* The overall workflow in this function is, as follows:
|
|
168
|
+
*
|
|
169
|
+
* 1. Get the item **at** the `initialIndex` position;
|
|
170
|
+
* 2. Get items **before** the `initialIndex` position so we have as many as
|
|
171
|
+
* `preferredBackCount`;
|
|
172
|
+
* 3. Get items **after** the `initialIndex` position until we have a total of
|
|
173
|
+
* `dataLimit` items, or the `adapter` has no more items;
|
|
174
|
+
* 4. If our array of items has fewer items than `dataLimit`, get items
|
|
175
|
+
* **before** the last item retrieved at step 2 until we have a total of
|
|
176
|
+
* `dataLimit` items, or the last item we retrieved was at position `0`;
|
|
177
|
+
*
|
|
178
|
+
* Internally, `getInitialData` uses the {@link resolveDataItems} function to
|
|
179
|
+
* guarantee that failed items are resolved (and accounted for) by the given
|
|
180
|
+
* adapter.
|
|
181
|
+
*
|
|
182
|
+
* @template ItemT The type of data items the list will use to render its items.
|
|
183
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
184
|
+
* or _stable IDs_) in the list;
|
|
185
|
+
*
|
|
186
|
+
* @param {CarouselDataAdapter<ItemT, KeyT>} adapter An object with the data access
|
|
187
|
+
* APIs that allow us to retrieve items from an external source.
|
|
188
|
+
* @param {RenderItemFunc<ItemT>} resolver
|
|
189
|
+
* @param {number} initialIndex
|
|
190
|
+
* @param {number} preferredBackCount
|
|
191
|
+
* @param {number} dataLimit
|
|
192
|
+
*/
|
|
193
|
+
function getInitialData(adapter, resolver, initialIndex, preferredBackCount, dataLimit) {
|
|
194
|
+
const initialData = [];
|
|
195
|
+
let startIndex = initialIndex;
|
|
196
|
+
let endIndex = initialIndex;
|
|
197
|
+
// To get our initial data set without information about how many items are
|
|
198
|
+
// available, we'll need to preemptively request items from our data adapter,
|
|
199
|
+
// and stop when there is no more data available, or we got `maxRenderItems`
|
|
200
|
+
// items.
|
|
201
|
+
// We start by pulling the item in the selected index position...
|
|
202
|
+
(0, CarouselData_1.resolveDataItems)(adapter, resolver, (0, CarouselData_1.dataReadAtTargetConfig)(initialIndex), (resolved) => {
|
|
203
|
+
initialData.push(resolved);
|
|
204
|
+
});
|
|
205
|
+
// If our adapter did not return an item for the initial position, we can
|
|
206
|
+
// assume this list is empty for now.
|
|
207
|
+
if (initialData.length > 0) {
|
|
208
|
+
// If we have the initial index, we try to get items to place **before** the
|
|
209
|
+
// selected one; we do this because of the `scrollOffsetCount` property that
|
|
210
|
+
// limits how many items we can have before the selected one, and not after
|
|
211
|
+
// it.
|
|
212
|
+
startIndex =
|
|
213
|
+
(0, CarouselData_1.resolveDataItems)(adapter, resolver, (0, CarouselData_1.dataReadBackwardsConfig)(initialIndex - 1, index => index >= 0 &&
|
|
214
|
+
initialData.length <= dataLimit &&
|
|
215
|
+
initialIndex - index <= preferredBackCount), (resolved) => {
|
|
216
|
+
initialData.unshift(resolved);
|
|
217
|
+
}) ?? initialIndex;
|
|
218
|
+
// Once we have all the items before the selected one, we're free to request
|
|
219
|
+
// the rest of the items in our initial data set after the selected item.
|
|
220
|
+
endIndex =
|
|
221
|
+
(0, CarouselData_1.resolveDataItems)(adapter, resolver, (0, CarouselData_1.dataReadForwardConfig)(initialIndex + 1, () => initialData.length < dataLimit), (resolved) => {
|
|
222
|
+
initialData.push(resolved);
|
|
223
|
+
}) ?? initialIndex;
|
|
224
|
+
// Sometimes, after retrieving items before and after the selected one, we
|
|
225
|
+
// still don't have enough items to match `renderedItemsCount` count, and when
|
|
226
|
+
// this happens, there are two possible reasons:
|
|
227
|
+
// 1. There is no more data available in the data set;
|
|
228
|
+
// 2. The `initialStartIndex` is close to the end of the data set;
|
|
229
|
+
// In the first case, there is nothing for us to do, but on the second one,
|
|
230
|
+
// we should try to go backwards while we still have data to fill our
|
|
231
|
+
// initial data array.
|
|
232
|
+
if (endIndex - startIndex < dataLimit - 1) {
|
|
233
|
+
(0, CarouselData_1.resolveDataItems)(adapter, resolver, (0, CarouselData_1.dataReadBackwardsConfig)(startIndex - 1, index => index >= 0 && initialData.length < dataLimit), (resolved) => {
|
|
234
|
+
initialData.unshift(resolved);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return initialData;
|
|
239
|
+
}
|
|
240
|
+
exports.getInitialData = getInitialData;
|
|
241
|
+
/**
|
|
242
|
+
* Function to hoist the workflow logic used when the `onSelectionChanged` event
|
|
243
|
+
* happens.
|
|
244
|
+
*
|
|
245
|
+
* It checks if the required callback is present, and if it is, it will build
|
|
246
|
+
* the expected event out of the native one to pass it to the callback.
|
|
247
|
+
*
|
|
248
|
+
* @param {OnSelectionChangedCallback} callback The function to be called when
|
|
249
|
+
* the `onSelectionChanged` event happens.
|
|
250
|
+
* @param {CarouselNativeHostComponentSelectionChangedEvent} event The native
|
|
251
|
+
* event emitted by the native layer.
|
|
252
|
+
*/
|
|
253
|
+
function triggerOnSelectionChangeCallback(callback, event) {
|
|
254
|
+
if (callback) {
|
|
255
|
+
const selectionChangedEvent = {
|
|
256
|
+
selectedIndex: event.nativeEvent.selectedIndex,
|
|
257
|
+
renderedRange: {
|
|
258
|
+
start: event.nativeEvent.renderFirstIndex,
|
|
259
|
+
end: event.nativeEvent.renderLastIndex,
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
callback(selectionChangedEvent);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
exports.triggerOnSelectionChangeCallback = triggerOnSelectionChangeCallback;
|
|
266
|
+
/**
|
|
267
|
+
* Function to hoist the workflow logic used when the `onItemUnbind` event
|
|
268
|
+
* happens.
|
|
269
|
+
*
|
|
270
|
+
* It will provide a `storeData` function to the callback that can be used to
|
|
271
|
+
* save any arbitrary data for the outbound item that can be used again when
|
|
272
|
+
* the same item gets recycled back into the list.
|
|
273
|
+
*
|
|
274
|
+
* @template ItemT The type of the data object used as an _item_ in the list
|
|
275
|
+
* component.
|
|
276
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
277
|
+
* or _stable IDs_) in the list;
|
|
278
|
+
*
|
|
279
|
+
* @param {OnItemUnbindFunc<ItemT> | undefined} callback The function to be
|
|
280
|
+
* called when the `onItemUnbind` event happens.
|
|
281
|
+
* @param {CarouselDataAdapter<ItemT, KeyT>} adapter Data adapter to use to
|
|
282
|
+
* retrieve items and its stable ID.
|
|
283
|
+
* @param {Map<KeyT, any>} stateMap The map object that stores all the
|
|
284
|
+
* children's state on the list component.
|
|
285
|
+
* @param {number} itemIndex The data index for the item that is about to be
|
|
286
|
+
* unbound from its native frame.
|
|
287
|
+
*/
|
|
288
|
+
function triggerOnItemUnbindCallback(callback, adapter, stateMap, itemIndex) {
|
|
289
|
+
if (callback) {
|
|
290
|
+
const item = adapter.getItem(itemIndex);
|
|
291
|
+
if (item !== undefined) {
|
|
292
|
+
const key = adapter.getItemKey(item, itemIndex);
|
|
293
|
+
if (key !== undefined) {
|
|
294
|
+
callback(item, itemIndex, (data) => {
|
|
295
|
+
stateMap.set(key, data);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
utils_1.Log.d('The item at position {0} is being unbound, but it does not have a KEY to store its state', itemIndex);
|
|
300
|
+
callback(item, itemIndex, () => { });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
utils_1.Log.d('There was a request to unbind item at position {0} but there is no item in that position', itemIndex);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
exports.triggerOnItemUnbindCallback = triggerOnItemUnbindCallback;
|
|
309
|
+
/**
|
|
310
|
+
* Function to hoist the workflow logic used when the `onItemBind` event
|
|
311
|
+
* happens.
|
|
312
|
+
*
|
|
313
|
+
* It will pass a previously stored item state to the callback if one was saved
|
|
314
|
+
* by calling the `storeState` function from the `onItemUnbind` event.
|
|
315
|
+
*
|
|
316
|
+
* @template ItemT The type of the data object used as an _item_ in the list
|
|
317
|
+
* component.
|
|
318
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
319
|
+
* or _stable IDs_) in the list;
|
|
320
|
+
*
|
|
321
|
+
* @param {OnItemBindFunc<ItemT> | undefined} callback The function to be called
|
|
322
|
+
* when the `onItemBind` event happens.
|
|
323
|
+
* @param {CarouselDataAdapter<ItemT, KeyT>} adapter Data adapter to use to
|
|
324
|
+
* retrieve items and its stable ID.
|
|
325
|
+
* @param {Map<KeyT, any>} stateMap The map object that stores all the
|
|
326
|
+
* children's state on the list component.
|
|
327
|
+
* @param {number} itemIndex The data index for the item that is about to be
|
|
328
|
+
* bound to its native frame.
|
|
329
|
+
*/
|
|
330
|
+
function triggerOnItemBindCallback(callback, adapter, stateMap, itemIndex) {
|
|
331
|
+
if (callback) {
|
|
332
|
+
const item = adapter.getItem(itemIndex);
|
|
333
|
+
if (item !== undefined) {
|
|
334
|
+
const key = adapter.getItemKey(item, itemIndex);
|
|
335
|
+
let itemState;
|
|
336
|
+
if (key !== undefined) {
|
|
337
|
+
itemState = stateMap.get(key);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
utils_1.Log.d('The item at position {0} is being bound, but it does not have a KEY to retrieve its past state', itemIndex);
|
|
341
|
+
}
|
|
342
|
+
callback(item, itemIndex, itemState);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
utils_1.Log.d('There was a request to bind item at position {0} but there is no item in that position', itemIndex);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
exports.triggerOnItemBindCallback = triggerOnItemBindCallback;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CarouselScrollableProps } from '../CarouselScrollableProps';
|
|
3
|
+
import type { CarouselScrollableRef } from '../CarouselScrollableRef';
|
|
4
|
+
/**
|
|
5
|
+
* Internal implementation of the {@link CarouselNativeWrapper} component.
|
|
6
|
+
*
|
|
7
|
+
* Check the {@link CarouselNativeWrapper} documentation for details on this component.
|
|
8
|
+
*
|
|
9
|
+
* @template ItemT The type of data items the list will use to render its items.
|
|
10
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
11
|
+
* or _stable IDs_) in the list;
|
|
12
|
+
*
|
|
13
|
+
* @see {@link CarouselNativeWrapper}
|
|
14
|
+
*/
|
|
15
|
+
declare function CarouselNativeInner<ItemT, KeyT = React.Key>(rawProps: CarouselScrollableProps<ItemT, KeyT>, ref?: React.Ref<CarouselScrollableRef>): React.JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* The Kepler {@link CarouselScrollable} definition.
|
|
18
|
+
*
|
|
19
|
+
* This implementation of the list uses a Native Turbo Module to control user
|
|
20
|
+
* interaction, animations, and native frame recycling.
|
|
21
|
+
*
|
|
22
|
+
* This native layer only has information about indexes; therefore, when it
|
|
23
|
+
* initially renders, it will have the knowledge about its rendered items and
|
|
24
|
+
* nothing more.
|
|
25
|
+
*
|
|
26
|
+
* As the user interacts with the component, the native layer will send messages
|
|
27
|
+
* to the JS components, and expect updates from it about any change occurring
|
|
28
|
+
* on the data backing the scrollable list.
|
|
29
|
+
*
|
|
30
|
+
* Check the documentation of {@link CarouselScrollableRef} for details about the
|
|
31
|
+
* information that the user can send to the native side.
|
|
32
|
+
*
|
|
33
|
+
* If you're required to have an encapsulated object to handle the data side of
|
|
34
|
+
* your application, check the {@link CarouselDataAdapter} documentation for a
|
|
35
|
+
* contract you can implement and use with this component.
|
|
36
|
+
*
|
|
37
|
+
* To avoid problems when using the list component, you need to understand its
|
|
38
|
+
* relation with your data.
|
|
39
|
+
*
|
|
40
|
+
* At no point, the scrollable will have any information about the _things_ your
|
|
41
|
+
* application is displaying in it, and it will never try to infer any change on
|
|
42
|
+
* your data.
|
|
43
|
+
*
|
|
44
|
+
* The user of this component is the sole owner of the data backing it, and as
|
|
45
|
+
* such, is responsible for any data change on the data set, together with the
|
|
46
|
+
* notification to the list informing it about them.
|
|
47
|
+
*
|
|
48
|
+
* With this concept, one can implement a variety of composable components
|
|
49
|
+
* taking full advantage of the scrollable list one.
|
|
50
|
+
*
|
|
51
|
+
* @template ItemT The type of data items the list will use to render its items.
|
|
52
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
53
|
+
* or _stable IDs_) in the list;
|
|
54
|
+
*
|
|
55
|
+
* @param {CarouselScrollableProps<ItemT, KeyT>} props All of the configuration
|
|
56
|
+
* attributes one can change in the scrollable list.
|
|
57
|
+
* @param {React.Ref<CarouselScrollableRef>} ref An optional {@link React.Ref} object
|
|
58
|
+
* that allows one to access the imperative functions from the
|
|
59
|
+
* {@link CarouselScrollableRef.}
|
|
60
|
+
*
|
|
61
|
+
* @see {@link CarouselScrollableProps}
|
|
62
|
+
* @see {@link CarouselScrollableRef}
|
|
63
|
+
* @see {@link CarouselDataAdapter}
|
|
64
|
+
*/
|
|
65
|
+
export declare const CarouselNativeWrapper: <ItemT, KeyT = React.Key>(props: CarouselScrollableProps<ItemT, KeyT> & {
|
|
66
|
+
ref?: React.Ref<CarouselScrollableRef> | undefined;
|
|
67
|
+
}) => React.JSX.Element;
|
|
68
|
+
export {};
|