@hero-design/rn 8.35.0-alpha.1 → 8.35.0-alpha.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.35.0-alpha.1",
3
+ "version": "8.35.0-alpha.2",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -21,6 +21,7 @@
21
21
  "dependencies": {
22
22
  "@emotion/native": "^11.9.3",
23
23
  "@emotion/react": "^11.9.3",
24
+ "@gorhom/portal": "^1.0.14",
24
25
  "@hero-design/colors": "8.34.1",
25
26
  "date-fns": "^2.16.1",
26
27
  "events": "^3.2.0",
@@ -82,6 +83,5 @@
82
83
  "rollup-plugin-flow": "^1.1.1",
83
84
  "ts-jest": "^27.0.7"
84
85
  },
85
- "prettier": "prettier-config-hd",
86
- "react-native": "src/index.ts"
86
+ "prettier": "prettier-config-hd"
87
87
  }
@@ -1,6 +1,6 @@
1
1
  import React, { forwardRef, useRef } from 'react';
2
2
  import type { StyleProp, ViewStyle } from 'react-native';
3
- import { Animated, Modal, Platform } from 'react-native';
3
+ import { Animated, Platform } from 'react-native';
4
4
  import type { IconName } from '../../Icon';
5
5
  import type { ActionItemProps } from './ActionItem';
6
6
  import ActionItem from './ActionItem';
@@ -14,7 +14,7 @@ import {
14
14
 
15
15
  import Box from '../../Box';
16
16
  import { FABHandles } from '../FAB';
17
- import { FABModal } from '../../..';
17
+ import { Portal } from '@gorhom/portal';
18
18
 
19
19
  export type ActionGroupHandles = {
20
20
  showFAB: () => void;
@@ -32,6 +32,7 @@ export interface ActionGroupProps {
32
32
  * This function is called on pressing the FAB button.
33
33
  * */
34
34
  onPress?: () => void;
35
+
35
36
  /**
36
37
  * Specify if the FAB button is in active state and the action group is shown.
37
38
  * */
@@ -61,6 +62,7 @@ export interface ActionGroupProps {
61
62
  * Testing id of the component.
62
63
  */
63
64
  testID?: string;
65
+ portalName?: string;
64
66
  }
65
67
 
66
68
  const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
@@ -74,6 +76,7 @@ const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
74
76
  testID,
75
77
  fabTitle,
76
78
  fabIcon = 'add',
79
+ portalName,
77
80
  },
78
81
  ref
79
82
  ) => {
@@ -123,51 +126,45 @@ const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
123
126
  outputRange: [0, 1],
124
127
  });
125
128
 
129
+ const Wrapper = portalName ? Portal : React.Fragment;
126
130
  return (
127
- <StyledContainer testID={testID} pointerEvents="box-none" style={style}>
128
- <FABModal visible={active}>
129
- <StyledContainer
130
- testID={testID}
131
- pointerEvents="box-none"
132
- style={style}
131
+ <Wrapper name={portalName}>
132
+ <StyledContainer testID={testID} pointerEvents="box-none" style={style}>
133
+ <StyledBackdrop
134
+ pointerEvents={active ? 'auto' : 'box-none'}
135
+ testID="back-drop"
136
+ style={{ opacity: interpolatedBackdropOpacityAnimation }}
137
+ />
138
+ <StyledActionGroupContainer
139
+ pointerEvents={active ? 'auto' : 'none'}
140
+ testID="action-group"
141
+ style={{
142
+ opacity: interpolatedActionGroupOpacityAnimation,
143
+ }}
133
144
  >
134
- <StyledBackdrop
135
- pointerEvents={active ? 'auto' : 'box-none'}
136
- testID="back-drop"
137
- style={{
138
- opacity: interpolatedBackdropOpacityAnimation,
139
- backgroundColor: 'yellow',
140
- }}
141
- />
142
- <StyledActionGroupContainer
143
- pointerEvents={active ? 'auto' : 'none'}
144
- testID="action-group"
145
- style={{
146
- opacity: interpolatedActionGroupOpacityAnimation,
147
- flex: 1,
148
- }}
149
- >
150
- {!!headerTitle && (
151
- <Animated.View
152
- style={{ transform: [{ translateY: titleTranslateY }] }}
153
- >
154
- <StyledHeaderText testID="header-text" level="h4">
155
- {headerTitle}
156
- </StyledHeaderText>
157
- </Animated.View>
158
- )}
159
-
160
- <Box style={[style, { paddingBottom: 0 }]}>
161
- {items?.map((itemProp, index) => (
162
- <ActionItem
163
- key={itemProp.key || `${itemProp.icon}_${itemProp.title}`}
164
- {...itemProp}
165
- index={active ? index : items.length - index}
166
- active={active}
167
- />
168
- ))}
169
- </Box>
170
- </StyledActionGroupContainer>
145
+ {!!headerTitle && (
146
+ <Animated.View
147
+ style={{ transform: [{ translateY: titleTranslateY }] }}
148
+ >
149
+ <StyledHeaderText testID="header-text" level="h4">
150
+ {headerTitle}
151
+ </StyledHeaderText>
152
+ </Animated.View>
153
+ )}
154
+
155
+ <Box style={[style, { paddingBottom: 0 }]}>
156
+ {items?.map((itemProp, index) => (
157
+ <ActionItem
158
+ key={itemProp.key || `${itemProp.icon}_${itemProp.title}`}
159
+ {...itemProp}
160
+ index={active ? index : items.length - index}
161
+ active={active}
162
+ />
163
+ ))}
164
+ </Box>
165
+ </StyledActionGroupContainer>
166
+
167
+ <Portal hostName="CustomPortalHost">
171
168
  <StyledFAB
172
169
  testID="fab"
173
170
  icon={fabIcon}
@@ -177,18 +174,9 @@ const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
177
174
  title={fabTitle}
178
175
  ref={fabRef}
179
176
  />
180
- </StyledContainer>
181
- </FABModal>
182
- <StyledFAB
183
- testID="fab"
184
- icon={fabIcon}
185
- onPress={onPress}
186
- animated
187
- active={active}
188
- title={fabTitle}
189
- ref={fabRef}
190
- />
191
- </StyledContainer>
177
+ </Portal>
178
+ </StyledContainer>
179
+ </Wrapper>
192
180
  );
