react-native-molecules 0.5.0-beta.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/components/Accordion/Accordion.tsx +89 -0
- package/components/Accordion/AccordionItem.tsx +94 -0
- package/components/Accordion/AccordionItemContent.tsx +17 -0
- package/components/Accordion/AccordionItemHeader.tsx +122 -0
- package/components/Accordion/index.tsx +36 -0
- package/components/Accordion/utils.ts +62 -0
- package/components/ActivityIndicator/ActivityIndicator.ios.tsx +1 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +200 -0
- package/components/ActivityIndicator/AnimatedSpinner.tsx +121 -0
- package/components/ActivityIndicator/index.tsx +17 -0
- package/components/Appbar/AppbarActions.tsx +13 -0
- package/components/Appbar/AppbarBase.tsx +60 -0
- package/components/Appbar/AppbarCenterAligned.tsx +13 -0
- package/components/Appbar/AppbarLarge.tsx +13 -0
- package/components/Appbar/AppbarLeft.tsx +26 -0
- package/components/Appbar/AppbarMedium.tsx +13 -0
- package/components/Appbar/AppbarRight.tsx +40 -0
- package/components/Appbar/AppbarSmall.tsx +13 -0
- package/components/Appbar/AppbarTitle.tsx +49 -0
- package/components/Appbar/index.tsx +46 -0
- package/components/Appbar/types.ts +19 -0
- package/components/Appbar/utils.ts +127 -0
- package/components/Avatar/Avatar.tsx +189 -0
- package/components/Avatar/index.tsx +11 -0
- package/components/Avatar/utils.ts +35 -0
- package/components/Backdrop/Backdrop.tsx +18 -0
- package/components/Backdrop/index.tsx +11 -0
- package/components/Backdrop/types.ts +3 -0
- package/components/Backdrop/utils.ts +21 -0
- package/components/Badge/Badge.tsx +29 -0
- package/components/Badge/index.tsx +11 -0
- package/components/Badge/utils.ts +38 -0
- package/components/Button/Button.tsx +349 -0
- package/components/Button/index.tsx +11 -0
- package/components/Button/types.ts +5 -0
- package/components/Button/utils.ts +416 -0
- package/components/Card/Card.tsx +160 -0
- package/components/Card/CardActions.tsx +18 -0
- package/components/Card/CardContent.tsx +29 -0
- package/components/Card/CardHeader.tsx +31 -0
- package/components/Card/CardHeadline.tsx +15 -0
- package/components/Card/CardMedia.tsx +36 -0
- package/components/Card/CardSubhead.tsx +15 -0
- package/components/Card/CardText.tsx +13 -0
- package/components/Card/CardTypography.tsx +113 -0
- package/components/Card/index.tsx +38 -0
- package/components/Card/types.ts +1 -0
- package/components/Card/utils.ts +23 -0
- package/components/Checkbox/Checkbox.tsx +123 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +86 -0
- package/components/Checkbox/CheckboxBase.tsx +216 -0
- package/components/Checkbox/index.tsx +11 -0
- package/components/Checkbox/types.ts +72 -0
- package/components/Checkbox/utils.ts +210 -0
- package/components/Chip/Chip.tsx +416 -0
- package/components/Chip/index.tsx +51 -0
- package/components/Chip/utils.ts +100 -0
- package/components/DatePickerDocked/DatePickerDocked.tsx +30 -0
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +129 -0
- package/components/DatePickerDocked/index.tsx +21 -0
- package/components/DatePickerDocked/types.ts +11 -0
- package/components/DatePickerDocked/utils.ts +155 -0
- package/components/DatePickerInline/AutoSizer.tsx +46 -0
- package/components/DatePickerInline/DatePickerContext.tsx +21 -0
- package/components/DatePickerInline/DatePickerInline.tsx +82 -0
- package/components/DatePickerInline/DatePickerInlineBase.tsx +181 -0
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +108 -0
- package/components/DatePickerInline/Day.tsx +88 -0
- package/components/DatePickerInline/DayName.tsx +17 -0
- package/components/DatePickerInline/DayNames.tsx +32 -0
- package/components/DatePickerInline/DayRange.tsx +48 -0
- package/components/DatePickerInline/HeaderItem.tsx +111 -0
- package/components/DatePickerInline/Month.tsx +233 -0
- package/components/DatePickerInline/MonthPicker.tsx +174 -0
- package/components/DatePickerInline/Swiper.native.tsx +172 -0
- package/components/DatePickerInline/Swiper.tsx +172 -0
- package/components/DatePickerInline/SwiperUtils.ts +40 -0
- package/components/DatePickerInline/Week.tsx +67 -0
- package/components/DatePickerInline/YearPicker.tsx +139 -0
- package/components/DatePickerInline/dateUtils.tsx +334 -0
- package/components/DatePickerInline/index.tsx +41 -0
- package/components/DatePickerInline/types.ts +104 -0
- package/components/DatePickerInline/utils.ts +367 -0
- package/components/DatePickerInput/DatePickerInput.tsx +139 -0
- package/components/DatePickerInput/DatePickerInputModal.tsx +48 -0
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +77 -0
- package/components/DatePickerInput/DateRangeInput.tsx +88 -0
- package/components/DatePickerInput/index.tsx +14 -0
- package/components/DatePickerInput/inputUtils.ts +138 -0
- package/components/DatePickerInput/types.ts +28 -0
- package/components/DatePickerInput/utils.ts +16 -0
- package/components/DatePickerModal/AnimatedCrossView.tsx +94 -0
- package/components/DatePickerModal/CalendarEdit.tsx +139 -0
- package/components/DatePickerModal/DatePickerModal.tsx +85 -0
- package/components/DatePickerModal/DatePickerModalContent.tsx +155 -0
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +213 -0
- package/components/DatePickerModal/DatePickerModalHeader.tsx +74 -0
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +13 -0
- package/components/DatePickerModal/index.tsx +20 -0
- package/components/DatePickerModal/types.ts +92 -0
- package/components/DatePickerModal/utils.ts +121 -0
- package/components/DateTimePicker/DateTimePicker.tsx +172 -0
- package/components/DateTimePicker/index.tsx +14 -0
- package/components/DateTimePicker/utils.ts +13 -0
- package/components/Dialog/Dialog.tsx +66 -0
- package/components/Dialog/DialogActions.tsx +89 -0
- package/components/Dialog/DialogContent.tsx +37 -0
- package/components/Dialog/DialogIcon.tsx +69 -0
- package/components/Dialog/DialogTitle.tsx +68 -0
- package/components/Dialog/index.tsx +37 -0
- package/components/Dialog/utils.ts +80 -0
- package/components/Drawer/Collapsible/DrawerCollapsible.tsx +22 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItem.tsx +38 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemContent.tsx +16 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemHeader.tsx +48 -0
- package/components/Drawer/Collapsible/index.tsx +23 -0
- package/components/Drawer/Collapsible/utils.ts +49 -0
- package/components/Drawer/Drawer.tsx +43 -0
- package/components/Drawer/DrawerContent.tsx +35 -0
- package/components/Drawer/DrawerFooter.tsx +27 -0
- package/components/Drawer/DrawerHeader.tsx +27 -0
- package/components/Drawer/DrawerItem.tsx +206 -0
- package/components/Drawer/DrawerItemGroup.tsx +82 -0
- package/components/Drawer/index.tsx +47 -0
- package/components/Drawer/types.ts +3 -0
- package/components/Drawer/utils.ts +8 -0
- package/components/ElementGroup/ElementGroup.tsx +139 -0
- package/components/ElementGroup/index.tsx +11 -0
- package/components/ElementGroup/utils.ts +25 -0
- package/components/FAB/FAB.tsx +176 -0
- package/components/FAB/index.tsx +12 -0
- package/components/FAB/types.ts +1 -0
- package/components/FAB/utils.ts +221 -0
- package/components/FilePicker/FilePicker.tsx +133 -0
- package/components/FilePicker/index.tsx +11 -0
- package/components/FilePicker/utils.ts +13 -0
- package/components/HelperText/HelperText.tsx +139 -0
- package/components/HelperText/index.tsx +11 -0
- package/components/HelperText/utils.ts +29 -0
- package/components/HorizontalDivider/HorizontalDivider.tsx +101 -0
- package/components/HorizontalDivider/index.tsx +13 -0
- package/components/Icon/CrossFadeIcon.tsx +116 -0
- package/components/Icon/Icon.tsx +41 -0
- package/components/Icon/iconFactory.tsx +23 -0
- package/components/Icon/index.tsx +11 -0
- package/components/Icon/types.ts +35 -0
- package/components/IconButton/IconButton.tsx +218 -0
- package/components/IconButton/index.tsx +11 -0
- package/components/IconButton/types.ts +1 -0
- package/components/IconButton/utils.ts +325 -0
- package/components/If/index.tsx +13 -0
- package/components/InputAddon/InputAddon.tsx +27 -0
- package/components/InputAddon/index.tsx +11 -0
- package/components/InputAddon/utils.ts +33 -0
- package/components/Link/Link.tsx +48 -0
- package/components/Link/index.tsx +11 -0
- package/components/Link/utils.ts +37 -0
- package/components/ListItem/ListItem.tsx +136 -0
- package/components/ListItem/ListItemDescription.tsx +25 -0
- package/components/ListItem/ListItemTitle.tsx +25 -0
- package/components/ListItem/index.tsx +18 -0
- package/components/ListItem/utils.ts +113 -0
- package/components/Menu/Menu.tsx +69 -0
- package/components/Menu/MenuDivider.tsx +13 -0
- package/components/Menu/MenuItem.tsx +128 -0
- package/components/Menu/index.tsx +19 -0
- package/components/Menu/utils.ts +92 -0
- package/components/Modal/Modal.tsx +261 -0
- package/components/Modal/index.tsx +11 -0
- package/components/Modal/utils.ts +45 -0
- package/components/NavigationRail/NavigationRail.tsx +32 -0
- package/components/NavigationRail/NavigationRailContent.tsx +25 -0
- package/components/NavigationRail/NavigationRailFooter.tsx +18 -0
- package/components/NavigationRail/NavigationRailHeader.tsx +18 -0
- package/components/NavigationRail/NavigationRailItem.tsx +226 -0
- package/components/NavigationRail/index.tsx +35 -0
- package/components/NavigationRail/utils.ts +170 -0
- package/components/NavigationStack/NavigationStack.tsx +85 -0
- package/components/NavigationStack/NavigationStackItem.tsx +60 -0
- package/components/NavigationStack/index.tsx +20 -0
- package/components/NavigationStack/utils.tsx +16 -0
- package/components/Popover/Popover.native.tsx +185 -0
- package/components/Popover/Popover.tsx +198 -0
- package/components/Popover/common.ts +459 -0
- package/components/Popover/index.ts +2 -0
- package/components/Portal/Portal.tsx +13 -0
- package/components/Portal/index.tsx +12 -0
- package/components/RadioButton/RadioButton.tsx +138 -0
- package/components/RadioButton/RadioButtonAndroid.tsx +188 -0
- package/components/RadioButton/RadioButtonGroup.tsx +98 -0
- package/components/RadioButton/RadioButtonIOS.tsx +106 -0
- package/components/RadioButton/RadioButtonItem.tsx +232 -0
- package/components/RadioButton/index.ts +27 -0
- package/components/RadioButton/utils.ts +164 -0
- package/components/Rating/Rating.tsx +149 -0
- package/components/Rating/RatingItem.tsx +125 -0
- package/components/Rating/index.tsx +13 -0
- package/components/Rating/utils.ts +38 -0
- package/components/Select/Select.tsx +1038 -0
- package/components/Select/index.ts +14 -0
- package/components/Select/types.ts +115 -0
- package/components/StateLayer/StateLayer.tsx +12 -0
- package/components/StateLayer/index.tsx +11 -0
- package/components/StateLayer/utils.ts +17 -0
- package/components/Surface/BackgroundContextWrapper.tsx +27 -0
- package/components/Surface/Surface.android.tsx +62 -0
- package/components/Surface/Surface.ios.tsx +123 -0
- package/components/Surface/Surface.tsx +48 -0
- package/components/Surface/index.tsx +12 -0
- package/components/Surface/utils.ts +106 -0
- package/components/Switch/Switch.ios.tsx +67 -0
- package/components/Switch/Switch.tsx +278 -0
- package/components/Switch/index.tsx +11 -0
- package/components/Switch/utils.ts +283 -0
- package/components/Tabs/TabItem.tsx +150 -0
- package/components/Tabs/TabLabel.tsx +84 -0
- package/components/Tabs/Tabs.tsx +398 -0
- package/components/Tabs/index.tsx +21 -0
- package/components/Tabs/utils.ts +126 -0
- package/components/Text/Text.tsx +23 -0
- package/components/Text/index.tsx +2 -0
- package/components/Text/textFactory.tsx +33 -0
- package/components/TextInput/InputLabel.tsx +181 -0
- package/components/TextInput/TextInput.tsx +693 -0
- package/components/TextInput/index.tsx +16 -0
- package/components/TextInput/types.ts +96 -0
- package/components/TextInput/utils.ts +544 -0
- package/components/TextInputWithMask/TextInputMask.tsx +57 -0
- package/components/TextInputWithMask/index.tsx +11 -0
- package/components/TextInputWithMask/utils.ts +56 -0
- package/components/TimePicker/AmPmSwitcher.tsx +99 -0
- package/components/TimePicker/AnalogClock.tsx +165 -0
- package/components/TimePicker/AnalogClockHours.tsx +163 -0
- package/components/TimePicker/AnalogClockMinutes.tsx +68 -0
- package/components/TimePicker/AnimatedClockSwitcher.tsx +72 -0
- package/components/TimePicker/DisplayModeContext.tsx +6 -0
- package/components/TimePicker/TimeInput.tsx +112 -0
- package/components/TimePicker/TimeInputs.tsx +148 -0
- package/components/TimePicker/TimePicker.tsx +130 -0
- package/components/TimePicker/index.tsx +19 -0
- package/components/TimePicker/timeUtils.ts +159 -0
- package/components/TimePicker/utils.ts +285 -0
- package/components/TimePickerField/TimePickerField.tsx +152 -0
- package/components/TimePickerField/index.tsx +14 -0
- package/components/TimePickerField/sanitizeTime.ts +85 -0
- package/components/TimePickerField/utils.ts +95 -0
- package/components/TimePickerModal/TimePickerModal.tsx +115 -0
- package/components/TimePickerModal/index.tsx +14 -0
- package/components/TimePickerModal/utils.ts +48 -0
- package/components/Tooltip/Tooltip.tsx +137 -0
- package/components/Tooltip/TooltipContent.tsx +12 -0
- package/components/Tooltip/TooltipTrigger.tsx +94 -0
- package/components/Tooltip/index.tsx +20 -0
- package/components/Tooltip/utils.ts +21 -0
- package/components/TouchableRipple/TouchableRipple.native.tsx +105 -0
- package/components/TouchableRipple/TouchableRipple.tsx +286 -0
- package/components/TouchableRipple/index.tsx +14 -0
- package/components/TouchableRipple/utils.ts +15 -0
- package/components/VerticalDivider/VerticalDivider.tsx +99 -0
- package/components/VerticalDivider/index.tsx +13 -0
- package/context-bridge/index.tsx +87 -0
- package/core/componentsRegistry.ts +164 -0
- package/core/index.tsx +2 -0
- package/fast-context/index.tsx +190 -0
- package/hocs/index.tsx +5 -0
- package/hocs/typedMemo.tsx +5 -0
- package/hocs/withKeyboardAccessibility.tsx +231 -0
- package/hocs/withPortal.tsx +16 -0
- package/hooks/createPsuedoHook.tsx +50 -0
- package/hooks/index.tsx +29 -0
- package/hooks/useActionState.native.tsx +22 -0
- package/hooks/useActionState.tsx +34 -0
- package/hooks/useActive.tsx +5 -0
- package/hooks/useBreakpoints.tsx +7 -0
- package/hooks/useColorMode.tsx +17 -0
- package/hooks/useContrastColor.ts +15 -0
- package/hooks/useControlledValue.tsx +68 -0
- package/hooks/useFilePicker.tsx +48 -0
- package/hooks/useFocus.tsx +5 -0
- package/hooks/useHandleNumberFormat.tsx +106 -0
- package/hooks/useHover.tsx +5 -0
- package/hooks/useKeyboardDismissable.ts +66 -0
- package/hooks/useLatest.tsx +9 -0
- package/hooks/useMediaQuery.tsx +64 -0
- package/hooks/useMergedRefs.ts +14 -0
- package/hooks/usePrevious.ts +13 -0
- package/hooks/useQueryFilter.tsx +35 -0
- package/hooks/useSearchable.tsx +74 -0
- package/hooks/useSubcomponents.tsx +59 -0
- package/hooks/useTheme.ts +3 -0
- package/hooks/useToggle.tsx +24 -0
- package/package.json +114 -0
- package/shortcuts-manager/EventsManager.tsx +121 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.native.tsx +9 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +58 -0
- package/shortcuts-manager/ShortcutsManager/index.tsx +2 -0
- package/shortcuts-manager/ShortcutsManager/utils.tsx +30 -0
- package/shortcuts-manager/index.tsx +6 -0
- package/shortcuts-manager/types.ts +24 -0
- package/shortcuts-manager/useIsKeyPressed/index.tsx +1 -0
- package/shortcuts-manager/useIsKeyPressed/useIsKeyPress.tsx +9 -0
- package/shortcuts-manager/useSetScopes/index.tsx +1 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.native.tsx +9 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +25 -0
- package/shortcuts-manager/useShortcut/index.tsx +2 -0
- package/shortcuts-manager/useShortcut/types.ts +3 -0
- package/shortcuts-manager/useShortcut/useShortcut.native.tsx +9 -0
- package/shortcuts-manager/useShortcut/useShortcut.tsx +61 -0
- package/shortcuts-manager/utils.ts +105 -0
- package/styles/index.ts +4 -0
- package/styles/overlay.ts +69 -0
- package/styles/shadow.ts +21 -0
- package/styles/themes/DarkTheme.tsx +98 -0
- package/styles/themes/LightTheme.tsx +212 -0
- package/styles/themes/tokens.ts +248 -0
- package/styles/utils.ts +11 -0
- package/types/index.ts +129 -0
- package/types/theme.ts +159 -0
- package/utils/DocumentPicker/documentPicker.native.ts +10 -0
- package/utils/DocumentPicker/documentPicker.ts +76 -0
- package/utils/DocumentPicker/index.ts +2 -0
- package/utils/DocumentPicker/types.ts +28 -0
- package/utils/addEventListener.tsx +51 -0
- package/utils/backgroundContext.ts +9 -0
- package/utils/color.ts +22 -0
- package/utils/compare/index.ts +54 -0
- package/utils/composeEventHandlers.ts +9 -0
- package/utils/createNumberMask/createNumberMask.ts +98 -0
- package/utils/createNumberMask/index.ts +5 -0
- package/utils/createSyntheticEvent.ts +31 -0
- package/utils/date-fns.ts +7 -0
- package/utils/dateTimePicker.ts +5 -0
- package/utils/escapeRegex.ts +9 -0
- package/utils/extractTextStyles.ts +52 -0
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +26 -0
- package/utils/formatNumberWithMask/formatWithMask.ts +119 -0
- package/utils/formatNumberWithMask/index.ts +6 -0
- package/utils/getCursorStyle/getCursorStyle.native.ts +1 -0
- package/utils/getCursorStyle/getCursorStyle.ts +1 -0
- package/utils/getCursorStyle/index.ts +1 -0
- package/utils/getOS/getOS.native.ts +7 -0
- package/utils/getOS/getOS.ts +24 -0
- package/utils/getOS/index.ts +1 -0
- package/utils/getyearRange.ts +5 -0
- package/utils/index.ts +20 -0
- package/utils/lodash.ts +50 -0
- package/utils/mergeRefs.ts +13 -0
- package/utils/normalizeBorderRadiuses.ts +24 -0
- package/utils/normalizeSpacings.ts +110 -0
- package/utils/normalizeToNumberString/index.ts +4 -0
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +48 -0
- package/utils/repository.ts +103 -0
- package/utils/resolveColorMode.ts +9 -0
- package/utils/resolveStateVariant.ts +26 -0
- package/utils/tokenStylesParser.ts +7 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentPropsWithRef,
|
|
3
|
+
createContext,
|
|
4
|
+
forwardRef,
|
|
5
|
+
memo,
|
|
6
|
+
type ReactElement,
|
|
7
|
+
useCallback,
|
|
8
|
+
useMemo,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { View } from 'react-native';
|
|
11
|
+
|
|
12
|
+
import { useControlledValue, useSubcomponents } from '../../hooks';
|
|
13
|
+
import { accordionStyles } from './utils';
|
|
14
|
+
|
|
15
|
+
export type Props = Omit<ComponentPropsWithRef<typeof View>, 'children'> & {
|
|
16
|
+
children: ReactElement | ReactElement[];
|
|
17
|
+
expandedItemIds?: string | string[];
|
|
18
|
+
defaultExpandedItemIds?: string | string[];
|
|
19
|
+
onChange?: (expandedItems: string | string[]) => void;
|
|
20
|
+
multiple?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const Accordion = (
|
|
24
|
+
{
|
|
25
|
+
children,
|
|
26
|
+
style,
|
|
27
|
+
expandedItemIds: expandedItemIdsProp,
|
|
28
|
+
defaultExpandedItemIds,
|
|
29
|
+
onChange: onChangeProp,
|
|
30
|
+
multiple = false,
|
|
31
|
+
...rest
|
|
32
|
+
}: Props,
|
|
33
|
+
ref: any,
|
|
34
|
+
) => {
|
|
35
|
+
const [expandedItemIds, onChange] = useControlledValue({
|
|
36
|
+
value: expandedItemIdsProp,
|
|
37
|
+
defaultValue: defaultExpandedItemIds,
|
|
38
|
+
onChange: onChangeProp,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const { AccordionItem } = useSubcomponents({ children, allowedChildren: ['AccordionItem'] });
|
|
42
|
+
|
|
43
|
+
const onPressItem = useCallback(
|
|
44
|
+
(id: string) => {
|
|
45
|
+
const isSelected = Array.isArray(expandedItemIds)
|
|
46
|
+
? expandedItemIds.find(_id => _id === id)
|
|
47
|
+
: expandedItemIds === id;
|
|
48
|
+
|
|
49
|
+
const multipleValue = Array.isArray(expandedItemIds)
|
|
50
|
+
? isSelected
|
|
51
|
+
? expandedItemIds.filter(_id => _id !== id)
|
|
52
|
+
: [...expandedItemIds, id]
|
|
53
|
+
: [id];
|
|
54
|
+
|
|
55
|
+
const singleValue = !isSelected ? id : '';
|
|
56
|
+
|
|
57
|
+
onChange(multiple ? multipleValue : singleValue);
|
|
58
|
+
},
|
|
59
|
+
[multiple, onChange, expandedItemIds],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const contextValue = useMemo(() => {
|
|
63
|
+
return {
|
|
64
|
+
expandedItemIds,
|
|
65
|
+
onChange,
|
|
66
|
+
onPressItem,
|
|
67
|
+
multiple,
|
|
68
|
+
};
|
|
69
|
+
}, [expandedItemIds, multiple, onChange, onPressItem]);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<View style={[accordionStyles.root, style]} {...rest} ref={ref}>
|
|
73
|
+
<AccordionContext.Provider value={contextValue}>
|
|
74
|
+
{AccordionItem}
|
|
75
|
+
</AccordionContext.Provider>
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type AccordionContextType = {
|
|
81
|
+
expandedItemIds: string | string[] | undefined;
|
|
82
|
+
onChange: ((expandedItems: string | string[]) => void) | undefined;
|
|
83
|
+
onPressItem: ((id: string) => void) | undefined;
|
|
84
|
+
multiple: boolean;
|
|
85
|
+
} | null;
|
|
86
|
+
|
|
87
|
+
export const AccordionContext = createContext<AccordionContextType>(null);
|
|
88
|
+
|
|
89
|
+
export default memo(forwardRef(Accordion));
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
forwardRef,
|
|
4
|
+
memo,
|
|
5
|
+
ReactElement,
|
|
6
|
+
ReactNode,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useMemo,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { View, type ViewProps } from 'react-native';
|
|
12
|
+
import { useControlledValue, useSubcomponents } from '../../hooks';
|
|
13
|
+
import type { WithElements } from '../../types';
|
|
14
|
+
import { AccordionContext } from './Accordion';
|
|
15
|
+
import { accordionItemStyles } from './utils';
|
|
16
|
+
|
|
17
|
+
export type Props = Omit<ViewProps, 'children'> &
|
|
18
|
+
WithElements<ReactNode> & {
|
|
19
|
+
id?: string;
|
|
20
|
+
expanded?: boolean;
|
|
21
|
+
setExpanded?: (expanded: boolean) => void;
|
|
22
|
+
children: ReactElement | ReactElement[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const AccordionItem = memo(
|
|
26
|
+
forwardRef(
|
|
27
|
+
(
|
|
28
|
+
{
|
|
29
|
+
id,
|
|
30
|
+
expanded: expandedProp,
|
|
31
|
+
setExpanded: setExpandedProp,
|
|
32
|
+
children,
|
|
33
|
+
style,
|
|
34
|
+
...rest
|
|
35
|
+
}: Props,
|
|
36
|
+
ref: any,
|
|
37
|
+
) => {
|
|
38
|
+
const [expanded, onExpandedChange] = useControlledValue({
|
|
39
|
+
value: expandedProp,
|
|
40
|
+
onChange: setExpandedProp,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const expandedInternal = expandedProp !== undefined ? expandedProp : expanded;
|
|
44
|
+
|
|
45
|
+
const groupContext = useContext(AccordionContext);
|
|
46
|
+
|
|
47
|
+
const { AccordionItem_Header, AccordionItem_Content } = useSubcomponents({
|
|
48
|
+
children,
|
|
49
|
+
allowedChildren: ['AccordionItem_Header', 'AccordionItem_Content'],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (groupContext !== null && !id) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'AccordionItem is used inside Accordion without specifying an id prop.',
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}, [groupContext, id]);
|
|
59
|
+
|
|
60
|
+
const contextValue = useMemo(() => {
|
|
61
|
+
const isExpanded = groupContext
|
|
62
|
+
? Array.isArray(groupContext.expandedItemIds)
|
|
63
|
+
? !!groupContext.expandedItemIds.find(_id => _id === id)
|
|
64
|
+
: groupContext.expandedItemIds === id
|
|
65
|
+
: expandedInternal;
|
|
66
|
+
|
|
67
|
+
const handleExpandChange =
|
|
68
|
+
groupContext && id !== undefined
|
|
69
|
+
? () => groupContext.onPressItem?.(id)
|
|
70
|
+
: onExpandedChange;
|
|
71
|
+
|
|
72
|
+
return { expanded: isExpanded, onExpandedChange: handleExpandChange };
|
|
73
|
+
}, [groupContext, id, expandedInternal, onExpandedChange]);
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<View style={[accordionItemStyles.root, style]} {...rest} ref={ref}>
|
|
77
|
+
<AccordionItemContext.Provider value={contextValue}>
|
|
78
|
+
{AccordionItem_Header[0]}
|
|
79
|
+
{contextValue.expanded ? AccordionItem_Content[0] : null}
|
|
80
|
+
</AccordionItemContext.Provider>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
export const AccordionItemContext = createContext({
|
|
88
|
+
expanded: false,
|
|
89
|
+
onExpandedChange: (_expanded: boolean) => {},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
AccordionItem.displayName = 'AccordionItem';
|
|
93
|
+
|
|
94
|
+
export default AccordionItem;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
|
+
import { accordionItemContentStyles } from './utils';
|
|
4
|
+
|
|
5
|
+
export type Props = ViewProps & {};
|
|
6
|
+
|
|
7
|
+
const AccordionItemContent = memo(({ style, children, ...rest }: Props) => {
|
|
8
|
+
return (
|
|
9
|
+
<View style={[accordionItemContentStyles.root, style]} {...rest}>
|
|
10
|
+
{children}
|
|
11
|
+
</View>
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
AccordionItemContent.displayName = 'AccordionItem_Content';
|
|
16
|
+
|
|
17
|
+
export default AccordionItemContent;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { forwardRef, memo, ReactNode, useCallback, useContext, useMemo } from 'react';
|
|
2
|
+
import type { WithElements } from '../../types';
|
|
3
|
+
import { TouchableRipple, type TouchableRippleProps } from '../TouchableRipple';
|
|
4
|
+
import { AccordionItemContext } from './AccordionItem';
|
|
5
|
+
import { View, type GestureResponderEvent, type TextStyle, type ViewStyle } from 'react-native';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
import { accordionItemHeaderStyles } from './utils';
|
|
8
|
+
import { resolveStateVariant } from '../../utils';
|
|
9
|
+
import { useActionState } from '../../hooks';
|
|
10
|
+
|
|
11
|
+
export type AccordionHeaderElementProps = {
|
|
12
|
+
color: string;
|
|
13
|
+
expanded: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type Element = ReactNode | ((props: AccordionHeaderElementProps) => ReactNode);
|
|
17
|
+
|
|
18
|
+
export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
19
|
+
WithElements<Element> & {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
leftElementStyle?: ViewStyle;
|
|
22
|
+
rightElementStyle?: ViewStyle;
|
|
23
|
+
contentStyle?: TextStyle;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const emptyArr = {};
|
|
27
|
+
|
|
28
|
+
const AccordionItemHeader = memo(
|
|
29
|
+
forwardRef(
|
|
30
|
+
(
|
|
31
|
+
{
|
|
32
|
+
left,
|
|
33
|
+
right,
|
|
34
|
+
style,
|
|
35
|
+
children,
|
|
36
|
+
leftElementStyle: leftElementStyleProp = emptyArr,
|
|
37
|
+
rightElementStyle: rightElementStyleProp = emptyArr,
|
|
38
|
+
contentStyle: contentStyleProp = emptyArr,
|
|
39
|
+
onPress: onPressProp,
|
|
40
|
+
...rest
|
|
41
|
+
}: Props,
|
|
42
|
+
ref: any,
|
|
43
|
+
) => {
|
|
44
|
+
const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
|
|
45
|
+
|
|
46
|
+
const { expanded, onExpandedChange } = useContext(AccordionItemContext);
|
|
47
|
+
|
|
48
|
+
const state = resolveStateVariant({
|
|
49
|
+
expandedAndHovered: expanded && hovered,
|
|
50
|
+
expanded,
|
|
51
|
+
hovered,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// @ts-ignore // TODO - fix this issue
|
|
55
|
+
accordionItemHeaderStyles.useVariants({
|
|
56
|
+
state,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const onPress = useCallback(
|
|
60
|
+
(e: GestureResponderEvent) => {
|
|
61
|
+
onPressProp?.(e);
|
|
62
|
+
|
|
63
|
+
onExpandedChange(!expanded);
|
|
64
|
+
},
|
|
65
|
+
[expanded, onPressProp, onExpandedChange],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const { containerStyle } = useMemo(() => {
|
|
69
|
+
return {
|
|
70
|
+
containerStyle: [accordionItemHeaderStyles.root, style],
|
|
71
|
+
};
|
|
72
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
+
}, [style, state]);
|
|
74
|
+
|
|
75
|
+
const elementProps = useMemo(
|
|
76
|
+
() => ({
|
|
77
|
+
color: accordionItemHeaderStyles.root.elementColor,
|
|
78
|
+
expanded,
|
|
79
|
+
}),
|
|
80
|
+
[expanded],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<TouchableRipple
|
|
85
|
+
style={containerStyle}
|
|
86
|
+
{...rest}
|
|
87
|
+
onPress={onPress}
|
|
88
|
+
ref={actionsRef}>
|
|
89
|
+
<>
|
|
90
|
+
{left && (
|
|
91
|
+
<View
|
|
92
|
+
style={[
|
|
93
|
+
accordionItemHeaderStyles.leftElement,
|
|
94
|
+
leftElementStyleProp,
|
|
95
|
+
]}>
|
|
96
|
+
{typeof left === 'function' ? left(elementProps) : left}
|
|
97
|
+
</View>
|
|
98
|
+
)}
|
|
99
|
+
<Text
|
|
100
|
+
style={[accordionItemHeaderStyles.content, contentStyleProp]}
|
|
101
|
+
selectable={false}>
|
|
102
|
+
{children}
|
|
103
|
+
</Text>
|
|
104
|
+
{right && (
|
|
105
|
+
<View
|
|
106
|
+
style={[
|
|
107
|
+
accordionItemHeaderStyles.rightElement,
|
|
108
|
+
rightElementStyleProp,
|
|
109
|
+
]}>
|
|
110
|
+
{typeof right === 'function' ? right(elementProps) : right}
|
|
111
|
+
</View>
|
|
112
|
+
)}
|
|
113
|
+
</>
|
|
114
|
+
</TouchableRipple>
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
AccordionItemHeader.displayName = 'AccordionItem_Header';
|
|
121
|
+
|
|
122
|
+
export default AccordionItemHeader;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import AccordionItemComponent from './AccordionItem';
|
|
2
|
+
import AccordionItemHeader from './AccordionItemHeader';
|
|
3
|
+
import AccordionItemContent from './AccordionItemContent';
|
|
4
|
+
import AccordionDefault from './Accordion';
|
|
5
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
6
|
+
|
|
7
|
+
const AccordionItemDefault = Object.assign(AccordionItemComponent, {
|
|
8
|
+
Header: AccordionItemHeader,
|
|
9
|
+
Content: AccordionItemContent,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
registerMoleculesComponents({
|
|
13
|
+
Accordion: AccordionDefault,
|
|
14
|
+
AccordionItem: AccordionItemDefault,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const Accordion = getRegisteredComponentWithFallback('Accordion', AccordionDefault);
|
|
18
|
+
export const AccordionItem = getRegisteredComponentWithFallback(
|
|
19
|
+
'AccordionItem',
|
|
20
|
+
AccordionItemDefault,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export type { Props as AccordionProps } from './Accordion';
|
|
24
|
+
export type { Props as AccordionItemProps } from './AccordionItem';
|
|
25
|
+
export type {
|
|
26
|
+
Props as AccordionItemHeaderProps,
|
|
27
|
+
AccordionHeaderElementProps,
|
|
28
|
+
} from './AccordionItemHeader';
|
|
29
|
+
export type { Props as AccordionItemContentProps } from './AccordionItemContent';
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
accordionStyles,
|
|
33
|
+
accordionItemStyles,
|
|
34
|
+
accordionItemHeaderStyles,
|
|
35
|
+
accordionItemContentStyles,
|
|
36
|
+
} from './utils';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
4
|
+
|
|
5
|
+
const accordionStylesDefault = StyleSheet.create({
|
|
6
|
+
root: {},
|
|
7
|
+
});
|
|
8
|
+
const accordionItemStylesDefault = StyleSheet.create({
|
|
9
|
+
root: {},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const accordionItemHeaderStylesDefault = StyleSheet.create(theme => ({
|
|
13
|
+
root: {
|
|
14
|
+
minHeight: 56,
|
|
15
|
+
flexDirection: 'row',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
borderRadius: theme.shapes.corner.full,
|
|
18
|
+
paddingLeft: theme.spacings['4'],
|
|
19
|
+
paddingRight: theme.spacings['6'],
|
|
20
|
+
elementColor: theme.colors.onSurfaceVariant,
|
|
21
|
+
state: {
|
|
22
|
+
expandedAndHovered: {
|
|
23
|
+
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
24
|
+
},
|
|
25
|
+
expanded: {},
|
|
26
|
+
hovered: {
|
|
27
|
+
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
leftElement: {
|
|
33
|
+
marginRight: theme.spacings['3'],
|
|
34
|
+
},
|
|
35
|
+
rightElement: {
|
|
36
|
+
marginLeft: theme.spacings['3'],
|
|
37
|
+
},
|
|
38
|
+
content: {
|
|
39
|
+
color: theme.colors.onSurfaceVariant,
|
|
40
|
+
...theme.typescale.titleMedium,
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
const accordionItemContentStylesDefault = StyleSheet.create(theme => ({
|
|
45
|
+
root: {
|
|
46
|
+
paddingLeft: theme.spacings['6'],
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
registerComponentsStyles({
|
|
51
|
+
Accordion: accordionStylesDefault,
|
|
52
|
+
AccordionItem: accordionItemStylesDefault,
|
|
53
|
+
AccordionItem_Header: accordionItemHeaderStylesDefault,
|
|
54
|
+
AccordionItem_Content: accordionItemContentStylesDefault,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const accordionStyles = getRegisteredMoleculesComponentStyles('Accordion');
|
|
58
|
+
export const accordionItemStyles = getRegisteredMoleculesComponentStyles('AccordionItem');
|
|
59
|
+
export const accordionItemHeaderStyles =
|
|
60
|
+
getRegisteredMoleculesComponentStyles('AccordionItem_Header');
|
|
61
|
+
export const accordionItemContentStyles =
|
|
62
|
+
getRegisteredMoleculesComponentStyles('AccordionItem_Content');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ActivityIndicator as default } from 'react-native';
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type ActivityIndicatorProps,
|
|
4
|
+
Animated,
|
|
5
|
+
Easing,
|
|
6
|
+
Platform,
|
|
7
|
+
View,
|
|
8
|
+
type ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
11
|
+
|
|
12
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentStyles } from '../../core';
|
|
13
|
+
import AnimatedSpinner from './AnimatedSpinner';
|
|
14
|
+
|
|
15
|
+
export type Props = ActivityIndicatorProps & {
|
|
16
|
+
/**
|
|
17
|
+
* Whether to show the indicator or hide it.
|
|
18
|
+
*/
|
|
19
|
+
animating?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The color of the spinner.
|
|
22
|
+
*/
|
|
23
|
+
color?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Size of the indicator.
|
|
26
|
+
*/
|
|
27
|
+
size?: 'small' | 'large' | number;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the indicator should hide when not animating.
|
|
30
|
+
*/
|
|
31
|
+
hidesWhenStopped?: boolean;
|
|
32
|
+
style?: ViewStyle;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const DURATION = 2400;
|
|
36
|
+
|
|
37
|
+
const mapIndicatorSize = (indicatorSize: 'small' | 'large' | number | undefined) => {
|
|
38
|
+
if (typeof indicatorSize === 'string') {
|
|
39
|
+
return indicatorSize === 'small' ? 24 : 48;
|
|
40
|
+
}
|
|
41
|
+
return indicatorSize ? indicatorSize : 24;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Activity indicator is used to present progress of some activity in the app.
|
|
46
|
+
* It can be used as a drop-in for the ActivityIndicator shipped with React Native.
|
|
47
|
+
*
|
|
48
|
+
* <div class="screenshots">
|
|
49
|
+
* <img src="screenshots/activity-indicator.gif" style="width: 100px;" />
|
|
50
|
+
* </div>
|
|
51
|
+
*
|
|
52
|
+
* ## Usage
|
|
53
|
+
* ```js
|
|
54
|
+
* import * as React from 'react';
|
|
55
|
+
* import { ActivityIndicator, MD2Colors } from 'react-native-paper';
|
|
56
|
+
*
|
|
57
|
+
* const MyComponent = () => (
|
|
58
|
+
* <ActivityIndicator animating={true} color={MD2Colors.red800} />
|
|
59
|
+
* );
|
|
60
|
+
*
|
|
61
|
+
* export default MyComponent;
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
const ActivityIndicator = ({
|
|
65
|
+
animating = true,
|
|
66
|
+
color: indicatorColorProp,
|
|
67
|
+
hidesWhenStopped = true,
|
|
68
|
+
size: indicatorSize = 'small',
|
|
69
|
+
style: styleProp,
|
|
70
|
+
...rest
|
|
71
|
+
}: Props) => {
|
|
72
|
+
// const componentStyles = useComponentStyles('ActivityIndicator', [
|
|
73
|
+
// styleProp,
|
|
74
|
+
// { normalizedIndicatorColorProp: indicatorColorProp },
|
|
75
|
+
// ]);
|
|
76
|
+
const componentStyles = activityIndicatorStyles;
|
|
77
|
+
const { current: timer } = useRef<Animated.Value>(new Animated.Value(0));
|
|
78
|
+
const { current: fade } = useRef<Animated.Value>(
|
|
79
|
+
new Animated.Value(!animating && hidesWhenStopped ? 0 : 1),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const rotation = useRef<Animated.CompositeAnimation | undefined>(undefined);
|
|
83
|
+
|
|
84
|
+
const size = mapIndicatorSize(indicatorSize);
|
|
85
|
+
|
|
86
|
+
const { color, viewStyle, animatedViewStyle } = useMemo(() => {
|
|
87
|
+
return {
|
|
88
|
+
color: indicatorColorProp,
|
|
89
|
+
viewStyle: [componentStyles.container, styleProp],
|
|
90
|
+
animatedViewStyle: [{ width: size, height: size, opacity: fade }],
|
|
91
|
+
};
|
|
92
|
+
}, [componentStyles.container, fade, indicatorColorProp, size, styleProp]);
|
|
93
|
+
|
|
94
|
+
const startRotation = useCallback(() => {
|
|
95
|
+
// Show indicator
|
|
96
|
+
Animated.timing(fade, {
|
|
97
|
+
duration: 200,
|
|
98
|
+
toValue: 1,
|
|
99
|
+
isInteraction: false,
|
|
100
|
+
useNativeDriver: true,
|
|
101
|
+
}).start();
|
|
102
|
+
|
|
103
|
+
// Circular animation in loop
|
|
104
|
+
if (rotation.current) {
|
|
105
|
+
timer.setValue(0);
|
|
106
|
+
// $FlowFixMe
|
|
107
|
+
Animated.loop(rotation.current).start();
|
|
108
|
+
}
|
|
109
|
+
}, [fade, timer]);
|
|
110
|
+
|
|
111
|
+
const stopRotation = () => {
|
|
112
|
+
if (rotation.current) {
|
|
113
|
+
rotation.current.stop();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (rotation.current === undefined) {
|
|
119
|
+
// Circular animation in loop
|
|
120
|
+
rotation.current = Animated.timing(timer, {
|
|
121
|
+
duration: DURATION,
|
|
122
|
+
easing: Easing.linear,
|
|
123
|
+
// Animated.loop does not work if useNativeDriver is true on web
|
|
124
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
125
|
+
toValue: 1,
|
|
126
|
+
isInteraction: false,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (animating) {
|
|
131
|
+
startRotation();
|
|
132
|
+
} else if (hidesWhenStopped) {
|
|
133
|
+
// Hide indicator first and then stop rotation
|
|
134
|
+
Animated.timing(fade, {
|
|
135
|
+
duration: 200,
|
|
136
|
+
toValue: 0,
|
|
137
|
+
useNativeDriver: true,
|
|
138
|
+
isInteraction: false,
|
|
139
|
+
}).start(stopRotation);
|
|
140
|
+
} else {
|
|
141
|
+
stopRotation();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return () => {
|
|
145
|
+
if (animating) stopRotation();
|
|
146
|
+
};
|
|
147
|
+
}, [animating, fade, hidesWhenStopped, startRotation, timer]);
|
|
148
|
+
|
|
149
|
+
// console.log({ layer: defaultStyles.layer });
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<View
|
|
153
|
+
style={viewStyle}
|
|
154
|
+
{...rest}
|
|
155
|
+
accessible
|
|
156
|
+
accessibilityRole="progressbar"
|
|
157
|
+
accessibilityState={{ busy: animating }}>
|
|
158
|
+
<Animated.View style={animatedViewStyle} collapsable={false}>
|
|
159
|
+
{[0, 1].map(index => {
|
|
160
|
+
// Thanks to https://github.com/n4kz/react-native-indicators for the great work
|
|
161
|
+
return (
|
|
162
|
+
<AnimatedSpinner
|
|
163
|
+
key={index}
|
|
164
|
+
style={componentStyles.root}
|
|
165
|
+
index={index}
|
|
166
|
+
size={size}
|
|
167
|
+
color={color}
|
|
168
|
+
timer={timer}
|
|
169
|
+
// style={defaultStyles.layer}
|
|
170
|
+
duration={DURATION}
|
|
171
|
+
/>
|
|
172
|
+
);
|
|
173
|
+
})}
|
|
174
|
+
</Animated.View>
|
|
175
|
+
</View>
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const activityIndicatorStylesDefault = StyleSheet.create(theme => ({
|
|
180
|
+
spinner: {
|
|
181
|
+
borderColor: theme.colors.primary,
|
|
182
|
+
},
|
|
183
|
+
container: {
|
|
184
|
+
justifyContent: 'center',
|
|
185
|
+
alignItems: 'center',
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
layer: {
|
|
189
|
+
...StyleSheet.absoluteFillObject,
|
|
190
|
+
|
|
191
|
+
justifyContent: 'center',
|
|
192
|
+
alignItems: 'center',
|
|
193
|
+
},
|
|
194
|
+
}));
|
|
195
|
+
|
|
196
|
+
registerComponentStyles('ActivityIndicator', activityIndicatorStylesDefault);
|
|
197
|
+
|
|
198
|
+
export const activityIndicatorStyles = getRegisteredMoleculesComponentStyles('ActivityIndicator');
|
|
199
|
+
|
|
200
|
+
export default memo(ActivityIndicator);
|