@ankhorage/zora 27.7.1 → 27.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 +12 -0
- package/README.md +2 -2
- package/dist/capabilities/index.js +50 -1
- package/dist/capabilities/index.js.map +6 -5
- package/dist/constants/authoring.d.ts +4 -3
- package/dist/constants/authoring.d.ts.map +1 -1
- package/dist/constants/authoring.js +2 -0
- package/dist/constants/authoring.js.map +1 -1
- package/dist/features/accordion/accordionItemMeta.d.ts +1 -1
- package/dist/features/bottom-sheet/bottomSheetMeta.d.ts +1 -1
- package/dist/features/card/cardMeta.d.ts +1 -1
- package/dist/features/card/mediaCardMeta.d.ts +1 -1
- package/dist/features/card/postCardMeta.d.ts +1 -1
- package/dist/features/carousel/Carousel.d.ts +8 -0
- package/dist/features/carousel/Carousel.d.ts.map +1 -0
- package/dist/features/carousel/Carousel.js +203 -0
- package/dist/features/carousel/Carousel.js.map +1 -0
- package/dist/features/carousel/public.d.ts +3 -0
- package/dist/features/carousel/public.d.ts.map +1 -0
- package/dist/features/carousel/public.js +2 -0
- package/dist/features/carousel/public.js.map +1 -0
- package/dist/features/carousel/useCarouselPlayback.d.ts +15 -0
- package/dist/features/carousel/useCarouselPlayback.d.ts.map +1 -0
- package/dist/features/carousel/useCarouselPlayback.js +74 -0
- package/dist/features/carousel/useCarouselPlayback.js.map +1 -0
- package/dist/features/chat/messageBubbleMeta.d.ts +1 -1
- package/dist/features/dialog/dialogMeta.d.ts +2 -2
- package/dist/features/gradient/gradientMeta.d.ts +1 -1
- package/dist/features/keyboard-avoiding-view/keyboardAvoidingViewMeta.d.ts +1 -1
- package/dist/features/layout/adapters/inbound/Screen.d.ts.map +1 -1
- package/dist/features/layout/adapters/inbound/Screen.js +1 -1
- package/dist/features/layout/adapters/inbound/Screen.js.map +1 -1
- package/dist/features/layout/gridMeta.d.ts +1 -1
- package/dist/features/layout/screenMeta.d.ts +1 -1
- package/dist/features/layout/scrollViewMeta.d.ts +1 -1
- package/dist/features/layout/viewMeta.d.ts +1 -1
- package/dist/features/list/flatListMeta.d.ts +1 -1
- package/dist/features/list/sectionListMeta.d.ts +1 -1
- package/dist/features/master-detail/adapters/inbound/MasterDetail.d.ts +5 -0
- package/dist/features/master-detail/adapters/inbound/MasterDetail.d.ts.map +1 -0
- package/dist/features/master-detail/adapters/inbound/MasterDetail.js +39 -0
- package/dist/features/master-detail/adapters/inbound/MasterDetail.js.map +1 -0
- package/dist/features/master-detail/application/resolveMasterDetailPresentation.d.ts +6 -0
- package/dist/features/master-detail/application/resolveMasterDetailPresentation.d.ts.map +1 -0
- package/dist/features/master-detail/application/resolveMasterDetailPresentation.js +7 -0
- package/dist/features/master-detail/application/resolveMasterDetailPresentation.js.map +1 -0
- package/dist/features/master-detail/masterDetailMeta.d.ts +52 -0
- package/dist/features/master-detail/masterDetailMeta.d.ts.map +1 -0
- package/dist/features/master-detail/masterDetailMeta.js +47 -0
- package/dist/features/master-detail/masterDetailMeta.js.map +1 -0
- package/dist/features/master-detail/public.d.ts +3 -0
- package/dist/features/master-detail/public.d.ts.map +1 -0
- package/dist/features/master-detail/public.js +2 -0
- package/dist/features/master-detail/public.js.map +1 -0
- package/dist/features/reader/meta.d.ts +2 -2
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.d.ts.map +1 -1
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.js +2 -0
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.js.map +1 -1
- package/dist/features/registry/bindableComponentMeta.d.ts +2 -2
- package/dist/features/registry/componentMeta.d.ts.map +1 -1
- package/dist/features/registry/componentMeta.js +2 -0
- package/dist/features/registry/componentMeta.js.map +1 -1
- package/dist/features/scanner/meta.d.ts +2 -2
- package/dist/features/section/screenSectionMeta.d.ts +1 -1
- package/dist/features/surface/surfaceMeta.d.ts +1 -1
- package/dist/features/tabs/tabPanelMeta.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/readerFree.d.ts +2 -0
- package/dist/readerFree.d.ts.map +1 -1
- package/dist/readerFree.js +1 -0
- package/dist/readerFree.js.map +1 -1
- package/dist/types/carousel.d.ts +52 -0
- package/dist/types/carousel.d.ts.map +1 -0
- package/dist/types/carousel.js +2 -0
- package/dist/types/carousel.js.map +1 -0
- package/dist/types/master-detail.d.ts +21 -0
- package/dist/types/master-detail.d.ts.map +1 -0
- package/dist/types/master-detail.js +2 -0
- package/dist/types/master-detail.js.map +1 -0
- package/package.json +1 -1
- package/src/constants/authoring.ts +2 -0
- package/src/features/carousel/Carousel.test.ts +66 -0
- package/src/features/carousel/Carousel.tsx +470 -0
- package/src/features/carousel/public.ts +2 -0
- package/src/features/carousel/useCarouselPlayback.ts +103 -0
- package/src/features/layout/adapters/inbound/Screen.tsx +3 -0
- package/src/features/master-detail/adapters/inbound/MasterDetail.runtime.test.tsx +121 -0
- package/src/features/master-detail/adapters/inbound/MasterDetail.tsx +75 -0
- package/src/features/master-detail/application/resolveMasterDetailPresentation.test.ts +18 -0
- package/src/features/master-detail/application/resolveMasterDetailPresentation.ts +15 -0
- package/src/features/master-detail/masterDetailMeta.ts +49 -0
- package/src/features/master-detail/public.ts +7 -0
- package/src/features/registry/ZORA_BASE_COMPONENT_REGISTRY.ts +2 -0
- package/src/features/registry/componentMeta.test.ts +16 -0
- package/src/features/registry/componentMeta.ts +2 -0
- package/src/features/registry/featureManifest.test.ts +2 -0
- package/src/index.ts +9 -0
- package/src/readerFree.ts +7 -0
- package/src/types/carousel.ts +60 -0
- package/src/types/master-detail.ts +25 -0
- package/web-dist/chunks/{Accordion-p2f0e4pn.js → Accordion-0bgzetnd.js} +6 -6
- package/web-dist/chunks/{Accordion-wvghkwxx.js → Accordion-0yn2b3ha.js} +9 -9
- package/web-dist/chunks/{Accordion-9d3rd7ne.js → Accordion-19zt3dyq.js} +1 -1
- package/web-dist/chunks/{Accordion-sxzts6bj.js → Accordion-1k7pyxdd.js} +2 -2
- package/web-dist/chunks/{Accordion-ew2cebyd.js → Accordion-1mjn0atk.js} +4 -4
- package/web-dist/chunks/{Accordion-ms1y70gq.js → Accordion-6qesggn9.js} +4 -4
- package/web-dist/chunks/{Accordion-e8dg1z2s.js → Accordion-6y42ws4p.js} +2 -2
- package/web-dist/chunks/{Accordion-jh94mg56.js → Accordion-70hh6g1f.js} +9 -9
- package/web-dist/chunks/{Accordion-wx0jp5cn.js → Accordion-7qb7741m.js} +7 -7
- package/web-dist/chunks/{Accordion-rwc34cn2.js → Accordion-818avkay.js} +5 -5
- package/web-dist/chunks/{Accordion-t2cvrn0r.js → Accordion-8ahdjt13.js} +8 -8
- package/web-dist/chunks/{Accordion-j6bs1yfn.js → Accordion-8vw4k0s6.js} +2 -2
- package/web-dist/chunks/{Accordion-m3xb7z7j.js → Accordion-8y13469y.js} +8 -8
- package/web-dist/chunks/{Accordion-4kmh6s2k.js → Accordion-91v243pz.js} +2 -2
- package/web-dist/chunks/{Accordion-8vcs6nz6.js → Accordion-9cpm8x92.js} +1 -1
- package/web-dist/chunks/{Accordion-vq8zrnwh.js → Accordion-9kkfz7s8.js} +4 -4
- package/web-dist/chunks/{Accordion-6jsea4e0.js → Accordion-ajgffs75.js} +8 -8
- package/web-dist/chunks/{Accordion-hf4nfkn0.js → Accordion-bednnpzh.js} +13 -13
- package/web-dist/chunks/{Accordion-c44m1q0m.js → Accordion-ctcxh9pk.js} +3 -3
- package/web-dist/chunks/{Accordion-fbehwpr1.js → Accordion-dnfrzbpb.js} +7 -7
- package/web-dist/chunks/{Accordion-f2n2zz1x.js → Accordion-ea0ag7wf.js} +6 -6
- package/web-dist/chunks/{Accordion-260pyaxy.js → Accordion-g45xga4b.js} +5 -5
- package/web-dist/chunks/{Accordion-yb4as6wc.js → Accordion-gjeaevge.js} +5 -5
- package/web-dist/chunks/{Accordion-7788ybcs.js → Accordion-grtf75xt.js} +4 -4
- package/web-dist/chunks/{Accordion-9hcbf56f.js → Accordion-h4928ex8.js} +2 -2
- package/web-dist/chunks/{Accordion-mrhkw8n6.js → Accordion-hqg1zbxk.js} +6 -4
- package/web-dist/chunks/{Accordion-gysa24fk.js → Accordion-j5wsx41j.js} +1 -1
- package/web-dist/chunks/{Accordion-yrzm02g2.js → Accordion-jmhn8mm5.js} +5 -5
- package/web-dist/chunks/{Accordion-252dr90x.js → Accordion-jsapannb.js} +4 -4
- package/web-dist/chunks/{Accordion-b4yr6yq3.js → Accordion-jsdjgfn2.js} +2 -2
- package/web-dist/chunks/{Accordion-8ac6dkcs.js → Accordion-k058095e.js} +1 -1
- package/web-dist/chunks/Accordion-kcx57mk5.js +39 -0
- package/web-dist/chunks/{Accordion-5z8pbn4z.js → Accordion-nbje2ywp.js} +3 -3
- package/web-dist/chunks/{Accordion-tpd1vvy9.js → Accordion-ng79nxzz.js} +1 -38
- package/web-dist/chunks/{Accordion-7mnan4q4.js → Accordion-qw6tzn3f.js} +6 -6
- package/web-dist/chunks/{Accordion-w0prbwy0.js → Accordion-qx45gtx9.js} +8 -8
- package/web-dist/chunks/{Accordion-rcs75kj4.js → Accordion-r6gwemh9.js} +3 -3
- package/web-dist/chunks/{Accordion-s9nbkzky.js → Accordion-rt4jfq2r.js} +2 -2
- package/web-dist/chunks/{Accordion-r86ce0wj.js → Accordion-t11cptjk.js} +4 -4
- package/web-dist/chunks/{Accordion-jx9tc6p1.js → Accordion-th8pkeqc.js} +4 -4
- package/web-dist/chunks/{Accordion-tnt1txfq.js → Accordion-tkxddb2c.js} +4 -4
- package/web-dist/chunks/{Accordion-5pbvgvqc.js → Accordion-tnq8bt8v.js} +2 -2
- package/web-dist/chunks/{Accordion-nnhznqgf.js → Accordion-ttjyk97v.js} +2 -2
- package/web-dist/chunks/{Accordion-r6zvzrkd.js → Accordion-v21vz0cg.js} +7 -4
- package/web-dist/chunks/{Accordion-0j4xzcwz.js → Accordion-vdqc8rxv.js} +3 -3
- package/web-dist/chunks/{Accordion-a8k3cvj0.js → Accordion-w1ag7sr4.js} +2 -2
- package/web-dist/chunks/{Accordion-vzgpdtr2.js → Accordion-wdby2v5r.js} +1 -1
- package/web-dist/chunks/{Accordion-zj4wnm3e.js → Accordion-wgc67k1g.js} +1 -1
- package/web-dist/chunks/{Accordion-p7mxkxhs.js → Accordion-x3em7tpd.js} +9 -9
- package/web-dist/chunks/{Accordion-mpebzjby.js → Accordion-xb2nj0q6.js} +4 -4
- package/web-dist/chunks/{Accordion-001ymezm.js → Accordion-y524ph0g.js} +1 -1
- package/web-dist/chunks/{Accordion-np16p9mh.js → Accordion-zexve9d3.js} +4 -4
- package/web-dist/chunks/{Accordion-4c7hqeg3.js → Accordion-zvpkhqb7.js} +2 -2
- package/web-dist/chunks/{Accordion-kcca65d8.js → Accordion-zxergnck.js} +5 -5
- package/web-dist/chunks/{Accordion-hh48jjhk.js → Accordion-zyah4pvq.js} +7 -7
- package/web-dist/chunks/{Accordion-8j7t77tf.js → Accordion-zymf1mp8.js} +5 -5
- package/web-dist/components/accordion/Accordion.js +12 -11
- package/web-dist/components/accordion-item/AccordionItem.js +12 -11
- package/web-dist/components/activity-indicator/ActivityIndicator.js +4 -3
- package/web-dist/components/app-bar/AppBar.js +18 -17
- package/web-dist/components/app-header/AppHeader.js +18 -17
- package/web-dist/components/app-shell/AppShell.js +6 -5
- package/web-dist/components/auth-screen/AuthScreen.js +23 -22
- package/web-dist/components/avatar/Avatar.js +12 -11
- package/web-dist/components/avatar-group/AvatarGroup.js +12 -11
- package/web-dist/components/badge/Badge.js +7 -6
- package/web-dist/components/barcode-scanner-view/BarcodeScannerView.js +21 -20
- package/web-dist/components/bottom-sheet/BottomSheet.js +8 -7
- package/web-dist/components/bottom-sheet-flat-list/BottomSheetFlatList.js +8 -7
- package/web-dist/components/bottom-sheet-scroll-view/BottomSheetScrollView.js +8 -7
- package/web-dist/components/bottom-sheet-section-list/BottomSheetSectionList.js +8 -7
- package/web-dist/components/bottom-sheet-view/BottomSheetView.js +8 -7
- package/web-dist/components/bottom-sheet-virtualized-list/BottomSheetVirtualizedList.js +8 -7
- package/web-dist/components/breadcrumbs/Breadcrumbs.js +15 -14
- package/web-dist/components/button/Button.js +13 -12
- package/web-dist/components/button-group/ButtonGroup.js +13 -12
- package/web-dist/components/calendar/Calendar.js +15 -14
- package/web-dist/components/camera-permission-view/CameraPermissionView.js +21 -20
- package/web-dist/components/card/Card.js +20 -19
- package/web-dist/components/card-back/CardBack.js +5 -4
- package/web-dist/components/card-hand/CardHand.js +5 -4
- package/web-dist/components/carousel/Carousel.d.ts +10 -0
- package/web-dist/components/carousel/Carousel.js +483 -0
- package/web-dist/components/carousel/Carousel.types-0.d.ts +55 -0
- package/web-dist/components/carousel/index.d.ts +2 -0
- package/web-dist/components/carousel/index.js +2 -0
- package/web-dist/components/chat-list-item/ChatListItem.js +16 -15
- package/web-dist/components/checkbox/Checkbox.js +12 -11
- package/web-dist/components/checkbox-group/CheckboxGroup.js +12 -11
- package/web-dist/components/chess-board/ChessBoard.js +5 -4
- package/web-dist/components/chip/Chip.js +13 -12
- package/web-dist/components/chip-group/ChipGroup.js +13 -12
- package/web-dist/components/collection-editor/CollectionEditor.js +20 -19
- package/web-dist/components/color-hue-scale/ColorHueScale.js +16 -15
- package/web-dist/components/color-picker/ColorPicker.js +16 -15
- package/web-dist/components/color-tone/ColorTone.js +16 -15
- package/web-dist/components/color-wheel/ColorWheel.js +16 -15
- package/web-dist/components/content-rail/ContentRail.js +14 -13
- package/web-dist/components/data-table/DataTable.js +26 -25
- package/web-dist/components/date-picker/DatePicker.js +19 -18
- package/web-dist/components/dialog/Dialog.js +11 -10
- package/web-dist/components/divider/Divider.js +6 -5
- package/web-dist/components/empty-state/EmptyState.js +21 -20
- package/web-dist/components/explorer/Explorer.js +13 -12
- package/web-dist/components/field/Field.js +12 -11
- package/web-dist/components/file-explorer/FileExplorer.js +13 -12
- package/web-dist/components/flat-list/FlatList.js +13 -12
- package/web-dist/components/forgot-password-form/ForgotPasswordForm.js +23 -22
- package/web-dist/components/form/Form.js +17 -16
- package/web-dist/components/form-actions/FormActions.js +17 -16
- package/web-dist/components/form-error/FormError.js +17 -16
- package/web-dist/components/game/Game.js +7 -6
- package/web-dist/components/game-entity/GameEntity.js +7 -6
- package/web-dist/components/game-field/GameField.js +7 -6
- package/web-dist/components/game-input-zone/GameInputZone.js +7 -6
- package/web-dist/components/game-measurement-probe/GameMeasurementProbe.js +7 -6
- package/web-dist/components/game-overlay/GameOverlay.js +7 -6
- package/web-dist/components/gradient/Gradient.js +7 -6
- package/web-dist/components/gradient-renderer-provider/GradientRendererProvider.js +7 -6
- package/web-dist/components/grid/Grid.js +6 -5
- package/web-dist/components/grid-line-overlay/GridLineOverlay.js +5 -4
- package/web-dist/components/grid-ruler/GridRuler.js +5 -4
- package/web-dist/components/heading/Heading.js +7 -6
- package/web-dist/components/hero/Hero.js +20 -19
- package/web-dist/components/icon/Icon.js +5 -4
- package/web-dist/components/icon-button/IconButton.js +13 -12
- package/web-dist/components/image/Image.js +10 -9
- package/web-dist/components/keyboard-avoiding-view/KeyboardAvoidingView.js +4 -3
- package/web-dist/components/list/List.js +13 -12
- package/web-dist/components/list-item/ListItem.js +13 -12
- package/web-dist/components/list-section/ListSection.js +13 -12
- package/web-dist/components/master-detail/MasterDetail.d.ts +7 -0
- package/web-dist/components/master-detail/MasterDetail.dependency-0.d.ts +27 -0
- package/web-dist/components/master-detail/MasterDetail.dependency-1.d.ts +3 -0
- package/web-dist/components/master-detail/MasterDetail.js +110 -0
- package/web-dist/components/master-detail/MasterDetail.types-0.d.ts +25 -0
- package/web-dist/components/master-detail/index.d.ts +2 -0
- package/web-dist/components/master-detail/index.js +2 -0
- package/web-dist/components/matrix-grid/MatrixGrid.js +5 -4
- package/web-dist/components/media-card/MediaCard.js +20 -19
- package/web-dist/components/media-explorer/MediaExplorer.js +13 -12
- package/web-dist/components/message-bubble/MessageBubble.js +16 -15
- package/web-dist/components/metric-card/MetricCard.js +20 -19
- package/web-dist/components/missing-element/MissingElement.js +11 -10
- package/web-dist/components/o-auth-provider-button/OAuthProviderButton.js +23 -22
- package/web-dist/components/o-auth-provider-list/OAuthProviderList.js +23 -22
- package/web-dist/components/opening-book/OpeningBook.js +5 -4
- package/web-dist/components/otp-form/OtpForm.js +23 -22
- package/web-dist/components/pagination/Pagination.js +14 -13
- package/web-dist/components/palette-item/PaletteItem.js +20 -19
- package/web-dist/components/playing-card/PlayingCard.js +5 -4
- package/web-dist/components/poker-training-table/PokerTrainingTable.js +5 -4
- package/web-dist/components/popover-menu/PopoverMenu.js +12 -11
- package/web-dist/components/post-card/PostCard.js +20 -19
- package/web-dist/components/product-card/ProductCard.js +20 -19
- package/web-dist/components/progress/Progress.js +10 -9
- package/web-dist/components/progress-ring/ProgressRing.js +10 -9
- package/web-dist/components/radio/Radio.js +14 -13
- package/web-dist/components/radio-group/RadioGroup.js +14 -13
- package/web-dist/components/rating/Rating.js +9 -8
- package/web-dist/components/reader/Reader.js +21 -20
- package/web-dist/components/scan-overlay/ScanOverlay.js +21 -20
- package/web-dist/components/screen/Screen.js +6 -5
- package/web-dist/components/screen-section/ScreenSection.js +10 -9
- package/web-dist/components/scroll-view/ScrollView.js +6 -5
- package/web-dist/components/search-input/SearchInput.js +15 -14
- package/web-dist/components/section-header/SectionHeader.js +10 -9
- package/web-dist/components/section-list/SectionList.js +13 -12
- package/web-dist/components/select/Select.js +16 -15
- package/web-dist/components/selectable-item/SelectableItem.js +4 -3
- package/web-dist/components/selection-provider/SelectionProvider.js +4 -3
- package/web-dist/components/sign-in-form/SignInForm.js +23 -22
- package/web-dist/components/sign-up-form/SignUpForm.js +23 -22
- package/web-dist/components/skeleton/Skeleton.js +23 -22
- package/web-dist/components/skeleton-card/SkeletonCard.js +23 -22
- package/web-dist/components/skeleton-list/SkeletonList.js +23 -22
- package/web-dist/components/skeleton-text/SkeletonText.js +23 -22
- package/web-dist/components/surface/Surface.js +7 -6
- package/web-dist/components/switch/Switch.js +7 -6
- package/web-dist/components/tab/Tab.js +7 -6
- package/web-dist/components/tab-list/TabList.js +7 -6
- package/web-dist/components/tab-panel/TabPanel.js +7 -6
- package/web-dist/components/tabletop-table/TabletopTable.js +5 -4
- package/web-dist/components/tabs/Tabs.js +7 -6
- package/web-dist/components/text/Text.js +7 -6
- package/web-dist/components/text-input/TextInput.js +15 -14
- package/web-dist/components/theme-mode-toggle/ThemeModeToggle.js +13 -12
- package/web-dist/components/time-picker/TimePicker.js +18 -17
- package/web-dist/components/timeline/Timeline.js +12 -11
- package/web-dist/components/toast/Toast.js +9 -8
- package/web-dist/components/toast-provider/ToastProvider.js +9 -8
- package/web-dist/components/toolbar/Toolbar.js +20 -19
- package/web-dist/components/tree-item/TreeItem.js +18 -17
- package/web-dist/components/uploader/Uploader.js +23 -22
- package/web-dist/components/view/View.js +6 -5
- package/web-dist/manifest.json +1787 -1617
- package/web-dist/runtime/ZoraProvider.js +12 -10
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Carousel, type CarouselProps } from '@ankhorage/zora/web/carousel';
|
|
2
|
+
import { ZoraProvider } from '@ankhorage/zora/web/runtime';
|
|
3
|
+
import { expect, test } from 'bun:test';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
6
|
+
|
|
7
|
+
/*** Render the published browser facade inside its real theme provider. */
|
|
8
|
+
function renderCarousel(props: CarouselProps): string {
|
|
9
|
+
return renderToStaticMarkup(
|
|
10
|
+
React.createElement(ZoraProvider, undefined, React.createElement(Carousel, props)),
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test('renders no slides or progress with an empty collection', () => {
|
|
15
|
+
const html = renderCarousel({ slides: [] });
|
|
16
|
+
expect(html).not.toContain('<img');
|
|
17
|
+
expect(html).not.toContain('progress');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('renders images through the consumer renderer without a Next.js dependency', () => {
|
|
21
|
+
const html = renderCarousel({
|
|
22
|
+
slides: [{ key: 'one', source: '/original.jpg', alt: 'Image' }],
|
|
23
|
+
renderImage: (slide) =>
|
|
24
|
+
React.createElement('img', {
|
|
25
|
+
src: typeof slide.source === 'string' ? slide.source : '',
|
|
26
|
+
alt: '',
|
|
27
|
+
}),
|
|
28
|
+
testID: 'carousel',
|
|
29
|
+
});
|
|
30
|
+
expect(html).toContain('/original.jpg');
|
|
31
|
+
expect(html).not.toContain('carousel-progress');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('supports arbitrary React content without requiring image sources', () => {
|
|
35
|
+
const html = renderCarousel({
|
|
36
|
+
slides: [
|
|
37
|
+
{ key: 'one', content: React.createElement('span', undefined, 'Discover your next idea') },
|
|
38
|
+
{ key: 'two', content: React.createElement('span', undefined, 'Create what matters') },
|
|
39
|
+
],
|
|
40
|
+
transition: 'none',
|
|
41
|
+
});
|
|
42
|
+
expect(html).toContain('Discover your next idea');
|
|
43
|
+
expect(html).toContain('Create what matters');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('renders configurable accessible arrows, indicators and progress', () => {
|
|
47
|
+
const slides = [
|
|
48
|
+
{ key: 'one', source: '/one.jpg' },
|
|
49
|
+
{ key: 'two', source: '/two.jpg' },
|
|
50
|
+
];
|
|
51
|
+
const html = renderCarousel({
|
|
52
|
+
slides,
|
|
53
|
+
showArrows: true,
|
|
54
|
+
showIndicators: true,
|
|
55
|
+
testID: 'carousel',
|
|
56
|
+
});
|
|
57
|
+
expect(html).toContain('carousel-previous');
|
|
58
|
+
expect(html).toContain('carousel-next');
|
|
59
|
+
expect(html).toContain('carousel-indicator-0');
|
|
60
|
+
expect(html).toContain('carousel-indicator-1');
|
|
61
|
+
expect(html).toContain('carousel-progress');
|
|
62
|
+
expect(html).toContain('Go to slide 1 of 2');
|
|
63
|
+
const minimal = renderCarousel({ slides, showProgress: false });
|
|
64
|
+
expect(minimal).not.toContain('progress');
|
|
65
|
+
expect(minimal).not.toContain('indicator-0');
|
|
66
|
+
});
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Animated, Easing, Image, Pressable, StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { CarouselProps, CarouselSlide, CarouselTransition } from '../../types/carousel';
|
|
5
|
+
import { useZoraTheme } from '../theme/composition/useZoraTheme';
|
|
6
|
+
import { useCarouselPlayback } from './useCarouselPlayback';
|
|
7
|
+
|
|
8
|
+
/***
|
|
9
|
+
* Present images, arbitrary React content, or both as a cross-platform slideshow.
|
|
10
|
+
* A published web artifact exposes the same API without consumer source imports.
|
|
11
|
+
*/
|
|
12
|
+
export function Carousel({
|
|
13
|
+
slides,
|
|
14
|
+
index,
|
|
15
|
+
defaultIndex,
|
|
16
|
+
onIndexChange,
|
|
17
|
+
autoPlay,
|
|
18
|
+
paused,
|
|
19
|
+
loop,
|
|
20
|
+
intervalMs,
|
|
21
|
+
transition = 'fade',
|
|
22
|
+
enterDurationMs = 1200,
|
|
23
|
+
exitDurationMs = 800,
|
|
24
|
+
initialScale = 1.06,
|
|
25
|
+
animateOnMount = false,
|
|
26
|
+
reducedMotion,
|
|
27
|
+
showProgress = true,
|
|
28
|
+
progressHeight = 4,
|
|
29
|
+
progressTrackColor,
|
|
30
|
+
progressIndicatorColor,
|
|
31
|
+
progressTrackStyle,
|
|
32
|
+
progressIndicatorStyle,
|
|
33
|
+
showArrows = false,
|
|
34
|
+
showIndicators = false,
|
|
35
|
+
previousLabel = 'Previous slide',
|
|
36
|
+
nextLabel = 'Next slide',
|
|
37
|
+
controlColor,
|
|
38
|
+
controlBackgroundColor,
|
|
39
|
+
controlsStyle,
|
|
40
|
+
activeIndicatorColor,
|
|
41
|
+
inactiveIndicatorColor,
|
|
42
|
+
indicatorsStyle,
|
|
43
|
+
resizeMode = 'cover',
|
|
44
|
+
imageStyle,
|
|
45
|
+
style,
|
|
46
|
+
renderImage,
|
|
47
|
+
testID,
|
|
48
|
+
}: CarouselProps) {
|
|
49
|
+
const { theme } = useZoraTheme();
|
|
50
|
+
const [width, setWidth] = React.useState(0);
|
|
51
|
+
const {
|
|
52
|
+
activeIndex,
|
|
53
|
+
controlledWithoutHandler,
|
|
54
|
+
direction,
|
|
55
|
+
loop: enabledLoop,
|
|
56
|
+
navigate,
|
|
57
|
+
progress,
|
|
58
|
+
shouldReduceMotion,
|
|
59
|
+
} = useCarouselPlayback({
|
|
60
|
+
slides,
|
|
61
|
+
index,
|
|
62
|
+
defaultIndex,
|
|
63
|
+
onIndexChange,
|
|
64
|
+
autoPlay,
|
|
65
|
+
paused,
|
|
66
|
+
loop,
|
|
67
|
+
intervalMs,
|
|
68
|
+
reducedMotion,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (slides.length === 0) return null;
|
|
72
|
+
|
|
73
|
+
const canPrevious = enabledLoop || activeIndex > 0;
|
|
74
|
+
const canNext = enabledLoop || activeIndex < slides.length - 1;
|
|
75
|
+
const markerColor = activeIndicatorColor ?? theme.colors.primary;
|
|
76
|
+
const idleMarkerColor = inactiveIndicatorColor ?? theme.semantics.neutral.divider;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<View
|
|
80
|
+
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
|
81
|
+
testID={testID}
|
|
82
|
+
style={[{ position: 'relative', overflow: 'hidden', width: '100%', height: '100%' }, style]}
|
|
83
|
+
>
|
|
84
|
+
{slides.map((slide, slideIndex) => (
|
|
85
|
+
<CarouselLayer
|
|
86
|
+
key={slide.key}
|
|
87
|
+
active={activeIndex === slideIndex}
|
|
88
|
+
animate={slides.length > 1}
|
|
89
|
+
animateOnMount={animateOnMount}
|
|
90
|
+
direction={direction}
|
|
91
|
+
enterDurationMs={enterDurationMs}
|
|
92
|
+
exitDurationMs={exitDurationMs}
|
|
93
|
+
imageStyle={imageStyle}
|
|
94
|
+
initialScale={initialScale}
|
|
95
|
+
reducedMotion={shouldReduceMotion}
|
|
96
|
+
renderImage={renderImage}
|
|
97
|
+
resizeMode={resizeMode}
|
|
98
|
+
slide={slide}
|
|
99
|
+
slideIndex={slideIndex}
|
|
100
|
+
transition={transition}
|
|
101
|
+
width={width}
|
|
102
|
+
/>
|
|
103
|
+
))}
|
|
104
|
+
<CarouselControls
|
|
105
|
+
activeIndex={activeIndex}
|
|
106
|
+
canNext={canNext}
|
|
107
|
+
canPrevious={canPrevious}
|
|
108
|
+
controlBackgroundColor={controlBackgroundColor ?? theme.semantics.surface.raised}
|
|
109
|
+
controlColor={controlColor ?? theme.semantics.content.default}
|
|
110
|
+
controlledWithoutHandler={controlledWithoutHandler}
|
|
111
|
+
controlsStyle={controlsStyle}
|
|
112
|
+
navigate={navigate}
|
|
113
|
+
nextLabel={nextLabel}
|
|
114
|
+
previousLabel={previousLabel}
|
|
115
|
+
show={showArrows && slides.length > 1}
|
|
116
|
+
testID={testID}
|
|
117
|
+
/>
|
|
118
|
+
<CarouselIndicators
|
|
119
|
+
activeIndex={activeIndex}
|
|
120
|
+
activeColor={markerColor}
|
|
121
|
+
controlledWithoutHandler={controlledWithoutHandler}
|
|
122
|
+
idleColor={idleMarkerColor}
|
|
123
|
+
indicatorsStyle={indicatorsStyle}
|
|
124
|
+
navigate={navigate}
|
|
125
|
+
show={showIndicators && slides.length > 1}
|
|
126
|
+
slides={slides}
|
|
127
|
+
testID={testID}
|
|
128
|
+
/>
|
|
129
|
+
<CarouselProgress
|
|
130
|
+
height={progressHeight}
|
|
131
|
+
indicatorColor={progressIndicatorColor ?? theme.colors.primary}
|
|
132
|
+
indicatorStyle={progressIndicatorStyle}
|
|
133
|
+
progress={progress}
|
|
134
|
+
show={showProgress && slides.length > 1}
|
|
135
|
+
testID={testID}
|
|
136
|
+
trackColor={progressTrackColor ?? theme.semantics.neutral.divider}
|
|
137
|
+
trackStyle={progressTrackStyle}
|
|
138
|
+
/>
|
|
139
|
+
</View>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface CarouselLayerProps {
|
|
144
|
+
readonly enterDurationMs?: CarouselProps['enterDurationMs'];
|
|
145
|
+
readonly exitDurationMs?: CarouselProps['exitDurationMs'];
|
|
146
|
+
readonly imageStyle: CarouselProps['imageStyle'];
|
|
147
|
+
readonly initialScale?: CarouselProps['initialScale'];
|
|
148
|
+
readonly renderImage: CarouselProps['renderImage'];
|
|
149
|
+
readonly resizeMode: CarouselProps['resizeMode'];
|
|
150
|
+
readonly slide: CarouselSlide;
|
|
151
|
+
readonly slideIndex: number;
|
|
152
|
+
readonly active: boolean;
|
|
153
|
+
readonly animate: boolean;
|
|
154
|
+
readonly animateOnMount: boolean;
|
|
155
|
+
readonly direction: 1 | -1;
|
|
156
|
+
readonly width: number;
|
|
157
|
+
readonly transition: CarouselTransition;
|
|
158
|
+
readonly reducedMotion: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/*** Keep departing slides mounted for an animated overlap without unmounting content. */
|
|
162
|
+
function CarouselLayer({
|
|
163
|
+
slide,
|
|
164
|
+
slideIndex,
|
|
165
|
+
active,
|
|
166
|
+
animate,
|
|
167
|
+
animateOnMount,
|
|
168
|
+
direction,
|
|
169
|
+
enterDurationMs = 1200,
|
|
170
|
+
exitDurationMs = 800,
|
|
171
|
+
initialScale = 1.06,
|
|
172
|
+
reducedMotion,
|
|
173
|
+
renderImage,
|
|
174
|
+
resizeMode,
|
|
175
|
+
imageStyle,
|
|
176
|
+
transition,
|
|
177
|
+
width,
|
|
178
|
+
}: CarouselLayerProps) {
|
|
179
|
+
const [opacity] = React.useState(() => new Animated.Value(active && !animateOnMount ? 1 : 0));
|
|
180
|
+
const [scale] = React.useState(
|
|
181
|
+
() => new Animated.Value(active && animateOnMount ? initialScale : 1),
|
|
182
|
+
);
|
|
183
|
+
const [offset] = React.useState(() => new Animated.Value(0));
|
|
184
|
+
const hasMounted = React.useRef(false);
|
|
185
|
+
|
|
186
|
+
React.useEffect(() => {
|
|
187
|
+
const firstRender = !hasMounted.current;
|
|
188
|
+
hasMounted.current = true;
|
|
189
|
+
if (firstRender && !animateOnMount) return;
|
|
190
|
+
opacity.stopAnimation();
|
|
191
|
+
scale.stopAnimation();
|
|
192
|
+
offset.stopAnimation();
|
|
193
|
+
if (!animate || reducedMotion || transition === 'none') {
|
|
194
|
+
opacity.setValue(active ? 1 : 0);
|
|
195
|
+
scale.setValue(1);
|
|
196
|
+
offset.setValue(0);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (transition === 'slide') {
|
|
200
|
+
scale.setValue(1);
|
|
201
|
+
if (active) {
|
|
202
|
+
offset.setValue(direction * width);
|
|
203
|
+
opacity.setValue(1);
|
|
204
|
+
}
|
|
205
|
+
Animated.parallel([
|
|
206
|
+
Animated.timing(offset, {
|
|
207
|
+
toValue: active ? 0 : -direction * width,
|
|
208
|
+
duration: Math.max(0, active ? enterDurationMs : exitDurationMs),
|
|
209
|
+
easing: Easing.bezier(0.4, 0, 0.2, 1),
|
|
210
|
+
useNativeDriver: true,
|
|
211
|
+
}),
|
|
212
|
+
Animated.timing(opacity, {
|
|
213
|
+
toValue: active ? 1 : 0,
|
|
214
|
+
duration: Math.max(0, active ? enterDurationMs : exitDurationMs),
|
|
215
|
+
easing: Easing.linear,
|
|
216
|
+
useNativeDriver: true,
|
|
217
|
+
}),
|
|
218
|
+
]).start();
|
|
219
|
+
} else if (active) {
|
|
220
|
+
opacity.setValue(0);
|
|
221
|
+
scale.setValue(initialScale);
|
|
222
|
+
Animated.parallel([
|
|
223
|
+
Animated.timing(opacity, {
|
|
224
|
+
toValue: 1,
|
|
225
|
+
duration: Math.max(0, enterDurationMs),
|
|
226
|
+
easing: Easing.bezier(0.4, 0, 0.2, 1),
|
|
227
|
+
useNativeDriver: true,
|
|
228
|
+
}),
|
|
229
|
+
Animated.timing(scale, {
|
|
230
|
+
toValue: 1,
|
|
231
|
+
duration: Math.max(0, enterDurationMs),
|
|
232
|
+
easing: Easing.bezier(0.4, 0, 0.2, 1),
|
|
233
|
+
useNativeDriver: true,
|
|
234
|
+
}),
|
|
235
|
+
]).start();
|
|
236
|
+
} else {
|
|
237
|
+
Animated.timing(opacity, {
|
|
238
|
+
toValue: 0,
|
|
239
|
+
duration: Math.max(0, exitDurationMs),
|
|
240
|
+
easing: Easing.bezier(0.4, 0, 0.2, 1),
|
|
241
|
+
useNativeDriver: true,
|
|
242
|
+
}).start();
|
|
243
|
+
}
|
|
244
|
+
return () => {
|
|
245
|
+
opacity.stopAnimation();
|
|
246
|
+
scale.stopAnimation();
|
|
247
|
+
offset.stopAnimation();
|
|
248
|
+
};
|
|
249
|
+
}, [
|
|
250
|
+
active,
|
|
251
|
+
animate,
|
|
252
|
+
animateOnMount,
|
|
253
|
+
direction,
|
|
254
|
+
enterDurationMs,
|
|
255
|
+
exitDurationMs,
|
|
256
|
+
initialScale,
|
|
257
|
+
offset,
|
|
258
|
+
opacity,
|
|
259
|
+
reducedMotion,
|
|
260
|
+
scale,
|
|
261
|
+
transition,
|
|
262
|
+
width,
|
|
263
|
+
]);
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<Animated.View
|
|
267
|
+
accessibilityElementsHidden={!active}
|
|
268
|
+
importantForAccessibility={active ? 'auto' : 'no-hide-descendants'}
|
|
269
|
+
pointerEvents={active ? 'auto' : 'none'}
|
|
270
|
+
style={[StyleSheet.absoluteFill, { opacity, transform: [{ scale }, { translateX: offset }] }]}
|
|
271
|
+
>
|
|
272
|
+
{slide.source !== undefined ? (
|
|
273
|
+
renderImage ? (
|
|
274
|
+
renderImage(slide, slideIndex)
|
|
275
|
+
) : (
|
|
276
|
+
<Image
|
|
277
|
+
accessibilityLabel={slide.alt}
|
|
278
|
+
accessible={Boolean(slide.alt)}
|
|
279
|
+
resizeMode={resizeMode}
|
|
280
|
+
source={typeof slide.source === 'string' ? { uri: slide.source } : slide.source}
|
|
281
|
+
style={[StyleSheet.absoluteFill, imageStyle]}
|
|
282
|
+
/>
|
|
283
|
+
)
|
|
284
|
+
) : null}
|
|
285
|
+
{slide.content}
|
|
286
|
+
</Animated.View>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface CarouselNavigationProps {
|
|
291
|
+
readonly activeIndex: number;
|
|
292
|
+
readonly navigate: (index: number, direction: 1 | -1) => void;
|
|
293
|
+
readonly controlledWithoutHandler: boolean;
|
|
294
|
+
readonly testID: CarouselProps['testID'];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
interface CarouselControlsProps extends CarouselNavigationProps {
|
|
298
|
+
readonly show: boolean;
|
|
299
|
+
readonly canPrevious: boolean;
|
|
300
|
+
readonly canNext: boolean;
|
|
301
|
+
readonly previousLabel: string;
|
|
302
|
+
readonly nextLabel: string;
|
|
303
|
+
readonly controlColor: string;
|
|
304
|
+
readonly controlBackgroundColor: string;
|
|
305
|
+
readonly controlsStyle: CarouselProps['controlsStyle'];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/*** Render optional previous/next buttons without coupling the slide content to navigation. */
|
|
309
|
+
function CarouselControls({
|
|
310
|
+
activeIndex,
|
|
311
|
+
canNext,
|
|
312
|
+
canPrevious,
|
|
313
|
+
controlBackgroundColor,
|
|
314
|
+
controlColor,
|
|
315
|
+
controlledWithoutHandler,
|
|
316
|
+
controlsStyle,
|
|
317
|
+
navigate,
|
|
318
|
+
nextLabel,
|
|
319
|
+
previousLabel,
|
|
320
|
+
show,
|
|
321
|
+
testID,
|
|
322
|
+
}: CarouselControlsProps) {
|
|
323
|
+
if (!show) return null;
|
|
324
|
+
const buttonStyle = [styles.control, { backgroundColor: controlBackgroundColor }];
|
|
325
|
+
const labelStyle = { color: controlColor, fontSize: 30 };
|
|
326
|
+
return (
|
|
327
|
+
<View pointerEvents="box-none" style={[styles.controls, controlsStyle]}>
|
|
328
|
+
<Pressable
|
|
329
|
+
accessibilityLabel={previousLabel}
|
|
330
|
+
accessibilityRole="button"
|
|
331
|
+
disabled={!canPrevious || controlledWithoutHandler}
|
|
332
|
+
onPress={() => navigate(activeIndex - 1, -1)}
|
|
333
|
+
style={buttonStyle}
|
|
334
|
+
testID={testID ? `${testID}-previous` : undefined}
|
|
335
|
+
>
|
|
336
|
+
<Text style={labelStyle}>{'‹'}</Text>
|
|
337
|
+
</Pressable>
|
|
338
|
+
<Pressable
|
|
339
|
+
accessibilityLabel={nextLabel}
|
|
340
|
+
accessibilityRole="button"
|
|
341
|
+
disabled={!canNext || controlledWithoutHandler}
|
|
342
|
+
onPress={() => navigate(activeIndex + 1, 1)}
|
|
343
|
+
style={buttonStyle}
|
|
344
|
+
testID={testID ? `${testID}-next` : undefined}
|
|
345
|
+
>
|
|
346
|
+
<Text style={labelStyle}>{'›'}</Text>
|
|
347
|
+
</Pressable>
|
|
348
|
+
</View>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
interface CarouselIndicatorsProps extends CarouselNavigationProps {
|
|
353
|
+
readonly show: boolean;
|
|
354
|
+
readonly slides: CarouselProps['slides'];
|
|
355
|
+
readonly activeColor: string;
|
|
356
|
+
readonly idleColor: string;
|
|
357
|
+
readonly indicatorsStyle: CarouselProps['indicatorsStyle'];
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/*** Render accessible selection dots for the currently controlled slide. */
|
|
361
|
+
function CarouselIndicators({
|
|
362
|
+
activeIndex,
|
|
363
|
+
activeColor,
|
|
364
|
+
controlledWithoutHandler,
|
|
365
|
+
idleColor,
|
|
366
|
+
indicatorsStyle,
|
|
367
|
+
navigate,
|
|
368
|
+
show,
|
|
369
|
+
slides,
|
|
370
|
+
testID,
|
|
371
|
+
}: CarouselIndicatorsProps) {
|
|
372
|
+
if (!show) return null;
|
|
373
|
+
return (
|
|
374
|
+
<View pointerEvents="box-none" style={[styles.indicators, indicatorsStyle]}>
|
|
375
|
+
{slides.map((slide, slideIndex) => (
|
|
376
|
+
<Pressable
|
|
377
|
+
key={slide.key}
|
|
378
|
+
accessibilityLabel={`Go to slide ${slideIndex + 1} of ${slides.length}`}
|
|
379
|
+
accessibilityRole="button"
|
|
380
|
+
accessibilityState={{ selected: slideIndex === activeIndex }}
|
|
381
|
+
disabled={controlledWithoutHandler}
|
|
382
|
+
onPress={() => navigate(slideIndex, slideIndex < activeIndex ? -1 : 1)}
|
|
383
|
+
style={[
|
|
384
|
+
styles.indicator,
|
|
385
|
+
{
|
|
386
|
+
backgroundColor: slideIndex === activeIndex ? activeColor : idleColor,
|
|
387
|
+
width: slideIndex === activeIndex ? 24 : 8,
|
|
388
|
+
},
|
|
389
|
+
]}
|
|
390
|
+
testID={testID ? `${testID}-indicator-${slideIndex}` : undefined}
|
|
391
|
+
/>
|
|
392
|
+
))}
|
|
393
|
+
</View>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
interface CarouselProgressProps {
|
|
398
|
+
readonly show: boolean;
|
|
399
|
+
readonly height: number;
|
|
400
|
+
readonly trackColor: string;
|
|
401
|
+
readonly indicatorColor: string;
|
|
402
|
+
readonly trackStyle: CarouselProps['progressTrackStyle'];
|
|
403
|
+
readonly indicatorStyle: CarouselProps['progressIndicatorStyle'];
|
|
404
|
+
readonly progress: Animated.Value;
|
|
405
|
+
readonly testID: CarouselProps['testID'];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/*** Render an optional linear autoplay timer without adding any required UI to slides. */
|
|
409
|
+
function CarouselProgress({
|
|
410
|
+
height,
|
|
411
|
+
indicatorColor,
|
|
412
|
+
indicatorStyle,
|
|
413
|
+
progress,
|
|
414
|
+
show,
|
|
415
|
+
testID,
|
|
416
|
+
trackColor,
|
|
417
|
+
trackStyle,
|
|
418
|
+
}: CarouselProgressProps) {
|
|
419
|
+
if (!show) return null;
|
|
420
|
+
return (
|
|
421
|
+
<View
|
|
422
|
+
pointerEvents="none"
|
|
423
|
+
style={[styles.progress, { height, backgroundColor: trackColor }, trackStyle]}
|
|
424
|
+
testID={testID ? `${testID}-progress` : undefined}
|
|
425
|
+
>
|
|
426
|
+
<Animated.View
|
|
427
|
+
style={[
|
|
428
|
+
{
|
|
429
|
+
height: '100%',
|
|
430
|
+
width: progress.interpolate({ inputRange: [0, 1], outputRange: ['0%', '100%'] }),
|
|
431
|
+
backgroundColor: indicatorColor,
|
|
432
|
+
},
|
|
433
|
+
indicatorStyle,
|
|
434
|
+
]}
|
|
435
|
+
/>
|
|
436
|
+
</View>
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const styles = StyleSheet.create({
|
|
441
|
+
controls: {
|
|
442
|
+
position: 'absolute',
|
|
443
|
+
top: 0,
|
|
444
|
+
bottom: 0,
|
|
445
|
+
left: 14,
|
|
446
|
+
right: 14,
|
|
447
|
+
flexDirection: 'row',
|
|
448
|
+
justifyContent: 'space-between',
|
|
449
|
+
alignItems: 'center',
|
|
450
|
+
},
|
|
451
|
+
control: {
|
|
452
|
+
width: 44,
|
|
453
|
+
height: 44,
|
|
454
|
+
borderRadius: 22,
|
|
455
|
+
justifyContent: 'center',
|
|
456
|
+
alignItems: 'center',
|
|
457
|
+
},
|
|
458
|
+
indicators: {
|
|
459
|
+
position: 'absolute',
|
|
460
|
+
bottom: 24,
|
|
461
|
+
left: 0,
|
|
462
|
+
right: 0,
|
|
463
|
+
flexDirection: 'row',
|
|
464
|
+
gap: 10,
|
|
465
|
+
justifyContent: 'center',
|
|
466
|
+
alignItems: 'center',
|
|
467
|
+
},
|
|
468
|
+
indicator: { height: 8, borderRadius: 8 },
|
|
469
|
+
progress: { position: 'absolute', bottom: 0, left: 0, right: 0, overflow: 'hidden' },
|
|
470
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AccessibilityInfo, Animated, Easing } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { CarouselProps } from '../../types/carousel';
|
|
5
|
+
|
|
6
|
+
/*** Own controlled/uncontrolled slide navigation, autoplay, and progress lifecycle. */
|
|
7
|
+
export function useCarouselPlayback({
|
|
8
|
+
slides,
|
|
9
|
+
index,
|
|
10
|
+
defaultIndex = 0,
|
|
11
|
+
onIndexChange,
|
|
12
|
+
autoPlay = true,
|
|
13
|
+
paused = false,
|
|
14
|
+
loop = true,
|
|
15
|
+
intervalMs = 6000,
|
|
16
|
+
reducedMotion,
|
|
17
|
+
}: CarouselPlaybackOptions) {
|
|
18
|
+
const [uncontrolledIndex, setUncontrolledIndex] = React.useState(defaultIndex);
|
|
19
|
+
const [direction, setDirection] = React.useState<1 | -1>(1);
|
|
20
|
+
const [progress] = React.useState(() => new Animated.Value(0));
|
|
21
|
+
const systemReducedMotion = useSystemReducedMotion();
|
|
22
|
+
const shouldReduceMotion = reducedMotion ?? systemReducedMotion;
|
|
23
|
+
const activeIndex = normalizeIndex(index ?? uncontrolledIndex, slides.length);
|
|
24
|
+
const duration = Math.max(1, intervalMs);
|
|
25
|
+
const controlledWithoutHandler = index !== undefined && onIndexChange === undefined;
|
|
26
|
+
const canAdvance = loop || activeIndex < slides.length - 1;
|
|
27
|
+
const shouldPlay =
|
|
28
|
+
autoPlay && !paused && slides.length > 1 && canAdvance && !controlledWithoutHandler;
|
|
29
|
+
|
|
30
|
+
const navigate = React.useCallback(
|
|
31
|
+
(target: number, nextDirection: 1 | -1) => {
|
|
32
|
+
if (slides.length < 2 || controlledWithoutHandler) return;
|
|
33
|
+
const next = loop
|
|
34
|
+
? (target + slides.length) % slides.length
|
|
35
|
+
: normalizeIndex(target, slides.length);
|
|
36
|
+
if (next === activeIndex) return;
|
|
37
|
+
setDirection(nextDirection);
|
|
38
|
+
if (index === undefined) setUncontrolledIndex(next);
|
|
39
|
+
onIndexChange?.(next);
|
|
40
|
+
},
|
|
41
|
+
[activeIndex, controlledWithoutHandler, index, loop, onIndexChange, slides.length],
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (!shouldPlay) return;
|
|
46
|
+
const timeout = setTimeout(() => navigate(activeIndex + 1, 1), duration);
|
|
47
|
+
return () => clearTimeout(timeout);
|
|
48
|
+
}, [activeIndex, duration, navigate, shouldPlay]);
|
|
49
|
+
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
progress.stopAnimation();
|
|
52
|
+
progress.setValue(0);
|
|
53
|
+
if (!shouldPlay || shouldReduceMotion) return;
|
|
54
|
+
const animation = Animated.timing(progress, {
|
|
55
|
+
toValue: 1,
|
|
56
|
+
duration,
|
|
57
|
+
easing: Easing.linear,
|
|
58
|
+
useNativeDriver: false,
|
|
59
|
+
});
|
|
60
|
+
animation.start();
|
|
61
|
+
return () => animation.stop();
|
|
62
|
+
}, [activeIndex, duration, progress, shouldPlay, shouldReduceMotion]);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
activeIndex,
|
|
66
|
+
controlledWithoutHandler,
|
|
67
|
+
direction,
|
|
68
|
+
loop,
|
|
69
|
+
navigate,
|
|
70
|
+
progress,
|
|
71
|
+
shouldReduceMotion,
|
|
72
|
+
} as const;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type CarouselPlaybackOptions = Pick<
|
|
76
|
+
CarouselProps,
|
|
77
|
+
| 'slides'
|
|
78
|
+
| 'index'
|
|
79
|
+
| 'defaultIndex'
|
|
80
|
+
| 'onIndexChange'
|
|
81
|
+
| 'autoPlay'
|
|
82
|
+
| 'paused'
|
|
83
|
+
| 'loop'
|
|
84
|
+
| 'intervalMs'
|
|
85
|
+
| 'reducedMotion'
|
|
86
|
+
>;
|
|
87
|
+
|
|
88
|
+
/*** Clamp a controlled index whenever the consumer changes the slide collection. */
|
|
89
|
+
function normalizeIndex(value: number, count: number): number {
|
|
90
|
+
if (count <= 0 || !Number.isFinite(value)) return 0;
|
|
91
|
+
return Math.min(Math.max(Math.trunc(value), 0), count - 1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/*** Observe reduced-motion preferences without adding browser-only imports. */
|
|
95
|
+
function useSystemReducedMotion(): boolean {
|
|
96
|
+
const [reduced, setReduced] = React.useState(false);
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
void AccessibilityInfo.isReduceMotionEnabled().then(setReduced);
|
|
99
|
+
const listener = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduced);
|
|
100
|
+
return () => listener.remove();
|
|
101
|
+
}, []);
|
|
102
|
+
return reduced;
|
|
103
|
+
}
|
|
@@ -19,8 +19,11 @@ function ScreenInner({
|
|
|
19
19
|
const content = (
|
|
20
20
|
<View
|
|
21
21
|
alignSelf="center"
|
|
22
|
+
flex={scroll ? undefined : 1}
|
|
22
23
|
gap="l"
|
|
23
24
|
maxWidth={resolvePageMaxWidth(width)}
|
|
25
|
+
minHeight={scroll ? undefined : 0}
|
|
26
|
+
minWidth={scroll ? undefined : 0}
|
|
24
27
|
px={{ base: 16, md: 24, lg: 32 }}
|
|
25
28
|
py="xl"
|
|
26
29
|
testID={testID}
|