193
181
  }
194
182
  );
@@ -163,16 +163,7 @@ const FAB = forwardRef<FABHandles, FABProps>(
163
163
  return (
164
164
  <StyledFAB
165
165
  /** Add a small timeout before executing animation to prevent flakiness */
166
- onLayout={() => {
167
- setTimeout(() => setCanAnimate(true), 500);
168
- }}
169
- ref={(ref) => {
170
- if (ref) {
171
- ref.measureInWindow((x, y, width, height) => {
172
- console.log('measureInWindow', x, y, width, height);
173
- });
174
- }
175
- }}
166
+ onLayout={() => setTimeout(() => setCanAnimate(true), 500)}
176
167
  underlayColor={theme.__hd__.fab.colors.buttonPressedBackground}
177
168
  onPress={onPress}
178
169
  style={[
@@ -1,6 +1,10 @@
1
1
  import FAB from './FAB';
2
2
  import ActionGroup from './ActionGroup';
3
+ import { Portal, PortalHost, PortalProvider } from '@gorhom/portal';
3
4
 
4
5
  export default Object.assign(FAB, {
5
6
  ActionGroup,
7
+ Portal: Portal,
8
+ PortalHost: PortalHost,
9
+ Provider: PortalProvider,
6
10
  });
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ import theme, {
12
12
  withTheme,
13
13
  } from './theme';
14
14
  import { scale } from './utils/scale';
15
+ import * as Portal from '@gorhom/portal';
15
16
 
16
17
  import Accordion from './components/Accordion';
17
18
  import Alert from './components/Alert';
@@ -60,7 +61,6 @@ import Rate from './components/Rate';
60
61
  import RefreshControl from './components/RefreshControl';
61
62
  import RichTextEditor from './components/RichTextEditor';
62
63
  import PageControl from './components/PageControl';
63
- import FABModal from './components/FAB/ActionGroup/FABModal';
64
64
 
65
65
  export {
66
66
  theme,
@@ -124,7 +124,7 @@ export {
124
124
  Rate,
125
125
  RefreshControl,
126
126
  RichTextEditor,
127
- FABModal,
127
+ Portal,
128
128
  };
129
129
 
130
130
  export * from './types';
package/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import theme, { getTheme, ThemeProvider, useTheme, swagSystemPalette, swagDarkSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, ThemeSwitcher, withTheme } from './theme';
2
2
  import { scale } from './utils/scale';
3
+ import * as Portal from '@gorhom/portal';
3
4
  import Accordion from './components/Accordion';
4
5
  import Alert from './components/Alert';
5
6
  import Attachment from './components/Attachment';
@@ -47,6 +48,5 @@ import Rate from './components/Rate';
47
48
  import RefreshControl from './components/RefreshControl';
48
49
  import RichTextEditor from './components/RichTextEditor';
49
50
  import PageControl from './components/PageControl';
50
- import FABModal from './components/FAB/ActionGroup/FABModal';
51
- export { theme, getTheme, useTheme, scale, ThemeProvider, ThemeSwitcher, withTheme, swagSystemPalette, swagDarkSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, Accordion, Alert, Attachment, Avatar, useAvatarColors, Badge, BottomNavigation, BottomSheet, Box, Button, Calendar, Card, Carousel, Collapse, Checkbox, ContentNavigator, DatePicker, Divider, Drawer, Empty, Error, FAB, Icon, Image, List, Modal, PinInput, Progress, PageControl, Skeleton, Slider, Spinner, Swipeable, Radio, SectionHeading, Select, Success, Switch, Tabs, Tag, TextInput, TimePicker, Toast, Toolbar, Typography, Rate, RefreshControl, RichTextEditor, FABModal, };
51
+ export { theme, getTheme, useTheme, scale, ThemeProvider, ThemeSwitcher, withTheme, swagSystemPalette, swagDarkSystemPalette, workSystemPalette, jobsSystemPalette, walletSystemPalette, eBensSystemPalette, Accordion, Alert, Attachment, Avatar, useAvatarColors, Badge, BottomNavigation, BottomSheet, Box, Button, Calendar, Card, Carousel, Collapse, Checkbox, ContentNavigator, DatePicker, Divider, Drawer, Empty, Error, FAB, Icon, Image, List, Modal, PinInput, Progress, PageControl, Skeleton, Slider, Spinner, Swipeable, Radio, SectionHeading, Select, Success, Switch, Tabs, Tag, TextInput, TimePicker, Toast, Toolbar, Typography, Rate, RefreshControl, RichTextEditor, Portal, };
52
52
  export * from './types';
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
- import { Dimensions, View, ViewStyle } from 'react-native';
3
- import { ModalHandler, showFABModal } from './ModalPresenter';
4
-
5
- const wrapperStyle: ViewStyle = {
6
- width: Dimensions.get('window').width,
7
- height: Dimensions.get('window').height,
8
- };
9
-
10
- export interface ModalProps {
11
- /**
12
- * Content of the modal.
13
- */
14
- children: React.ReactElement;
15
- /**
16
- * Visibility of the modal
17
- */
18
- visible?: boolean;
19
- /**
20
- * Callback when the modal is shown.
21
- */
22
- onShow?: () => void;
23
- /**
24
- * TestID of the modal.
25
- */
26
- testID?: string;
27
- }
28
-
29
- const fABModal = ({ children, onShow, testID, visible = true }: ModalProps) => {
30
- const [modalHandler, setModalHandler] = React.useState<ModalHandler>();
31
-
32
- const getModalContent = React.useCallback(
33
- () => (
34
- <View pointerEvents="box-none" style={wrapperStyle} testID={testID}>
35
- {children}
36
- </View>
37
- ),
38
- [visible, children, onShow, testID]
39
- );
40
-
41
- React.useEffect(() => {
42
- if (visible) {
43
- // Modal does not exist, create a new one
44
- if (!modalHandler) {
45
- const newModalHandler = showFABModal(getModalContent());
46
- setModalHandler(newModalHandler);
47
-
48
- onShow?.();
49
- }
50
- // Modal already exists, update it
51
- else {
52
- modalHandler.update(getModalContent());
53
- }
54
- } else {
55
- modalHandler?.dismiss();
56
- setModalHandler(undefined);
57
- }
58
- }, [getModalContent]);
59
-
60
- return null;
61
- };
62
-
63
- export default fABModal;
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import { StyleProp, View, ViewStyle } from 'react-native';
3
-
4
- type ModalContentWrapperProps = {
5
- children: React.ReactElement;
6
- visible?: boolean;
7
- testID?: string;
8
- style?: StyleProp<ViewStyle>;
9
- animated?: boolean;
10
- pointerEvents: 'box-none' | 'none' | 'box-only' | 'auto';
11
- };
12
-
13
- export type ModalContentWrapperHandler = {
14
- hide: (callback?: () => void) => void;
15
- };
16
-
17
- const FABModalContentWrapper = ({
18
- children,
19
- testID,
20
- pointerEvents,
21
- }: ModalContentWrapperProps) => {
22
- return (
23
- <View testID={testID} pointerEvents={pointerEvents}>
24
- {children}
25
- </View>
26
- );
27
- };
28
-
29
- FABModalContentWrapper.displayName = 'FABModalContentWrapper';
30
-
31
- export default FABModalContentWrapper;
@@ -1,133 +0,0 @@
1
- import React, { forwardRef, useRef } from 'react';
2
- import { Animated, StyleSheet, ViewProps } from 'react-native';
3
- import RootSiblings from 'react-native-root-siblings';
4
- import Box from '../../../Box';
5
-
6
- export type ModalPresenterHandles = {
7
- animatedOut: (completion?: () => void) => void;
8
- };
9
- export type FABModalDismissFunc = (onDismiss?: () => void) => void;
10
- export type FABModalUpdateFunc = (content: React.ReactNode) => void;
11
-
12
- /**
13
- * Modal handler is returned by `showModal` function.
14
- */
15
- export type FABModalHandler = {
16
- /**
17
- * Same `dismiss` function as in `ModalContentProps`.
18
- */
19
- dismiss: FABModalDismissFunc;
20
- /**
21
- * Same `update` function as in `ModalContentProps`.
22
- */
23
- update: FABModalUpdateFunc;
24
- };
25
-
26
- const FABModalPresenter = forwardRef<ModalPresenterHandles, ViewProps>(
27
- ({ style, children, ...props }, ref) => {
28
- const animatedOpacity = useRef(new Animated.Value(0));
29
-
30
- React.useEffect(() => {
31
- Animated.spring(animatedOpacity.current, {
32
- toValue: 1,
33
- useNativeDriver: true,
34
- }).start();
35
- }, []);
36
-
37
- React.useImperativeHandle(ref, () => ({
38
- animatedOut: (completion?: () => void) => {
39
- Animated.spring(animatedOpacity.current, {
40
- toValue: 0,
41
- useNativeDriver: true,
42
- }).start(() => {
43
- completion?.();
44
- });
45
- },
46
- }));
47
-
48
- return (
49
- <Box style={StyleSheet.absoluteFill} pointerEvents="box-none">
50
- <Animated.View
51
- style={[
52
- {
53
- width: '100%',
54
- height: '100%',
55
- justifyContent: 'center',
56
- alignItems: 'center',
57
- opacity: animatedOpacity.current,
58
- },
59
- style,
60
- ]}
61
- {...props}
62
- pointerEvents="box-none"
63
- >
64
- {children}
65
- </Animated.View>
66
- </Box>
67
- );
68
- }
69
- );
70
-
71
- /**
72
- * Present a modal on screen immediately.
73
- *
74
- * The new presented modal will be on top of existing modals if there are any.
75
- *
76
- * @param Content A component to be presented as a modal on screen.
77
- * This component will be centered horizontally and vertically on screen with
78
- * a semitransparent black overlay underneath.
79
- * @param contentProps Props for this modal component.
80
- * @returns A `ModalHandler` you can use to dismiss the modal.
81
- */
82
-
83
- export const showFABModal = (content: React.ReactNode): FABModalHandler => {
84
- let ref: ModalPresenterHandles | null = null;
85
- let rootSiblings: RootSiblings | null = null;
86
-
87
- const dismiss: FABModalDismissFunc = (onDismiss) => {
88
- if (rootSiblings) {
89
- const cleanup = () => {
90
- rootSiblings?.destroy();
91
- rootSiblings = null;
92
- ref = null;
93
- onDismiss?.();
94
- };
95
-
96
- if (ref) {
97
- ref.animatedOut(cleanup);
98
- } else {
99
- cleanup();
100
- }
101
- }
102
- };
103
-
104
- const update: FABModalUpdateFunc = (newContent) => {
105
- rootSiblings?.update(
106
- <FABModalPresenter
107
- ref={(_ref) => {
108
- ref = _ref;
109
- }}
110
- >
111
- {newContent}
112
- </FABModalPresenter>
113
- );
114
- };
115
-
116
- rootSiblings = new RootSiblings(
117
- (
118
- <FABModalPresenter
119
- ref={(_ref) => {
120
- ref = _ref;
121
- }}
122
- >
123
- {content}
124
- </FABModalPresenter>
125
- )
126
- );
127
-
128
- return { dismiss, update };
129
- };
130
-
131
- FABModalPresenter.displayName = 'FABModalPresenter';
132
-
133
- export default FABModalPresenter;
@@ -1,13 +0,0 @@
1
- import {
2
- FABModalDismissFunc,
3
- FABModalHandler,
4
- showFABModal,
5
- ModalPresenterHandles,
6
- } from './ModalPresenter';
7
-
8
- export type {
9
- FABModalDismissFunc as ModalDismissFunc,
10
- FABModalHandler as ModalHandler,
11
- ModalPresenterHandles,
12
- };
13
- export { showFABModal };