@hero-design/rn 8.22.0 → 8.24.0-alpha.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/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-build:types.log +2 -0
- package/.turbo/turbo-lint.log +146 -0
- package/.turbo/turbo-publish:npm.log +9 -0
- package/.turbo/turbo-test.log +451 -0
- package/.turbo/turbo-type-check.log +1 -0
- package/es/index.js +527 -165
- package/lib/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/lib/index.js +527 -164
- package/package.json +5 -5
- package/src/components/Alert/index.tsx +6 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePicker.spec.tsx.snap +21 -9
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +7 -3
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerCalendar.spec.tsx.snap +7 -3
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +7 -3
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
- package/src/components/Error/__tests__/__snapshots__/index.spec.tsx.snap +5 -5
- package/src/components/List/ListItem.tsx +12 -8
- package/src/components/RichTextEditor/RichTextEditor.tsx +10 -7
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +10 -8
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +37 -16
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/index.spec.tsx.snap +37 -16
- package/src/components/Success/StyledSuccess.tsx +87 -0
- package/src/components/Success/__tests__/__snapshots__/index.spec.tsx.snap +497 -0
- package/src/components/Success/__tests__/index.spec.tsx +78 -0
- package/src/components/Success/index.tsx +129 -0
- package/src/components/Tabs/ScrollableTabs.tsx +10 -149
- package/src/components/Tabs/ScrollableTabsHeader.tsx +214 -0
- package/src/components/Tabs/ScrollableTabsV2/SceneView.tsx +61 -0
- package/src/components/Tabs/ScrollableTabsV2/ScrollableTabsV2.tsx +120 -0
- package/src/components/Tabs/ScrollableTabsV2/__tests__/SceneView.spec.tsx +76 -0
- package/src/components/Tabs/ScrollableTabsV2/__tests__/ScrollableTabsV2.spec.tsx +166 -0
- package/src/components/Tabs/ScrollableTabsV2/__tests__/__snapshots__/SceneView.spec.tsx.snap +161 -0
- package/src/components/Tabs/ScrollableTabsV2/__tests__/__snapshots__/ScrollableTabsV2.spec.tsx.snap +2497 -0
- package/src/components/Tabs/ScrollableTabsV2/index.tsx +5 -0
- package/src/components/Tabs/__tests__/ScrollableTabsHeader.spec.tsx +80 -0
- package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabsHeader.spec.tsx.snap +587 -0
- package/src/components/Tabs/index.tsx +2 -0
- package/src/components/Tag/StyledTag.tsx +1 -1
- package/src/components/Tag/__tests__/Tag.spec.tsx +22 -71
- package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +106 -53
- package/src/components/TextInput/StyledTextInput.tsx +40 -29
- package/src/components/TextInput/__tests__/StyledTextInput.spec.tsx +48 -57
- package/src/components/TextInput/__tests__/__snapshots__/StyledTextInput.spec.tsx.snap +84 -58
- package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +587 -70
- package/src/components/TextInput/__tests__/index.spec.tsx +45 -4
- package/src/components/TextInput/index.tsx +31 -16
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +14 -6
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +14 -6
- package/src/index.ts +2 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +41 -6
- package/src/theme/components/empty.ts +1 -1
- package/src/theme/components/error.ts +1 -1
- package/src/theme/components/success.ts +40 -0
- package/src/theme/components/tag.ts +1 -1
- package/src/theme/components/textInput.ts +10 -4
- package/src/theme/getTheme.ts +3 -0
- package/src/utils/hooks.ts +1 -1
- package/testUtils/setup.tsx +6 -0
- package/types/components/Accordion/AccordionItem.d.ts +0 -0
- package/types/components/Accordion/StyledAccordion.d.ts +0 -0
- package/types/components/Accordion/index.d.ts +0 -0
- package/types/components/Alert/StyledAlert.d.ts +0 -0
- package/types/components/Alert/index.d.ts +0 -0
- package/types/components/Attachment/StyledAttachment.d.ts +0 -0
- package/types/components/Attachment/index.d.ts +0 -0
- package/types/components/Avatar/Avatar.d.ts +0 -0
- package/types/components/Avatar/AvatarStack/StyledAvatarStack.d.ts +0 -0
- package/types/components/Avatar/AvatarStack/index.d.ts +0 -0
- package/types/components/Avatar/AvatarStack/utils.d.ts +0 -0
- package/types/components/Avatar/StyledAvatar.d.ts +0 -0
- package/types/components/Avatar/index.d.ts +0 -0
- package/types/components/Badge/Status.d.ts +0 -0
- package/types/components/Badge/StyledBadge.d.ts +0 -0
- package/types/components/Badge/index.d.ts +0 -0
- package/types/components/BottomNavigation/StyledBottomNavigation.d.ts +0 -0
- package/types/components/BottomNavigation/index.d.ts +0 -0
- package/types/components/BottomSheet/BottomSheetContext.d.ts +0 -0
- package/types/components/BottomSheet/Footer.d.ts +0 -0
- package/types/components/BottomSheet/Header.d.ts +0 -0
- package/types/components/BottomSheet/ScrollView.d.ts +0 -0
- package/types/components/BottomSheet/StyledBottomSheet.d.ts +0 -0
- package/types/components/BottomSheet/index.d.ts +0 -0
- package/types/components/Box/StyledBox.d.ts +0 -0
- package/types/components/Box/config.d.ts +0 -0
- package/types/components/Box/index.d.ts +0 -0
- package/types/components/Box/types.d.ts +0 -0
- package/types/components/Button/Button.d.ts +0 -0
- package/types/components/Button/IconButton.d.ts +0 -0
- package/types/components/Button/LoadingIndicator/StyledLoadingIndicator.d.ts +0 -0
- package/types/components/Button/LoadingIndicator/index.d.ts +0 -0
- package/types/components/Button/StyledButton.d.ts +0 -0
- package/types/components/Button/UtilityButton/StyledUtilityButton.d.ts +0 -0
- package/types/components/Button/UtilityButton/index.d.ts +0 -0
- package/types/components/Button/index.d.ts +0 -0
- package/types/components/Calendar/CalendarRowItem.d.ts +0 -0
- package/types/components/Calendar/StyledCalendar.d.ts +0 -0
- package/types/components/Calendar/helpers.d.ts +0 -0
- package/types/components/Calendar/index.d.ts +0 -0
- package/types/components/Card/DataCard/StyledDataCard.d.ts +0 -0
- package/types/components/Card/DataCard/index.d.ts +0 -0
- package/types/components/Card/StyledCard.d.ts +0 -0
- package/types/components/Card/index.d.ts +0 -0
- package/types/components/Carousel/CardCarousel.d.ts +0 -0
- package/types/components/Carousel/CarouselItem.d.ts +0 -0
- package/types/components/Carousel/StyledCardCarousel.d.ts +0 -0
- package/types/components/Carousel/StyledCarousel.d.ts +0 -0
- package/types/components/Carousel/contants.d.ts +0 -0
- package/types/components/Carousel/index.d.ts +0 -0
- package/types/components/Carousel/types.d.ts +0 -0
- package/types/components/Checkbox/StyledCheckbox.d.ts +0 -0
- package/types/components/Checkbox/index.d.ts +0 -0
- package/types/components/Collapse/StyledCollapse.d.ts +0 -0
- package/types/components/Collapse/index.d.ts +0 -0
- package/types/components/ContentNavigator/StyledContentNavigator.d.ts +0 -0
- package/types/components/ContentNavigator/index.d.ts +0 -0
- package/types/components/DatePicker/DatePickerAndroid.d.ts +0 -0
- package/types/components/DatePicker/DatePickerCalendar.d.ts +0 -0
- package/types/components/DatePicker/DatePickerIOS.d.ts +0 -0
- package/types/components/DatePicker/StyledDatePicker.d.ts +0 -0
- package/types/components/DatePicker/index.d.ts +0 -0
- package/types/components/DatePicker/types.d.ts +0 -0
- package/types/components/Divider/StyledDivider.d.ts +0 -0
- package/types/components/Divider/index.d.ts +0 -0
- package/types/components/Drawer/DragableDrawer/helpers.d.ts +0 -0
- package/types/components/Drawer/DragableDrawer/index.d.ts +0 -0
- package/types/components/Drawer/StyledDrawer.d.ts +0 -0
- package/types/components/Drawer/index.d.ts +0 -0
- package/types/components/Empty/StyledEmpty.d.ts +0 -0
- package/types/components/Empty/index.d.ts +0 -0
- package/types/components/Error/StyledError.d.ts +0 -0
- package/types/components/Error/index.d.ts +0 -0
- package/types/components/FAB/ActionGroup/ActionItem.d.ts +0 -0
- package/types/components/FAB/ActionGroup/StyledActionGroup.d.ts +0 -0
- package/types/components/FAB/ActionGroup/StyledActionItem.d.ts +0 -0
- package/types/components/FAB/ActionGroup/index.d.ts +0 -0
- package/types/components/FAB/AnimatedFABIcon.d.ts +0 -0
- package/types/components/FAB/FAB.d.ts +0 -0
- package/types/components/FAB/StyledFAB.d.ts +0 -0
- package/types/components/FAB/index.d.ts +0 -0
- package/types/components/Icon/AnimatedIcon.d.ts +0 -0
- package/types/components/Icon/HeroIcon/index.d.ts +0 -0
- package/types/components/Icon/IconList.d.ts +0 -0
- package/types/components/Icon/index.d.ts +0 -0
- package/types/components/Icon/utils.d.ts +0 -0
- package/types/components/Image/index.d.ts +0 -0
- package/types/components/List/BasicListItem.d.ts +0 -0
- package/types/components/List/ListItem.d.ts +0 -0
- package/types/components/List/StyledBasicListItem.d.ts +0 -0
- package/types/components/List/StyledListItem.d.ts +0 -0
- package/types/components/List/index.d.ts +0 -0
- package/types/components/PageControl/StyledPageControl.d.ts +0 -0
- package/types/components/PageControl/index.d.ts +0 -0
- package/types/components/PinInput/PinCell.d.ts +0 -0
- package/types/components/PinInput/StyledPinInput.d.ts +0 -0
- package/types/components/PinInput/index.d.ts +0 -0
- package/types/components/Progress/ProgressBar.d.ts +0 -0
- package/types/components/Progress/ProgressCircle.d.ts +0 -0
- package/types/components/Progress/StyledProgressBar.d.ts +0 -0
- package/types/components/Progress/StyledProgressCircle.d.ts +0 -0
- package/types/components/Progress/__tests__/index.spec.d.ts +0 -0
- package/types/components/Progress/constants.d.ts +0 -0
- package/types/components/Progress/index.d.ts +0 -0
- package/types/components/Progress/types.d.ts +0 -0
- package/types/components/Radio/Radio.d.ts +0 -0
- package/types/components/Radio/RadioGroup.d.ts +0 -0
- package/types/components/Radio/StyledRadio.d.ts +0 -0
- package/types/components/Radio/index.d.ts +0 -0
- package/types/components/Radio/types.d.ts +0 -0
- package/types/components/RefreshControl/index.d.ts +0 -0
- package/types/components/RichTextEditor/EditorEvent.d.ts +0 -0
- package/types/components/RichTextEditor/EditorToolbar.d.ts +0 -0
- package/types/components/RichTextEditor/MentionList.d.ts +0 -0
- package/types/components/RichTextEditor/RichTextEditor.d.ts +0 -0
- package/types/components/RichTextEditor/StyledRichTextEditor.d.ts +0 -0
- package/types/components/RichTextEditor/StyledToolbar.d.ts +0 -0
- package/types/components/RichTextEditor/__mocks__/heroEditorApp.d.ts +0 -0
- package/types/components/RichTextEditor/constants.d.ts +0 -0
- package/types/components/RichTextEditor/heroEditorApp.d.ts +0 -0
- package/types/components/RichTextEditor/index.d.ts +0 -0
- package/types/components/RichTextEditor/types.d.ts +0 -0
- package/types/components/RichTextEditor/utils/events.d.ts +0 -0
- package/types/components/RichTextEditor/utils/rnWebView.d.ts +0 -0
- package/types/components/SectionHeading/StyledHeading.d.ts +0 -0
- package/types/components/SectionHeading/index.d.ts +0 -0
- package/types/components/Select/BaseOptionList.d.ts +0 -0
- package/types/components/Select/Footer.d.ts +0 -0
- package/types/components/Select/MultiSelect/Option.d.ts +0 -0
- package/types/components/Select/MultiSelect/OptionList.d.ts +0 -0
- package/types/components/Select/MultiSelect/index.d.ts +0 -0
- package/types/components/Select/SingleSelect/Option.d.ts +0 -0
- package/types/components/Select/SingleSelect/OptionList.d.ts +0 -0
- package/types/components/Select/SingleSelect/StyledSingleSelect.d.ts +0 -0
- package/types/components/Select/SingleSelect/index.d.ts +0 -0
- package/types/components/Select/StyledSelect.d.ts +0 -0
- package/types/components/Select/helpers.d.ts +0 -0
- package/types/components/Select/index.d.ts +0 -0
- package/types/components/Select/types.d.ts +0 -0
- package/types/components/Skeleton/StyledSkeleton.d.ts +0 -0
- package/types/components/Skeleton/index.d.ts +0 -0
- package/types/components/Slider/index.d.ts +0 -0
- package/types/components/Spinner/AnimatedSpinner.d.ts +0 -0
- package/types/components/Spinner/StyledSpinner.d.ts +0 -0
- package/types/components/Spinner/index.d.ts +0 -0
- package/types/components/Success/StyledSuccess.d.ts +54 -0
- package/types/components/Success/index.d.ts +42 -0
- package/types/components/Swipeable/StyledSwipeable.d.ts +0 -0
- package/types/components/Swipeable/SwipeableAction.d.ts +0 -0
- package/types/components/Swipeable/index.d.ts +0 -0
- package/types/components/Switch/SelectorSwitch/Option.d.ts +0 -0
- package/types/components/Switch/SelectorSwitch/StyledSelectorSwitch.d.ts +0 -0
- package/types/components/Switch/SelectorSwitch/index.d.ts +0 -0
- package/types/components/Switch/StyledSwitch.d.ts +0 -0
- package/types/components/Switch/index.d.ts +0 -0
- package/types/components/Tabs/ActiveTabIndicator.d.ts +0 -0
- package/types/components/Tabs/SceneView.d.ts +9 -0
- package/types/components/Tabs/ScrollableTabs.d.ts +0 -0
- package/types/components/Tabs/ScrollableTabsHeader.d.ts +35 -0
- package/types/components/Tabs/ScrollableTabsV2/SceneView.d.ts +10 -0
- package/types/components/Tabs/ScrollableTabsV2/ScrollableTabsV2.d.ts +9 -0
- package/types/components/Tabs/ScrollableTabsV2/index.d.ts +4 -0
- package/types/components/Tabs/StyledScrollableTabs.d.ts +0 -0
- package/types/components/Tabs/StyledTabs.d.ts +0 -0
- package/types/components/Tabs/TabWithBadge.d.ts +0 -0
- package/types/components/Tabs/index.d.ts +3 -0
- package/types/components/Tabs/utils.d.ts +0 -0
- package/types/components/Tag/StyledTag.d.ts +0 -0
- package/types/components/Tag/index.d.ts +0 -0
- package/types/components/TextInput/StyledTextInput.d.ts +12 -7
- package/types/components/TextInput/index.d.ts +12 -4
- package/types/components/TimePicker/StyledTimePicker.d.ts +0 -0
- package/types/components/TimePicker/TimePickerAndroid.d.ts +0 -0
- package/types/components/TimePicker/TimePickerIOS.d.ts +0 -0
- package/types/components/TimePicker/index.d.ts +0 -0
- package/types/components/TimePicker/types.d.ts +0 -0
- package/types/components/Toast/StyledToast.d.ts +0 -0
- package/types/components/Toast/Toast.d.ts +0 -0
- package/types/components/Toast/ToastContainer.d.ts +0 -0
- package/types/components/Toast/ToastContext.d.ts +0 -0
- package/types/components/Toast/ToastProvider.d.ts +0 -0
- package/types/components/Toast/index.d.ts +0 -0
- package/types/components/Toast/types.d.ts +0 -0
- package/types/components/Toolbar/StyledToolbar.d.ts +0 -0
- package/types/components/Toolbar/ToolbarGroup.d.ts +0 -0
- package/types/components/Toolbar/ToolbarItem.d.ts +0 -0
- package/types/components/Toolbar/index.d.ts +0 -0
- package/types/components/Typography/Text/StyledText.d.ts +0 -0
- package/types/components/Typography/Text/index.d.ts +0 -0
- package/types/components/Typography/index.d.ts +0 -0
- package/types/index.d.ts +2 -1
- package/types/testHelpers/renderWithTheme.d.ts +0 -0
- package/types/theme/ThemeProvider.d.ts +0 -0
- package/types/theme/ThemeSwitcher.d.ts +0 -0
- package/types/theme/components/accordion.d.ts +0 -0
- package/types/theme/components/alert.d.ts +0 -0
- package/types/theme/components/attachment.d.ts +0 -0
- package/types/theme/components/avatar.d.ts +0 -0
- package/types/theme/components/badge.d.ts +0 -0
- package/types/theme/components/bottomNavigation.d.ts +0 -0
- package/types/theme/components/bottomSheet.d.ts +0 -0
- package/types/theme/components/button.d.ts +0 -0
- package/types/theme/components/calendar.d.ts +0 -0
- package/types/theme/components/card.d.ts +0 -0
- package/types/theme/components/cardCarousel.d.ts +0 -0
- package/types/theme/components/carousel.d.ts +0 -0
- package/types/theme/components/checkbox.d.ts +0 -0
- package/types/theme/components/contentNavigator.d.ts +0 -0
- package/types/theme/components/datePicker.d.ts +0 -0
- package/types/theme/components/divider.d.ts +0 -0
- package/types/theme/components/drawer.d.ts +0 -0
- package/types/theme/components/empty.d.ts +0 -0
- package/types/theme/components/error.d.ts +0 -0
- package/types/theme/components/fab.d.ts +0 -0
- package/types/theme/components/icon.d.ts +0 -0
- package/types/theme/components/image.d.ts +0 -0
- package/types/theme/components/list.d.ts +0 -0
- package/types/theme/components/pageControl.d.ts +0 -0
- package/types/theme/components/pinInput.d.ts +0 -0
- package/types/theme/components/progress.d.ts +0 -0
- package/types/theme/components/radio.d.ts +0 -0
- package/types/theme/components/refreshControl.d.ts +0 -0
- package/types/theme/components/richTextEditor.d.ts +0 -0
- package/types/theme/components/sectionHeading.d.ts +0 -0
- package/types/theme/components/select.d.ts +0 -0
- package/types/theme/components/skeleton.d.ts +0 -0
- package/types/theme/components/slider.d.ts +0 -0
- package/types/theme/components/spinner.d.ts +0 -0
- package/types/theme/components/success.d.ts +32 -0
- package/types/theme/components/swipeable.d.ts +0 -0
- package/types/theme/components/switch.d.ts +0 -0
- package/types/theme/components/tabs.d.ts +0 -0
- package/types/theme/components/tag.d.ts +0 -0
- package/types/theme/components/textInput.d.ts +5 -0
- package/types/theme/components/timePicker.d.ts +0 -0
- package/types/theme/components/toast.d.ts +0 -0
- package/types/theme/components/toolbar.d.ts +0 -0
- package/types/theme/components/typography.d.ts +0 -0
- package/types/theme/getTheme.d.ts +2 -0
- package/types/theme/global/borders.d.ts +0 -0
- package/types/theme/global/colors/eBens.d.ts +0 -0
- package/types/theme/global/colors/global.d.ts +0 -0
- package/types/theme/global/colors/globalDark.d.ts +0 -0
- package/types/theme/global/colors/jobs.d.ts +0 -0
- package/types/theme/global/colors/swag.d.ts +0 -0
- package/types/theme/global/colors/swagDark.d.ts +0 -0
- package/types/theme/global/colors/types.d.ts +0 -0
- package/types/theme/global/colors/wallet.d.ts +0 -0
- package/types/theme/global/colors/work.d.ts +0 -0
- package/types/theme/global/index.d.ts +0 -0
- package/types/theme/global/scale.d.ts +0 -0
- package/types/theme/global/sizes.d.ts +0 -0
- package/types/theme/global/space.d.ts +0 -0
- package/types/theme/global/typography.d.ts +0 -0
- package/types/theme/index.d.ts +0 -0
- package/types/types.d.ts +0 -0
- package/types/utils/functions.d.ts +0 -0
- package/types/utils/helpers.d.ts +0 -0
- package/types/utils/hooks.d.ts +0 -0
- package/types/utils/scale.d.ts +0 -0
|
@@ -1,59 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TouchableWithoutFeedback, FlatList, Animated } from 'react-native';
|
|
3
2
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
-
import { useTheme } from '@emotion/react';
|
|
5
3
|
import PagerView from 'react-native-pager-view';
|
|
6
4
|
import {
|
|
7
|
-
HeaderTabItem,
|
|
8
|
-
HeaderTabWrapper,
|
|
9
5
|
TabContainer,
|
|
10
6
|
TabScreen,
|
|
11
7
|
ContentWrapper,
|
|
12
|
-
HeaderTabItemOutline,
|
|
13
|
-
HeaderTabItemWrapper,
|
|
14
|
-
HeaderTabItemOutlineWrapper,
|
|
15
8
|
} from './StyledScrollableTabs';
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import Icon from '../Icon';
|
|
19
|
-
import Typography from '../Typography';
|
|
20
|
-
import type { ItemType, TabsProps, TabType } from '.';
|
|
21
|
-
import TabWithBadge from './TabWithBadge';
|
|
22
|
-
|
|
23
|
-
const getTabItem = ({
|
|
24
|
-
item,
|
|
25
|
-
color,
|
|
26
|
-
active,
|
|
27
|
-
}: {
|
|
28
|
-
item: ItemType;
|
|
29
|
-
color: string;
|
|
30
|
-
active: boolean;
|
|
31
|
-
}) => {
|
|
32
|
-
if (isHeroIcon(item)) {
|
|
33
|
-
return (
|
|
34
|
-
<Icon
|
|
35
|
-
icon={item}
|
|
36
|
-
testID={`hero-icon-${item}`}
|
|
37
|
-
size="small"
|
|
38
|
-
style={{ color }}
|
|
39
|
-
/>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (typeof item === 'string') {
|
|
44
|
-
return (
|
|
45
|
-
<Typography.Text
|
|
46
|
-
fontWeight={active ? 'semi-bold' : 'regular'}
|
|
47
|
-
numberOfLines={1}
|
|
48
|
-
style={{ color }}
|
|
49
|
-
>
|
|
50
|
-
{item}
|
|
51
|
-
</Typography.Text>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return item({ color });
|
|
56
|
-
};
|
|
9
|
+
import type { TabsProps } from '.';
|
|
10
|
+
import ScrollableTabHeader from './ScrollableTabsHeader';
|
|
57
11
|
|
|
58
12
|
const ScrollableTab = ({
|
|
59
13
|
onTabPress,
|
|
@@ -66,24 +20,14 @@ const ScrollableTab = ({
|
|
|
66
20
|
swipeEnabled = true,
|
|
67
21
|
testID: componentTestID,
|
|
68
22
|
}: TabsProps) => {
|
|
69
|
-
const flatListRef = React.useRef<FlatList>(null);
|
|
70
23
|
const pagerViewRef = React.useRef<PagerView>(null);
|
|
71
24
|
const insets = useSafeAreaInsets();
|
|
72
|
-
const theme = useTheme();
|
|
73
25
|
const selectedTabIndex = tabs.findIndex(
|
|
74
26
|
(item) => item.key === selectedTabKey
|
|
75
27
|
);
|
|
76
|
-
const tabsAnims = useAnimatedValueArray(
|
|
77
|
-
tabs.map((_, i) => (i === selectedTabIndex ? 1 : 0))
|
|
78
|
-
);
|
|
79
|
-
|
|
80
28
|
React.useEffect(() => {
|
|
81
29
|
let timeoutHandle: number | null = null;
|
|
82
30
|
if (selectedTabIndex !== -1) {
|
|
83
|
-
flatListRef.current?.scrollToIndex({
|
|
84
|
-
index: selectedTabIndex,
|
|
85
|
-
viewPosition: 0.5,
|
|
86
|
-
});
|
|
87
31
|
// If the selected tab is changed too quickly, the setPage is crashed and not work anymore
|
|
88
32
|
// We apply throttle to prevent this issue https://github.com/Thinkei/hero-design/issues/1715
|
|
89
33
|
timeoutHandle = setTimeout(() => {
|
|
@@ -92,19 +36,7 @@ const ScrollableTab = ({
|
|
|
92
36
|
}, 200);
|
|
93
37
|
}
|
|
94
38
|
|
|
95
|
-
const animation = Animated.parallel([
|
|
96
|
-
...tabs.map((_, i) =>
|
|
97
|
-
Animated.timing(tabsAnims[i], {
|
|
98
|
-
toValue: i === selectedTabIndex ? 1 : 0,
|
|
99
|
-
duration: 150,
|
|
100
|
-
useNativeDriver: true,
|
|
101
|
-
})
|
|
102
|
-
),
|
|
103
|
-
]);
|
|
104
|
-
animation.start();
|
|
105
|
-
|
|
106
39
|
return () => {
|
|
107
|
-
animation.stop();
|
|
108
40
|
if (timeoutHandle) {
|
|
109
41
|
clearTimeout(timeoutHandle);
|
|
110
42
|
}
|
|
@@ -113,85 +45,14 @@ const ScrollableTab = ({
|
|
|
113
45
|
|
|
114
46
|
return (
|
|
115
47
|
<TabContainer style={containerStyle} testID={componentTestID}>
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
onScrollToIndexFailed={({ index }) => {
|
|
125
|
-
setTimeout(
|
|
126
|
-
() =>
|
|
127
|
-
flatListRef.current?.scrollToIndex({
|
|
128
|
-
index,
|
|
129
|
-
viewPosition: 0.5,
|
|
130
|
-
}),
|
|
131
|
-
100
|
|
132
|
-
);
|
|
133
|
-
}}
|
|
134
|
-
contentContainerStyle={{
|
|
135
|
-
paddingHorizontal:
|
|
136
|
-
theme.__hd__.tabs.space.flatListHorizontalPadding,
|
|
137
|
-
}}
|
|
138
|
-
renderItem={({ item: tab, index }) => {
|
|
139
|
-
const {
|
|
140
|
-
key,
|
|
141
|
-
testID,
|
|
142
|
-
activeItem,
|
|
143
|
-
inactiveItem: originalInactiveItem,
|
|
144
|
-
badge,
|
|
145
|
-
} = tab;
|
|
146
|
-
const active = selectedTabKey === key;
|
|
147
|
-
const activeAnimated = tabsAnims[index];
|
|
148
|
-
const outlineScale = active
|
|
149
|
-
? activeAnimated.interpolate({
|
|
150
|
-
inputRange: [0, 1],
|
|
151
|
-
outputRange: [0.5, 1],
|
|
152
|
-
})
|
|
153
|
-
: 0;
|
|
154
|
-
|
|
155
|
-
const inactiveItem = originalInactiveItem ?? activeItem;
|
|
156
|
-
const tabItem = getTabItem({
|
|
157
|
-
item: active ? activeItem : inactiveItem,
|
|
158
|
-
color: active
|
|
159
|
-
? theme.__hd__.tabs.colors.active
|
|
160
|
-
: theme.__hd__.tabs.colors.inactive,
|
|
161
|
-
active,
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<TouchableWithoutFeedback
|
|
166
|
-
key={key}
|
|
167
|
-
onPress={() => {
|
|
168
|
-
onTabPress(key);
|
|
169
|
-
}}
|
|
170
|
-
testID={testID}
|
|
171
|
-
>
|
|
172
|
-
<HeaderTabItem isFirstItem={index === 0}>
|
|
173
|
-
<HeaderTabItemOutlineWrapper>
|
|
174
|
-
<HeaderTabItemOutline
|
|
175
|
-
themeActive={active}
|
|
176
|
-
style={{
|
|
177
|
-
flex: 1,
|
|
178
|
-
transform: [
|
|
179
|
-
{
|
|
180
|
-
scaleX: outlineScale,
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
}}
|
|
184
|
-
/>
|
|
185
|
-
</HeaderTabItemOutlineWrapper>
|
|
186
|
-
<HeaderTabItemWrapper>
|
|
187
|
-
<TabWithBadge config={badge} tabItem={tabItem} />
|
|
188
|
-
</HeaderTabItemWrapper>
|
|
189
|
-
</HeaderTabItem>
|
|
190
|
-
</TouchableWithoutFeedback>
|
|
191
|
-
);
|
|
192
|
-
}}
|
|
193
|
-
/>
|
|
194
|
-
</HeaderTabWrapper>
|
|
48
|
+
<ScrollableTabHeader
|
|
49
|
+
tabs={tabs}
|
|
50
|
+
selectedIndex={selectedTabIndex}
|
|
51
|
+
onTabPress={onTabPress}
|
|
52
|
+
barStyle={barStyle}
|
|
53
|
+
insets={insets}
|
|
54
|
+
testID={componentTestID ? `${componentTestID}-tab-bar` : undefined}
|
|
55
|
+
/>
|
|
195
56
|
<ContentWrapper
|
|
196
57
|
initialPage={selectedTabIndex}
|
|
197
58
|
ref={pagerViewRef}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TouchableWithoutFeedback,
|
|
4
|
+
FlatList,
|
|
5
|
+
Animated,
|
|
6
|
+
StyleProp,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
ViewProps,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { useTheme } from '@emotion/react';
|
|
11
|
+
import {
|
|
12
|
+
HeaderTabItem,
|
|
13
|
+
HeaderTabWrapper,
|
|
14
|
+
HeaderTabItemOutline,
|
|
15
|
+
HeaderTabItemWrapper,
|
|
16
|
+
HeaderTabItemOutlineWrapper,
|
|
17
|
+
} from './StyledScrollableTabs';
|
|
18
|
+
import { useAnimatedValueArray } from './utils';
|
|
19
|
+
import { isHeroIcon } from '../Icon/utils';
|
|
20
|
+
import Icon from '../Icon';
|
|
21
|
+
import Typography from '../Typography';
|
|
22
|
+
import type { ItemType, TabType } from '.';
|
|
23
|
+
import TabWithBadge from './TabWithBadge';
|
|
24
|
+
|
|
25
|
+
const getTabItem = ({
|
|
26
|
+
item,
|
|
27
|
+
color,
|
|
28
|
+
active,
|
|
29
|
+
}: {
|
|
30
|
+
item: ItemType;
|
|
31
|
+
color: string;
|
|
32
|
+
active: boolean;
|
|
33
|
+
}) => {
|
|
34
|
+
if (isHeroIcon(item)) {
|
|
35
|
+
return (
|
|
36
|
+
<Icon
|
|
37
|
+
icon={item}
|
|
38
|
+
testID={`hero-icon-${item}`}
|
|
39
|
+
size="small"
|
|
40
|
+
style={{ color }}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof item === 'string') {
|
|
46
|
+
return (
|
|
47
|
+
<Typography.Text
|
|
48
|
+
fontWeight={active ? 'semi-bold' : 'regular'}
|
|
49
|
+
numberOfLines={1}
|
|
50
|
+
style={{ color }}
|
|
51
|
+
>
|
|
52
|
+
{item}
|
|
53
|
+
</Typography.Text>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return item({ color });
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export interface ScrollableTabHeaderProps extends ViewProps {
|
|
61
|
+
/**
|
|
62
|
+
* Callback which is called on tab press, receiving key of upcoming active Tab.
|
|
63
|
+
*/
|
|
64
|
+
onTabPress: (key: string) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Current selected tab key.
|
|
67
|
+
*/
|
|
68
|
+
selectedIndex?: number;
|
|
69
|
+
/**
|
|
70
|
+
* List of Tabs to be rendered. Each Tab must have an unique key.
|
|
71
|
+
*/
|
|
72
|
+
tabs: TabType[];
|
|
73
|
+
/**
|
|
74
|
+
* Style for the tab navigation bar.
|
|
75
|
+
*/
|
|
76
|
+
barStyle?: StyleProp<ViewStyle>;
|
|
77
|
+
/**
|
|
78
|
+
* Testing id of the component.
|
|
79
|
+
*/
|
|
80
|
+
testID?: string;
|
|
81
|
+
/**
|
|
82
|
+
* component insets
|
|
83
|
+
*/
|
|
84
|
+
insets?: {
|
|
85
|
+
top: number;
|
|
86
|
+
bottom: number;
|
|
87
|
+
right: number;
|
|
88
|
+
left: number;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const ScrollableTabHeader = ({
|
|
92
|
+
onTabPress,
|
|
93
|
+
selectedIndex,
|
|
94
|
+
tabs,
|
|
95
|
+
barStyle,
|
|
96
|
+
testID,
|
|
97
|
+
insets = { top: 0, bottom: 0, right: 0, left: 0 },
|
|
98
|
+
}: ScrollableTabHeaderProps) => {
|
|
99
|
+
const flatListRef = React.useRef<FlatList>(null);
|
|
100
|
+
const theme = useTheme();
|
|
101
|
+
const tabsAnims = useAnimatedValueArray(
|
|
102
|
+
tabs.map((_, i) => (i === selectedIndex ? 1 : 0))
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
const timeoutHandle: number | null = null;
|
|
107
|
+
if (selectedIndex !== undefined && selectedIndex !== -1) {
|
|
108
|
+
flatListRef.current?.scrollToIndex({
|
|
109
|
+
index: selectedIndex,
|
|
110
|
+
viewPosition: 0.5,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const animation = Animated.parallel([
|
|
115
|
+
...tabs.map((_, i) =>
|
|
116
|
+
Animated.timing(tabsAnims[i], {
|
|
117
|
+
toValue: i === selectedIndex ? 1 : 0,
|
|
118
|
+
duration: 150,
|
|
119
|
+
useNativeDriver: true,
|
|
120
|
+
})
|
|
121
|
+
),
|
|
122
|
+
]);
|
|
123
|
+
animation.start();
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
animation.stop();
|
|
127
|
+
if (timeoutHandle) {
|
|
128
|
+
clearTimeout(timeoutHandle);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}, [selectedIndex]);
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<HeaderTabWrapper themeInsets={insets} style={barStyle}>
|
|
135
|
+
<FlatList<TabType>
|
|
136
|
+
testID={testID}
|
|
137
|
+
ref={flatListRef}
|
|
138
|
+
horizontal
|
|
139
|
+
data={tabs}
|
|
140
|
+
keyExtractor={(tab) => String(tab.key)}
|
|
141
|
+
showsHorizontalScrollIndicator={false}
|
|
142
|
+
onScrollToIndexFailed={({ index }) => {
|
|
143
|
+
setTimeout(
|
|
144
|
+
() =>
|
|
145
|
+
flatListRef.current?.scrollToIndex({
|
|
146
|
+
index,
|
|
147
|
+
viewPosition: 0.5,
|
|
148
|
+
}),
|
|
149
|
+
100
|
|
150
|
+
);
|
|
151
|
+
}}
|
|
152
|
+
contentContainerStyle={{
|
|
153
|
+
paddingHorizontal: theme.__hd__.tabs.space.flatListHorizontalPadding,
|
|
154
|
+
}}
|
|
155
|
+
renderItem={({ item: tab, index }) => {
|
|
156
|
+
const {
|
|
157
|
+
key,
|
|
158
|
+
testID: tabItemTestID,
|
|
159
|
+
activeItem,
|
|
160
|
+
inactiveItem: originalInactiveItem,
|
|
161
|
+
badge,
|
|
162
|
+
} = tab;
|
|
163
|
+
const active = selectedIndex === index;
|
|
164
|
+
const activeAnimated = tabsAnims[index];
|
|
165
|
+
const outlineScale = active
|
|
166
|
+
? activeAnimated.interpolate({
|
|
167
|
+
inputRange: [0, 1],
|
|
168
|
+
outputRange: [0.5, 1],
|
|
169
|
+
})
|
|
170
|
+
: 0;
|
|
171
|
+
|
|
172
|
+
const inactiveItem = originalInactiveItem ?? activeItem;
|
|
173
|
+
const tabItem = getTabItem({
|
|
174
|
+
item: active ? activeItem : inactiveItem,
|
|
175
|
+
color: active
|
|
176
|
+
? theme.__hd__.tabs.colors.active
|
|
177
|
+
: theme.__hd__.tabs.colors.inactive,
|
|
178
|
+
active,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<TouchableWithoutFeedback
|
|
183
|
+
key={key}
|
|
184
|
+
onPress={() => {
|
|
185
|
+
onTabPress(key);
|
|
186
|
+
}}
|
|
187
|
+
testID={tabItemTestID}
|
|
188
|
+
>
|
|
189
|
+
<HeaderTabItem isFirstItem={index === 0}>
|
|
190
|
+
<HeaderTabItemOutlineWrapper>
|
|
191
|
+
<HeaderTabItemOutline
|
|
192
|
+
themeActive={active}
|
|
193
|
+
style={{
|
|
194
|
+
flex: 1,
|
|
195
|
+
transform: [
|
|
196
|
+
{
|
|
197
|
+
scaleX: outlineScale,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
}}
|
|
201
|
+
/>
|
|
202
|
+
</HeaderTabItemOutlineWrapper>
|
|
203
|
+
<HeaderTabItemWrapper>
|
|
204
|
+
<TabWithBadge config={badge} tabItem={tabItem} />
|
|
205
|
+
</HeaderTabItemWrapper>
|
|
206
|
+
</HeaderTabItem>
|
|
207
|
+
</TouchableWithoutFeedback>
|
|
208
|
+
);
|
|
209
|
+
}}
|
|
210
|
+
/>
|
|
211
|
+
</HeaderTabWrapper>
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
export default ScrollableTabHeader;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { TabScreen } from '../StyledScrollableTabs';
|
|
4
|
+
|
|
5
|
+
export const SceneView = ({
|
|
6
|
+
lazy = false,
|
|
7
|
+
lazyPreloadDistance = 1,
|
|
8
|
+
children,
|
|
9
|
+
index,
|
|
10
|
+
selectedIndex,
|
|
11
|
+
testID,
|
|
12
|
+
}: {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
index: number;
|
|
15
|
+
selectedIndex: number;
|
|
16
|
+
lazy?: boolean;
|
|
17
|
+
lazyPreloadDistance?: number;
|
|
18
|
+
testID?: string;
|
|
19
|
+
}) => {
|
|
20
|
+
const [isLoading, setIsLoading] = React.useState(
|
|
21
|
+
Math.abs(selectedIndex - index) > lazyPreloadDistance
|
|
22
|
+
);
|
|
23
|
+
const focused = index === selectedIndex;
|
|
24
|
+
|
|
25
|
+
if (isLoading && Math.abs(selectedIndex - index) <= lazyPreloadDistance) {
|
|
26
|
+
// Always render the route when it becomes focused
|
|
27
|
+
setIsLoading(false);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
let unsubscribe: (() => void) | undefined;
|
|
32
|
+
let timer: number | undefined;
|
|
33
|
+
|
|
34
|
+
if (!lazy && isLoading) {
|
|
35
|
+
// If lazy mode is not enabled, render the scene with a delay if not loaded already
|
|
36
|
+
// This improves the initial startup time as the scene is no longer blocking
|
|
37
|
+
timer = setTimeout(() => setIsLoading(false), 0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return () => {
|
|
41
|
+
unsubscribe?.();
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
};
|
|
44
|
+
}, [index, isLoading, lazy, focused]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<TabScreen
|
|
48
|
+
accessibilityElementsHidden={!focused}
|
|
49
|
+
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
|
|
50
|
+
style={[
|
|
51
|
+
{ flex: 1, overflow: 'hidden' },
|
|
52
|
+
focused ? StyleSheet.absoluteFill : null,
|
|
53
|
+
]}
|
|
54
|
+
testID={testID}
|
|
55
|
+
>
|
|
56
|
+
{focused || !isLoading ? children : null}
|
|
57
|
+
</TabScreen>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default SceneView;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
3
|
+
import PagerView from 'react-native-pager-view';
|
|
4
|
+
import { TabContainer, ContentWrapper } from '../StyledScrollableTabs';
|
|
5
|
+
import type { TabsProps } from '..';
|
|
6
|
+
import { SceneView } from './SceneView';
|
|
7
|
+
import ScrollableTabHeader from '../ScrollableTabsHeader';
|
|
8
|
+
|
|
9
|
+
export const TabContext = React.createContext<{
|
|
10
|
+
selectedTabKey: string;
|
|
11
|
+
} | null>(null);
|
|
12
|
+
|
|
13
|
+
export const ScreenContext = React.createContext<string | null>(null);
|
|
14
|
+
|
|
15
|
+
export const useIsFocused = () => {
|
|
16
|
+
const context = React.useContext(TabContext);
|
|
17
|
+
const key = React.useContext(ScreenContext);
|
|
18
|
+
if (!context || !key) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isFocused = context.selectedTabKey === key;
|
|
23
|
+
|
|
24
|
+
return isFocused;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const ScrollableTab = ({
|
|
28
|
+
onTabPress,
|
|
29
|
+
selectedTabKey,
|
|
30
|
+
tabs,
|
|
31
|
+
containerStyle,
|
|
32
|
+
barStyle,
|
|
33
|
+
lazy = false,
|
|
34
|
+
lazyPreloadDistance = 1,
|
|
35
|
+
swipeEnabled = true,
|
|
36
|
+
testID: componentTestID,
|
|
37
|
+
}: TabsProps) => {
|
|
38
|
+
const pagerViewRef = React.useRef<PagerView>(null);
|
|
39
|
+
const insets = useSafeAreaInsets();
|
|
40
|
+
const selectedTabIndex = tabs.findIndex(
|
|
41
|
+
(item) => item.key === selectedTabKey
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
let timeoutHandle: number | null = null;
|
|
46
|
+
if (selectedTabIndex !== -1) {
|
|
47
|
+
// If the selected tab is changed too quickly, the setPage is crashed and not work anymore
|
|
48
|
+
// We apply throttle to prevent this issue https://github.com/Thinkei/hero-design/issues/1715
|
|
49
|
+
timeoutHandle = setTimeout(() => {
|
|
50
|
+
// use no animation to prevent unexpected behavior if users select tab too quickly
|
|
51
|
+
pagerViewRef.current?.setPageWithoutAnimation(selectedTabIndex);
|
|
52
|
+
}, 200);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return () => {
|
|
56
|
+
if (timeoutHandle) {
|
|
57
|
+
clearTimeout(timeoutHandle);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, [selectedTabIndex, pagerViewRef]);
|
|
61
|
+
|
|
62
|
+
const indexRef = React.useRef(selectedTabIndex);
|
|
63
|
+
const tabContextProviderValue = React.useMemo(
|
|
64
|
+
() => ({
|
|
65
|
+
selectedTabKey,
|
|
66
|
+
}),
|
|
67
|
+
[selectedTabKey]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<TabContext.Provider value={tabContextProviderValue}>
|
|
72
|
+
<TabContainer style={containerStyle} testID={componentTestID}>
|
|
73
|
+
<ScrollableTabHeader
|
|
74
|
+
tabs={tabs}
|
|
75
|
+
selectedIndex={selectedTabIndex}
|
|
76
|
+
onTabPress={onTabPress}
|
|
77
|
+
barStyle={barStyle}
|
|
78
|
+
insets={insets}
|
|
79
|
+
testID={componentTestID ? `${componentTestID}-tab-bar` : undefined}
|
|
80
|
+
/>
|
|
81
|
+
<ContentWrapper
|
|
82
|
+
initialPage={selectedTabIndex}
|
|
83
|
+
ref={pagerViewRef}
|
|
84
|
+
onPageSelected={(e) => {
|
|
85
|
+
const index = e.nativeEvent.position;
|
|
86
|
+
const selectedItem = tabs[index];
|
|
87
|
+
if (selectedItem) {
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
onTabPress(selectedItem.key);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
indexRef.current = index;
|
|
93
|
+
}}
|
|
94
|
+
scrollEnabled={swipeEnabled}
|
|
95
|
+
>
|
|
96
|
+
{tabs.map((tab, index) => {
|
|
97
|
+
const { key, component, testID } = tab;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<ScreenContext.Provider value={key}>
|
|
101
|
+
<SceneView
|
|
102
|
+
testID={testID}
|
|
103
|
+
key={key}
|
|
104
|
+
index={index}
|
|
105
|
+
selectedIndex={indexRef.current}
|
|
106
|
+
lazy={lazy}
|
|
107
|
+
lazyPreloadDistance={lazyPreloadDistance}
|
|
108
|
+
>
|
|
109
|
+
{component}
|
|
110
|
+
</SceneView>
|
|
111
|
+
</ScreenContext.Provider>
|
|
112
|
+
);
|
|
113
|
+
})}
|
|
114
|
+
</ContentWrapper>
|
|
115
|
+
</TabContainer>
|
|
116
|
+
</TabContext.Provider>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default ScrollableTab;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ThemeProvider } from '@emotion/react';
|
|
3
|
+
import renderWithTheme from '../../../../testHelpers/renderWithTheme';
|
|
4
|
+
import ScenceView from '../SceneView';
|
|
5
|
+
import Typography from '../../../Typography';
|
|
6
|
+
import { theme } from '../../../../index';
|
|
7
|
+
|
|
8
|
+
describe('ScenceView', () => {
|
|
9
|
+
describe('lazy', () => {
|
|
10
|
+
it('renders child correctly when the scence is focused and should not unmount if selected index changed to index which is out of lazyPreloadDistance', () => {
|
|
11
|
+
const { getByText, toJSON, queryByText, rerender } = renderWithTheme(
|
|
12
|
+
<ScenceView
|
|
13
|
+
testID="scene-view"
|
|
14
|
+
index={0}
|
|
15
|
+
selectedIndex={0}
|
|
16
|
+
lazy
|
|
17
|
+
lazyPreloadDistance={1}
|
|
18
|
+
>
|
|
19
|
+
<Typography.Text>Scene 1</Typography.Text>
|
|
20
|
+
</ScenceView>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(toJSON()).toMatchSnapshot();
|
|
24
|
+
expect(getByText('Scene 1')).toBeDefined();
|
|
25
|
+
|
|
26
|
+
rerender(
|
|
27
|
+
<ThemeProvider theme={theme}>
|
|
28
|
+
<ScenceView
|
|
29
|
+
testID="scene-view"
|
|
30
|
+
index={0}
|
|
31
|
+
selectedIndex={2}
|
|
32
|
+
lazy
|
|
33
|
+
lazyPreloadDistance={1}
|
|
34
|
+
>
|
|
35
|
+
<Typography.Text>Scene 1</Typography.Text>
|
|
36
|
+
</ScenceView>
|
|
37
|
+
</ThemeProvider>
|
|
38
|
+
);
|
|
39
|
+
expect(toJSON()).toMatchSnapshot();
|
|
40
|
+
expect(queryByText('Scene 1')).toBeDefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('not renders child correctly when the scence is lazy and renders when selectedIndex change to 1', () => {
|
|
44
|
+
const { rerender, queryByText, toJSON } = renderWithTheme(
|
|
45
|
+
<ScenceView
|
|
46
|
+
testID="scene-view"
|
|
47
|
+
index={2}
|
|
48
|
+
selectedIndex={0}
|
|
49
|
+
lazy
|
|
50
|
+
lazyPreloadDistance={1}
|
|
51
|
+
>
|
|
52
|
+
<Typography.Text>Scene 1</Typography.Text>
|
|
53
|
+
</ScenceView>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(toJSON()).toMatchSnapshot();
|
|
57
|
+
expect(queryByText('Scene 1')).toBeNull();
|
|
58
|
+
|
|
59
|
+
rerender(
|
|
60
|
+
<ThemeProvider theme={theme}>
|
|
61
|
+
<ScenceView
|
|
62
|
+
testID="scene-view"
|
|
63
|
+
index={2}
|
|
64
|
+
selectedIndex={1}
|
|
65
|
+
lazy
|
|
66
|
+
lazyPreloadDistance={1}
|
|
67
|
+
>
|
|
68
|
+
<Typography.Text>Scene 1</Typography.Text>
|
|
69
|
+
</ScenceView>
|
|
70
|
+
</ThemeProvider>
|
|
71
|
+
);
|
|
72
|
+
expect(toJSON()).toMatchSnapshot();
|
|
73
|
+
expect(queryByText('Scene 1')).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|