@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,164 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
+
if (mod && mod.__esModule) return mod;
|
|
25
|
+
var result = {};
|
|
26
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
+
__setModuleDefault(result, mod);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.CarouselNativeWrapper = void 0;
|
|
32
|
+
const react_1 = __importStar(require("react"));
|
|
33
|
+
const CarouselScrollableProps_1 = require("../CarouselScrollableProps");
|
|
34
|
+
const CarouselNativeHostComponent_1 = require("./CarouselNativeHostComponent");
|
|
35
|
+
const CarouselNativeItemWrapper_1 = require("./CarouselNativeItemWrapper");
|
|
36
|
+
const CarouselNativeLogic_1 = require("./CarouselNativeLogic");
|
|
37
|
+
const utils_1 = require("../../utils");
|
|
38
|
+
/**
|
|
39
|
+
* Internal implementation of the {@link CarouselNativeWrapper} component.
|
|
40
|
+
*
|
|
41
|
+
* Check the {@link CarouselNativeWrapper} documentation for details on this component.
|
|
42
|
+
*
|
|
43
|
+
* @template ItemT The type of data items the list will use to render its items.
|
|
44
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
45
|
+
* or _stable IDs_) in the list;
|
|
46
|
+
*
|
|
47
|
+
* @see {@link CarouselNativeWrapper}
|
|
48
|
+
*/
|
|
49
|
+
function CarouselNativeInner(rawProps, ref) {
|
|
50
|
+
const props = (0, CarouselScrollableProps_1.useDefaults)(rawProps);
|
|
51
|
+
const dataAdapter = (0, CarouselScrollableProps_1.getDataAdapter)(props);
|
|
52
|
+
const hostRef = react_1.default.useRef(null);
|
|
53
|
+
const [childrenStates] = react_1.default.useState(new Map());
|
|
54
|
+
const { style, uniqueId, initialStartIndex, orientation, renderedItemsCount, numOffsetItems, showSelectionBorder, selectionBorderStyle, selectionBorderStrategy, focusedItemScaleFactor, pressedItemScaleFactor, shiftItemsOnSelection, renderItem, onItemBind, onItemUnbind, onSelectionChanged, } = props;
|
|
55
|
+
const initialStartIndexInternal = react_1.default.useMemo(() => initialStartIndex < dataAdapter.getItemCount()
|
|
56
|
+
? initialStartIndex
|
|
57
|
+
: Math.max(0, dataAdapter.getItemCount() - 1), [initialStartIndex, dataAdapter]);
|
|
58
|
+
// Activation animations on the native layer assume pressedItemScaleFactor is based on the unselected dimensions of an item.
|
|
59
|
+
// However, the prop for this wrapper is documented to be based on the selected dimensions to better align with specs given by BXT.
|
|
60
|
+
// This means that if a partner passes an pressedItemScaleFactor of 0.94 and a focusedItemScaleFactor of 1.4, when an item is pressed it should
|
|
61
|
+
// scale down to 94% of its selected dimensions.
|
|
62
|
+
// To conform to the logic on the native layer and to accomplish the same behavior we multiple the two scale factors together to yield 1.316. Instead of applying this adjusted scale factor to the selected dimensions
|
|
63
|
+
// we apply this scale factor to the unselected dimensions which the user perceives as the item shrinking when the item is pressed
|
|
64
|
+
const adjustedPressedItemScaleFactor = focusedItemScaleFactor * pressedItemScaleFactor;
|
|
65
|
+
const renderedFrames = react_1.default.useRef(renderedItemsCount);
|
|
66
|
+
const lastInitialData = react_1.default.useRef(undefined);
|
|
67
|
+
const lastParentId = react_1.default.useRef(undefined);
|
|
68
|
+
const onNativeSelectionChanged = react_1.default.useCallback(event => {
|
|
69
|
+
(0, CarouselNativeLogic_1.triggerOnSelectionChangeCallback)(onSelectionChanged, event);
|
|
70
|
+
}, [onSelectionChanged]);
|
|
71
|
+
const unbindCallback = react_1.default.useCallback(index => (0, CarouselNativeLogic_1.triggerOnItemUnbindCallback)(onItemUnbind, dataAdapter, childrenStates, index), [childrenStates, dataAdapter, onItemUnbind]);
|
|
72
|
+
const bindCallback = react_1.default.useCallback(index => (0, CarouselNativeLogic_1.triggerOnItemBindCallback)(onItemBind, dataAdapter, childrenStates, index), [childrenStates, dataAdapter, onItemBind]);
|
|
73
|
+
const onDataChangeCallback = react_1.default.useCallback((changes, animated) => {
|
|
74
|
+
utils_1.Log.d('The CarouselNative component received a notification about a data change on the backing system.');
|
|
75
|
+
(0, CarouselNativeLogic_1.callNativeNotifyDataChange)(hostRef.current, changes, animated ?? true);
|
|
76
|
+
}, [hostRef]);
|
|
77
|
+
react_1.default.useImperativeHandle(ref, () => {
|
|
78
|
+
return {
|
|
79
|
+
enableInputEvents: enable => (0, CarouselNativeLogic_1.callNativeEnableInputEvents)(hostRef.current, enable),
|
|
80
|
+
setSelectedItem: (index, animated) => (0, CarouselNativeLogic_1.callNativeSetSelectedItem)(hostRef.current, index, animated),
|
|
81
|
+
setOverflowItemsVisible: (visible, animated) => (0, CarouselNativeLogic_1.callNativeSetOverflowItemsVisible)(hostRef.current, visible, animated),
|
|
82
|
+
notifyDataChange: (changes, animated) => onDataChangeCallback(changes, animated),
|
|
83
|
+
reset: () => (0, CarouselNativeLogic_1.callReset)(hostRef.current),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const styleWithFlexDirection = react_1.default.useMemo(() => (0, CarouselNativeLogic_1.addFlexDirectionStyle)(style, orientation), [style, orientation]);
|
|
87
|
+
let initialData = lastInitialData.current && lastInitialData.current.length !== 0
|
|
88
|
+
? lastInitialData.current
|
|
89
|
+
: (0, CarouselNativeLogic_1.getInitialData)(dataAdapter, renderItem, initialStartIndexInternal, numOffsetItems, renderedFrames.current);
|
|
90
|
+
if (!lastParentId.current || !lastInitialData.current) {
|
|
91
|
+
lastParentId.current = uniqueId;
|
|
92
|
+
lastInitialData.current = initialData;
|
|
93
|
+
}
|
|
94
|
+
if (lastParentId.current !== uniqueId) {
|
|
95
|
+
initialData = (0, CarouselNativeLogic_1.getInitialData)(dataAdapter, renderItem, initialStartIndexInternal, numOffsetItems, renderedFrames.current);
|
|
96
|
+
lastParentId.current = uniqueId;
|
|
97
|
+
lastInitialData.current = initialData;
|
|
98
|
+
}
|
|
99
|
+
(0, react_1.useEffect)(() => {
|
|
100
|
+
dataAdapter.registerDataChangeCallback?.(onDataChangeCallback);
|
|
101
|
+
}, [dataAdapter, onDataChangeCallback]);
|
|
102
|
+
const startIndex = 0;
|
|
103
|
+
const endIndex = dataAdapter.getItemCount();
|
|
104
|
+
const indices = initialData.map(data => data.index);
|
|
105
|
+
const relativeInitialStartIndex = react_1.default.useMemo(() => {
|
|
106
|
+
const relativeIndex = indices.indexOf(initialStartIndexInternal);
|
|
107
|
+
return relativeIndex < 0 ? 0 : relativeIndex;
|
|
108
|
+
}, [indices, initialStartIndexInternal]);
|
|
109
|
+
utils_1.Log.i(`[CarouselScrollable] Rendering Carousel Native Wrapper "${uniqueId || ''}", startIndex = ${startIndex}, endIndex = ${endIndex}, initialSelectedIndex : ${initialStartIndexInternal}, initialData Length : ${initialData.length}, initialData Indices : ${JSON.stringify(indices)}`);
|
|
110
|
+
return (react_1.default.createElement(CarouselNativeHostComponent_1.CarouselNativeHostComponent, { ...props, initialStartIndex: initialStartIndexInternal, relativeInitialStartIndex: relativeInitialStartIndex, dataStartIndex: startIndex, dataLimitIndex: endIndex, style: styleWithFlexDirection, scaleItemOnPress: pressedItemScaleFactor != 1.0, scaleItemOnSelection: focusedItemScaleFactor !== 1.0, shiftItemsOnSelection: shiftItemsOnSelection.width !== 1.0 ||
|
|
111
|
+
shiftItemsOnSelection.height !== 1.0, onSelectionChanged: onNativeSelectionChanged, ref: hostRef }, Array(renderedFrames.current)
|
|
112
|
+
.fill({})
|
|
113
|
+
.map((_, index) => (react_1.default.createElement(CarouselNativeItemWrapper_1.CarouselNativeItemWrapper, { key: index, parentId: uniqueId, dataIndex: initialData[index]?.index, itemShift: initialData[index]?.shift, initialElement: initialData[index]?.element, initialKey: initialData[index]?.key, showSelectionBorder: showSelectionBorder, selectionBorderStyle: selectionBorderStyle, selectionBorderStrategy: selectionBorderStrategy, focusedItemScaleFactor: focusedItemScaleFactor, pressedItemScaleFactor: adjustedPressedItemScaleFactor, shiftItemsScaleFactor: shiftItemsOnSelection, dataAdapter: dataAdapter, renderItem: renderItem, bindCallback: bindCallback, unbindCallback: unbindCallback })))));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The Kepler {@link CarouselScrollable} definition.
|
|
117
|
+
*
|
|
118
|
+
* This implementation of the list uses a Native Turbo Module to control user
|
|
119
|
+
* interaction, animations, and native frame recycling.
|
|
120
|
+
*
|
|
121
|
+
* This native layer only has information about indexes; therefore, when it
|
|
122
|
+
* initially renders, it will have the knowledge about its rendered items and
|
|
123
|
+
* nothing more.
|
|
124
|
+
*
|
|
125
|
+
* As the user interacts with the component, the native layer will send messages
|
|
126
|
+
* to the JS components, and expect updates from it about any change occurring
|
|
127
|
+
* on the data backing the scrollable list.
|
|
128
|
+
*
|
|
129
|
+
* Check the documentation of {@link CarouselScrollableRef} for details about the
|
|
130
|
+
* information that the user can send to the native side.
|
|
131
|
+
*
|
|
132
|
+
* If you're required to have an encapsulated object to handle the data side of
|
|
133
|
+
* your application, check the {@link CarouselDataAdapter} documentation for a
|
|
134
|
+
* contract you can implement and use with this component.
|
|
135
|
+
*
|
|
136
|
+
* To avoid problems when using the list component, you need to understand its
|
|
137
|
+
* relation with your data.
|
|
138
|
+
*
|
|
139
|
+
* At no point, the scrollable will have any information about the _things_ your
|
|
140
|
+
* application is displaying in it, and it will never try to infer any change on
|
|
141
|
+
* your data.
|
|
142
|
+
*
|
|
143
|
+
* The user of this component is the sole owner of the data backing it, and as
|
|
144
|
+
* such, is responsible for any data change on the data set, together with the
|
|
145
|
+
* notification to the list informing it about them.
|
|
146
|
+
*
|
|
147
|
+
* With this concept, one can implement a variety of composable components
|
|
148
|
+
* taking full advantage of the scrollable list one.
|
|
149
|
+
*
|
|
150
|
+
* @template ItemT The type of data items the list will use to render its items.
|
|
151
|
+
* @template KeyT The type used as items unique identifiers (also called _keys_,
|
|
152
|
+
* or _stable IDs_) in the list;
|
|
153
|
+
*
|
|
154
|
+
* @param {CarouselScrollableProps<ItemT, KeyT>} props All of the configuration
|
|
155
|
+
* attributes one can change in the scrollable list.
|
|
156
|
+
* @param {React.Ref<CarouselScrollableRef>} ref An optional {@link React.Ref} object
|
|
157
|
+
* that allows one to access the imperative functions from the
|
|
158
|
+
* {@link CarouselScrollableRef.}
|
|
159
|
+
*
|
|
160
|
+
* @see {@link CarouselScrollableProps}
|
|
161
|
+
* @see {@link CarouselScrollableRef}
|
|
162
|
+
* @see {@link CarouselDataAdapter}
|
|
163
|
+
*/
|
|
164
|
+
exports.CarouselNativeWrapper = react_1.default.memo(react_1.default.forwardRef(CarouselNativeInner));
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./CarouselNativeWrapper"), exports);
|
|
23
|
+
__exportStar(require("./CarouselNativeHostComponent"), exports);
|
|
24
|
+
__exportStar(require("./CarouselNativeItemWrapper"), exports);
|
|
25
|
+
__exportStar(require("./CarouselNativeItemHostComponent"), exports);
|
|
26
|
+
__exportStar(require("./CarouselNativeLogic"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CarouselScrollableProps } from '../CarouselScrollableProps';
|
|
3
|
+
import { CarouselScrollableRef } from '../CarouselScrollableRef';
|
|
4
|
+
/**
|
|
5
|
+
* This Component is mainly used to allow us to maintain our Stock React Native
|
|
6
|
+
* use case, so we can continue to compare an existing stock solution against
|
|
7
|
+
* our Vega Script counterpart.
|
|
8
|
+
*
|
|
9
|
+
* This scrollable will try to provide the minimum functionality for navigating
|
|
10
|
+
* the list of objects, and should never be used in production.
|
|
11
|
+
*/
|
|
12
|
+
declare function JSRecyclerViewListInner<ItemT, KeyT = React.Key>(props: CarouselScrollableProps<ItemT, KeyT>, _ref?: React.Ref<CarouselScrollableRef>): React.JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* The `JSRecyclerViewList` component is a wrapper around `RecyclerListView`
|
|
15
|
+
* that provides the same API used by our {@link CarouselScrollable}.
|
|
16
|
+
*
|
|
17
|
+
* Refer to the {@link CarouselScrollable} documentation for details and usage.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link CarouselScrollable}
|
|
20
|
+
* @see {@link CarouselScrollableProps}
|
|
21
|
+
*/
|
|
22
|
+
export declare const JSRecyclerViewList: <ItemT, KeyT = React.Key>(props: CarouselScrollableProps<ItemT, KeyT> & {
|
|
23
|
+
ref?: React.Ref<CarouselScrollableRef> | undefined;
|
|
24
|
+
}) => React.JSX.Element;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* PROPRIETARY/CONFIDENTIAL. USE IS SUBJECT TO LICENSE TERMS.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
+
if (mod && mod.__esModule) return mod;
|
|
25
|
+
var result = {};
|
|
26
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
+
__setModuleDefault(result, mod);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.JSRecyclerViewList = void 0;
|
|
32
|
+
// This file is to keep stockRN functioning and hence ignoring coverage
|
|
33
|
+
// istanbul ignore file
|
|
34
|
+
const React = __importStar(require("react"));
|
|
35
|
+
const react_native_1 = require("react-native");
|
|
36
|
+
const recyclerlistview_1 = require("recyclerlistview");
|
|
37
|
+
const CarouselScrollableProps_1 = require("../CarouselScrollableProps");
|
|
38
|
+
const CarouselScrollableTypes_1 = require("../CarouselScrollableTypes");
|
|
39
|
+
const SCREEN_DP = (() => react_native_1.Dimensions.get('window'))();
|
|
40
|
+
/**
|
|
41
|
+
* Determines if an object has the given property.
|
|
42
|
+
*
|
|
43
|
+
* This function works around TypeScript errors by indicating the incoming `obj`
|
|
44
|
+
* is an object which has key `prop`.
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* 'prop' in obj && obj.prop === 'value' // Property 'prop' does not exist on type 'object'.
|
|
48
|
+
* hasProperty(obj, prop) && obj.pop === 'value' // No errors or warnings
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param obj object to check for property
|
|
52
|
+
* @param prop property name to check on object
|
|
53
|
+
* @typeParam X - type of `obj` which extends {@see object}
|
|
54
|
+
* @typeParam Y type of `prop` which extends {@see PropertyKey} - string | number | symbol
|
|
55
|
+
* @return true if `obj` has property `prop`; otherwise, false.
|
|
56
|
+
*/
|
|
57
|
+
function hasProperty(obj, prop) {
|
|
58
|
+
try {
|
|
59
|
+
return prop in obj;
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.warn('hasProperty threw an exception, defaulting to false: {}', e);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* This Component is mainly used to allow us to maintain our Stock React Native
|
|
68
|
+
* use case, so we can continue to compare an existing stock solution against
|
|
69
|
+
* our Vega Script counterpart.
|
|
70
|
+
*
|
|
71
|
+
* This scrollable will try to provide the minimum functionality for navigating
|
|
72
|
+
* the list of objects, and should never be used in production.
|
|
73
|
+
*/
|
|
74
|
+
function JSRecyclerViewListInner(props, _ref) {
|
|
75
|
+
const dataAdapter = (0, CarouselScrollableProps_1.getDataAdapter)(props);
|
|
76
|
+
const { testID, renderItem, orientation } = props;
|
|
77
|
+
// If keyProvider is undefined, then compare the two items directly
|
|
78
|
+
const dataDataProvider = React.useMemo(() => {
|
|
79
|
+
const rowHasChanged = (r1, r2) => {
|
|
80
|
+
const key1 = dataAdapter.getItemKey(r1, 0);
|
|
81
|
+
const key2 = dataAdapter.getItemKey(r2, 0);
|
|
82
|
+
return key1 !== key2;
|
|
83
|
+
};
|
|
84
|
+
const getStableId = index => {
|
|
85
|
+
const item = dataAdapter.getItem(index);
|
|
86
|
+
if (item) {
|
|
87
|
+
const key = dataAdapter.getItemKey(item, index);
|
|
88
|
+
return key;
|
|
89
|
+
}
|
|
90
|
+
return String(index);
|
|
91
|
+
};
|
|
92
|
+
return new recyclerlistview_1.DataProvider(rowHasChanged, getStableId);
|
|
93
|
+
}, [dataAdapter]);
|
|
94
|
+
const scrollableRef = React.useRef(null);
|
|
95
|
+
const rowRenderer = React.useCallback((_layoutId, _item, index) => {
|
|
96
|
+
const actualItem = dataAdapter.getItem(index);
|
|
97
|
+
if (!actualItem) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const c = renderItem(actualItem, index);
|
|
101
|
+
if (!c || !c.props) {
|
|
102
|
+
return c;
|
|
103
|
+
}
|
|
104
|
+
if (hasProperty(c.props, 'onFocusChanged')) {
|
|
105
|
+
const { onFocusChanged } = c.props;
|
|
106
|
+
c.props.onFocusChanged = (event) => {
|
|
107
|
+
if (event.focused) {
|
|
108
|
+
scrollableRef.current?.scrollToIndex(index, true);
|
|
109
|
+
}
|
|
110
|
+
onFocusChanged(event);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (hasProperty(c.props, 'onItemFocusChanged')) {
|
|
114
|
+
const { onItemFocusChanged } = c.props;
|
|
115
|
+
c.props.onItemFocusChanged = (childItem) => {
|
|
116
|
+
if (childItem.childEvent.focused) {
|
|
117
|
+
scrollableRef.current?.scrollToIndex(index, true);
|
|
118
|
+
}
|
|
119
|
+
onItemFocusChanged(childItem);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return c;
|
|
123
|
+
}, [dataAdapter, renderItem]);
|
|
124
|
+
const minStyle = {
|
|
125
|
+
minHeight: 1,
|
|
126
|
+
minWidth: 1,
|
|
127
|
+
};
|
|
128
|
+
return (React.createElement(recyclerlistview_1.RecyclerListView, { testID: testID, ref: scrollableRef, style: minStyle, scrollViewProps: {
|
|
129
|
+
style: [
|
|
130
|
+
orientation === CarouselScrollableTypes_1.ListOrientation.HORIZONTAL
|
|
131
|
+
? { paddingRight: 1000 }
|
|
132
|
+
: { paddingBottom: 1000 },
|
|
133
|
+
],
|
|
134
|
+
scrollEnabled: false,
|
|
135
|
+
showsHorizontalScrollIndicator: false,
|
|
136
|
+
showsVerticalScrollIndicator: false,
|
|
137
|
+
}, dataProvider: dataDataProvider, rowRenderer: rowRenderer, initialRenderIndex: 0, isHorizontal: orientation === CarouselScrollableTypes_1.ListOrientation.HORIZONTAL, renderAheadOffset: orientation === CarouselScrollableTypes_1.ListOrientation.HORIZONTAL
|
|
138
|
+
? SCREEN_DP.width * 0.2
|
|
139
|
+
: SCREEN_DP.height * 0.2 }));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The `JSRecyclerViewList` component is a wrapper around `RecyclerListView`
|
|
143
|
+
* that provides the same API used by our {@link CarouselScrollable}.
|
|
144
|
+
*
|
|
145
|
+
* Refer to the {@link CarouselScrollable} documentation for details and usage.
|
|
146
|
+
*
|
|
147
|
+
* @see {@link CarouselScrollable}
|
|
148
|
+
* @see {@link CarouselScrollableProps}
|
|
149
|
+
*/
|
|
150
|
+
exports.JSRecyclerViewList = React.forwardRef(JSRecyclerViewListInner);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023 - 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* PROPRIETARY/CONFIDENTIAL. USE IS SUBJECT TO LICENSE TERMS.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./CarouselScrollable"), exports);
|
|
23
|
+
__exportStar(require("./CarouselData"), exports);
|
|
24
|
+
__exportStar(require("./Carousel"), exports);
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"schema":1,"fileSets":{"native":[{"arch":"aarch64","variant":"release","directoryPath":"aarch64-release"},{"arch":"armv7","variant":"release","directoryPath":"armv7-release"},{"arch":"x86_64","variant":"release","directoryPath":"x86_64-release"},{"arch":"aarch64","variant":"debug","directoryPath":"aarch64-debug"},{"arch":"armv7","variant":"debug","directoryPath":"armv7-debug"},{"arch":"x86_64","variant":"debug","directoryPath":"x86_64-debug"}]}}
|
|
Binary file
|