@hero-design/rn 8.24.0-alpha.1 → 8.24.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 +3 -3
- package/.turbo/turbo-publish:npm.log +0 -9
- package/es/index.js +78 -142
- package/lib/index.js +78 -142
- package/package.json +5 -5
- package/src/components/RichTextEditor/RichTextEditor.tsx +3 -4
- package/src/components/Success/__tests__/index.spec.tsx +6 -0
- package/src/components/Success/index.tsx +19 -0
- package/src/components/Tabs/{ScrollableTabsV2/SceneView.tsx → SceneView.tsx} +2 -2
- package/src/components/Tabs/ScrollableTabs.tsx +54 -48
- package/src/components/Tabs/{ScrollableTabsV2/__tests__ → __tests__}/SceneView.spec.tsx +3 -3
- package/src/components/Tabs/__tests__/ScrollableTabs.spec.tsx +86 -28
- package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabs.spec.tsx.snap +1687 -49
- package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +1213 -29
- package/src/components/Tabs/__tests__/index.spec.tsx +58 -14
- package/src/components/Tabs/index.tsx +108 -102
- package/src/components/Tabs/useIsFocused.tsx +19 -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 +0 -0
- package/types/components/Success/index.d.ts +8 -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 +4 -3
- package/types/components/Tabs/ScrollableTabs.d.ts +0 -0
- package/types/components/Tabs/ScrollableTabsHeader.d.ts +0 -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 +1 -3
- package/types/components/Tabs/useIsFocused.d.ts +6 -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 +0 -0
- package/types/components/TextInput/index.d.ts +0 -0
- 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 +0 -0
- 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 +0 -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 +0 -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 +0 -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
- package/.turbo/turbo-build:types.log +0 -2
- package/.turbo/turbo-lint.log +0 -146
- package/.turbo/turbo-test.log +0 -451
- package/.turbo/turbo-type-check.log +0 -1
- package/src/components/Tabs/ScrollableTabsV2/ScrollableTabsV2.tsx +0 -120
- package/src/components/Tabs/ScrollableTabsV2/__tests__/ScrollableTabsV2.spec.tsx +0 -166
- package/src/components/Tabs/ScrollableTabsV2/__tests__/__snapshots__/ScrollableTabsV2.spec.tsx.snap +0 -2497
- package/src/components/Tabs/ScrollableTabsV2/index.tsx +0 -5
- package/types/components/Tabs/ScrollableTabsV2/SceneView.d.ts +0 -10
- package/types/components/Tabs/ScrollableTabsV2/ScrollableTabsV2.d.ts +0 -9
- package/types/components/Tabs/ScrollableTabsV2/index.d.ts +0 -4
- /package/src/components/Tabs/{ScrollableTabsV2/__tests__ → __tests__}/__snapshots__/SceneView.spec.tsx.snap +0 -0
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Text } from 'react-native';
|
|
3
|
-
import { fireEvent } from '@testing-library/react-native';
|
|
3
|
+
import { fireEvent, waitFor } from '@testing-library/react-native';
|
|
4
4
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
5
5
|
import type { ComponentProps } from 'react';
|
|
6
6
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
7
7
|
import Tabs from '..';
|
|
8
8
|
import Button from '../../Button';
|
|
9
9
|
import type { TabType } from '..';
|
|
10
|
+
import { useIsFocused } from '../useIsFocused';
|
|
11
|
+
|
|
12
|
+
const CustomScreen = ({ title }: { title: string }) => {
|
|
13
|
+
const isFocused = useIsFocused();
|
|
14
|
+
return (
|
|
15
|
+
<Text>
|
|
16
|
+
{title} {isFocused ? 'focused' : 'unfocused'}
|
|
17
|
+
</Text>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
10
20
|
|
|
11
21
|
const TestTabsComponent = (
|
|
12
22
|
props: Omit<
|
|
@@ -19,17 +29,17 @@ const TestTabsComponent = (
|
|
|
19
29
|
{
|
|
20
30
|
key: 'work',
|
|
21
31
|
activeItem: 'Work',
|
|
22
|
-
component: <
|
|
32
|
+
component: <CustomScreen title="Work Screen" />,
|
|
23
33
|
},
|
|
24
34
|
{
|
|
25
35
|
key: 'personal',
|
|
26
36
|
activeItem: 'Personal',
|
|
27
|
-
component: <
|
|
37
|
+
component: <CustomScreen title="Personal Screen" />,
|
|
28
38
|
},
|
|
29
39
|
{
|
|
30
40
|
key: 'home',
|
|
31
41
|
activeItem: 'Home',
|
|
32
|
-
component: <
|
|
42
|
+
component: <CustomScreen title="Home Screen" />,
|
|
33
43
|
badge: {
|
|
34
44
|
type: 'status',
|
|
35
45
|
},
|
|
@@ -37,7 +47,7 @@ const TestTabsComponent = (
|
|
|
37
47
|
{
|
|
38
48
|
key: 'money',
|
|
39
49
|
activeItem: 'Money',
|
|
40
|
-
component: <
|
|
50
|
+
component: <CustomScreen title="Money Screen" />,
|
|
41
51
|
badge: {
|
|
42
52
|
type: 'counter',
|
|
43
53
|
value: 50,
|
|
@@ -75,15 +85,15 @@ describe('Tabs', () => {
|
|
|
75
85
|
expect(getByText('Work')).toBeDefined();
|
|
76
86
|
expect(getByText('Personal')).toBeDefined();
|
|
77
87
|
expect(getByText('Home')).toBeDefined();
|
|
78
|
-
expect(getByText('Work Screen')).toBeDefined();
|
|
88
|
+
expect(getByText('Work Screen focused')).toBeDefined();
|
|
79
89
|
fireEvent.press(getByText('Personal'));
|
|
80
|
-
expect(getByText('Personal Screen')).toBeDefined();
|
|
90
|
+
expect(getByText('Personal Screen focused')).toBeDefined();
|
|
81
91
|
fireEvent.press(getByText('Home'));
|
|
82
|
-
expect(getByText('Home Screen')).toBeDefined();
|
|
92
|
+
expect(getByText('Home Screen focused')).toBeDefined();
|
|
83
93
|
fireEvent.press(getByText('Move to Work'));
|
|
84
|
-
expect(getByText('Work Screen')).toBeDefined();
|
|
94
|
+
expect(getByText('Work Screen focused')).toBeDefined();
|
|
85
95
|
fireEvent.press(getByText('Money'));
|
|
86
|
-
expect(getByText('Money Screen')).toBeDefined();
|
|
96
|
+
expect(getByText('Money Screen focused')).toBeDefined();
|
|
87
97
|
expect(getByText('50')).toBeDefined();
|
|
88
98
|
});
|
|
89
99
|
|
|
@@ -92,13 +102,47 @@ describe('Tabs', () => {
|
|
|
92
102
|
<TestTabsComponent lazy lazyPreloadDistance={1} swipeEnabled={false} />
|
|
93
103
|
);
|
|
94
104
|
|
|
95
|
-
expect(getByText('Work Screen')).toBeDefined();
|
|
96
|
-
expect(getByText('Personal Screen')).toBeDefined();
|
|
105
|
+
expect(getByText('Work Screen focused')).toBeDefined();
|
|
106
|
+
expect(getByText('Personal Screen unfocused')).toBeDefined();
|
|
97
107
|
// Preload distance is 1, so Home Screen is not rendered.
|
|
98
108
|
expect(queryByText('Home Screen')).toBeNull();
|
|
99
109
|
|
|
100
110
|
fireEvent.press(getByText('Home'));
|
|
101
|
-
expect(getByText('Home Screen')).toBeDefined();
|
|
102
|
-
|
|
111
|
+
expect(getByText('Home Screen focused')).toBeDefined();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('useIsFocused', () => {
|
|
116
|
+
it('renders correctly', async () => {
|
|
117
|
+
const { getByText, toJSON } = renderWithTheme(<TestTabsComponent />);
|
|
118
|
+
|
|
119
|
+
expect(toJSON()).toMatchSnapshot();
|
|
120
|
+
expect(getByText('Work Screen focused')).toBeDefined();
|
|
121
|
+
expect(getByText('Personal Screen unfocused')).toBeDefined();
|
|
122
|
+
await waitFor(() =>
|
|
123
|
+
expect(getByText('Home Screen unfocused')).toBeDefined()
|
|
124
|
+
);
|
|
125
|
+
expect(getByText('Home Screen unfocused')).toBeDefined();
|
|
126
|
+
expect(getByText('Money Screen unfocused')).toBeDefined();
|
|
127
|
+
|
|
128
|
+
fireEvent.press(getByText('Personal'));
|
|
129
|
+
expect(toJSON()).toMatchSnapshot('xxxxxx');
|
|
130
|
+
expect(getByText('Personal Screen focused')).toBeDefined();
|
|
131
|
+
expect(getByText('Work Screen unfocused')).toBeDefined();
|
|
132
|
+
expect(getByText('Home Screen unfocused')).toBeDefined();
|
|
133
|
+
expect(getByText('Money Screen unfocused')).toBeDefined();
|
|
134
|
+
|
|
135
|
+
fireEvent.press(getByText('Home'));
|
|
136
|
+
expect(getByText('Personal Screen unfocused')).toBeDefined();
|
|
137
|
+
expect(getByText('Work Screen unfocused')).toBeDefined();
|
|
138
|
+
expect(getByText('Home Screen focused')).toBeDefined();
|
|
139
|
+
expect(getByText('Money Screen unfocused')).toBeDefined();
|
|
140
|
+
|
|
141
|
+
fireEvent.press(getByText('Money'));
|
|
142
|
+
expect(getByText('Personal Screen unfocused')).toBeDefined();
|
|
143
|
+
expect(getByText('Work Screen unfocused')).toBeDefined();
|
|
144
|
+
expect(getByText('Home Screen unfocused')).toBeDefined();
|
|
145
|
+
expect(getByText('Money Screen focused')).toBeDefined();
|
|
146
|
+
expect(getByText('50')).toBeDefined();
|
|
103
147
|
});
|
|
104
148
|
});
|
|
@@ -9,18 +9,18 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
9
9
|
import { IconName } from '../Icon';
|
|
10
10
|
import Typography from '../Typography';
|
|
11
11
|
import ActiveTabIndicator from './ActiveTabIndicator';
|
|
12
|
+
import SceneView from './SceneView';
|
|
12
13
|
import ScrollableTabs from './ScrollableTabs';
|
|
13
|
-
import ScrollableTabsV2 from './ScrollableTabsV2';
|
|
14
14
|
import {
|
|
15
15
|
ContentWrapper,
|
|
16
16
|
HeaderTab,
|
|
17
17
|
HeaderTabItem,
|
|
18
18
|
HeaderTabWrapper,
|
|
19
19
|
TabContainer,
|
|
20
|
-
TabScreen,
|
|
21
20
|
} from './StyledTabs';
|
|
22
21
|
import type { BadgeConfigType } from './TabWithBadge';
|
|
23
22
|
import TabWithBadge from './TabWithBadge';
|
|
23
|
+
import { ScreenContext, TabContext, useIsFocused } from './useIsFocused';
|
|
24
24
|
|
|
25
25
|
export type ItemType =
|
|
26
26
|
| string
|
|
@@ -129,114 +129,120 @@ const Tabs = ({
|
|
|
129
129
|
}
|
|
130
130
|
}, [selectedTabIndex]);
|
|
131
131
|
|
|
132
|
+
const tabContextProviderValue = React.useMemo(
|
|
133
|
+
() => ({
|
|
134
|
+
selectedTabKey,
|
|
135
|
+
}),
|
|
136
|
+
[selectedTabKey]
|
|
137
|
+
);
|
|
138
|
+
|
|
132
139
|
return (
|
|
133
|
-
<
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
<TabContext.Provider value={tabContextProviderValue}>
|
|
141
|
+
<TabContainer style={containerStyle} testID={componentTestID}>
|
|
142
|
+
<HeaderTabWrapper
|
|
143
|
+
themeInsets={insets}
|
|
144
|
+
style={barStyle}
|
|
145
|
+
testID={componentTestID ? `${componentTestID}-tab-bar` : undefined}
|
|
146
|
+
>
|
|
147
|
+
<View>
|
|
148
|
+
<HeaderTab
|
|
149
|
+
onLayout={(e) => {
|
|
150
|
+
const { width } = e.nativeEvent.layout;
|
|
151
|
+
if (tabsWidth !== width) {
|
|
152
|
+
setTabsWidth(width);
|
|
153
|
+
}
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{tabs.map((tab) => {
|
|
157
|
+
const {
|
|
158
|
+
key,
|
|
159
|
+
testID,
|
|
160
|
+
activeItem,
|
|
161
|
+
inactiveItem: originalInactiveItem,
|
|
162
|
+
badge,
|
|
163
|
+
} = tab;
|
|
156
164
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
const active = selectedTabKey === key;
|
|
166
|
+
const inactiveItem = originalInactiveItem ?? activeItem;
|
|
167
|
+
const tabItem = getTabItem({
|
|
168
|
+
item: active ? activeItem : inactiveItem,
|
|
169
|
+
color: theme.__hd__.tabs.colors.text,
|
|
170
|
+
active,
|
|
171
|
+
});
|
|
164
172
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
173
|
+
return (
|
|
174
|
+
<TouchableWithoutFeedback
|
|
175
|
+
key={key}
|
|
176
|
+
onPress={() => {
|
|
177
|
+
onTabPress(key);
|
|
178
|
+
}}
|
|
179
|
+
testID={testID}
|
|
180
|
+
>
|
|
181
|
+
<HeaderTabItem>
|
|
182
|
+
<TabWithBadge config={badge} tabItem={tabItem} />
|
|
183
|
+
</HeaderTabItem>
|
|
184
|
+
</TouchableWithoutFeedback>
|
|
185
|
+
);
|
|
186
|
+
})}
|
|
187
|
+
</HeaderTab>
|
|
188
|
+
<ActiveTabIndicator
|
|
189
|
+
positionAnimatedValue={positionAnimatedValue}
|
|
190
|
+
scrollOffsetAnimatedValue={scrollOffsetAnimatedValue}
|
|
191
|
+
tabsLength={tabs.length}
|
|
192
|
+
tabsWidth={tabsWidth}
|
|
193
|
+
/>
|
|
194
|
+
</View>
|
|
195
|
+
</HeaderTabWrapper>
|
|
196
|
+
<ContentWrapper
|
|
197
|
+
initialPage={selectedTabIndex}
|
|
198
|
+
ref={pagerViewRef}
|
|
199
|
+
onPageSelected={(e) => {
|
|
200
|
+
const index = e.nativeEvent.position;
|
|
201
|
+
const selectedItem = tabs[index];
|
|
202
|
+
if (selectedItem) {
|
|
203
|
+
onTabPress(selectedItem.key);
|
|
204
|
+
}
|
|
205
|
+
}}
|
|
206
|
+
onPageScroll={Animated.event<PagerViewOnPageScrollEventData>(
|
|
207
|
+
[
|
|
208
|
+
{
|
|
209
|
+
nativeEvent: {
|
|
210
|
+
offset: scrollOffsetAnimatedValue,
|
|
211
|
+
position: positionAnimatedValue,
|
|
212
|
+
},
|
|
204
213
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const { key, component, testID } = tab;
|
|
215
|
-
const active = selectedTabKey === key;
|
|
216
|
-
const isLazyScreen =
|
|
217
|
-
lazy && Math.abs(selectedTabIndex - index) > lazyPreloadDistance;
|
|
214
|
+
],
|
|
215
|
+
{
|
|
216
|
+
useNativeDriver: true,
|
|
217
|
+
}
|
|
218
|
+
)}
|
|
219
|
+
scrollEnabled={swipeEnabled}
|
|
220
|
+
>
|
|
221
|
+
{tabs.map((tab, index) => {
|
|
222
|
+
const { key, component, testID } = tab;
|
|
218
223
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
return (
|
|
225
|
+
<ScreenContext.Provider value={key} key={key}>
|
|
226
|
+
<SceneView
|
|
227
|
+
testID={testID}
|
|
228
|
+
key={key}
|
|
229
|
+
index={index}
|
|
230
|
+
selectedIndex={selectedTabIndex}
|
|
231
|
+
lazy={lazy}
|
|
232
|
+
lazyPreloadDistance={lazyPreloadDistance}
|
|
233
|
+
>
|
|
234
|
+
{component}
|
|
235
|
+
</SceneView>
|
|
236
|
+
</ScreenContext.Provider>
|
|
237
|
+
);
|
|
238
|
+
})}
|
|
239
|
+
</ContentWrapper>
|
|
240
|
+
</TabContainer>
|
|
241
|
+
</TabContext.Provider>
|
|
236
242
|
);
|
|
237
243
|
};
|
|
238
244
|
|
|
239
245
|
export default Object.assign(Tabs, {
|
|
240
246
|
Scroll: ScrollableTabs,
|
|
241
|
-
|
|
247
|
+
useIsFocused,
|
|
242
248
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export const TabContext = React.createContext<{
|
|
4
|
+
selectedTabKey: string;
|
|
5
|
+
} | null>(null);
|
|
6
|
+
|
|
7
|
+
export const ScreenContext = React.createContext<string | null>(null);
|
|
8
|
+
|
|
9
|
+
export const useIsFocused = () => {
|
|
10
|
+
const context = React.useContext(TabContext);
|
|
11
|
+
const key = React.useContext(ScreenContext);
|
|
12
|
+
if (!context || !key) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const isFocused = context.selectedTabKey === key;
|
|
17
|
+
|
|
18
|
+
return isFocused;
|
|
19
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|