@hero-design/rn 8.35.0-alpha.0 → 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.0",
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
  }
@@ -14,7 +14,7 @@ import {
14
14
 
15
15
  import Box from '../../Box';
16
16
  import { FABHandles } from '../FAB';
17
- import FABModal from './FABModal';
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,8 +126,9 @@ 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
- <FABModal>
131
+ <Wrapper name={portalName}>
128
132
  <StyledContainer testID={testID} pointerEvents="box-none" style={style}>
129
133
  <StyledBackdrop
130
134
  pointerEvents={active ? 'auto' : 'box-none'}
@@ -160,17 +164,19 @@ const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
160
164
  </Box>
161
165
  </StyledActionGroupContainer>
162
166
 
163
- <StyledFAB
164
- testID="fab"
165
- icon={fabIcon}
166
- onPress={onPress}
167
- animated
168
- active={active}
169
- title={fabTitle}
170
- ref={fabRef}
171
- />
167
+ <Portal hostName="CustomPortalHost">
168
+ <StyledFAB
169
+ testID="fab"
170
+ icon={fabIcon}
171
+ onPress={onPress}
172
+ animated
173
+ active={active}
174
+ title={fabTitle}
175
+ ref={fabRef}
176
+ />
177
+ </Portal>
172
178
  </StyledContainer>
173
- </FABModal>
179
+ </Wrapper>
174
180
  );
175
181
  }
176
182
  );
@@ -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';
@@ -123,6 +124,7 @@ export {
123
124
  Rate,
124
125
  RefreshControl,
125
126
  RichTextEditor,
127
+ Portal,
126
128
  };
127
129
 
128
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,5 +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
- 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, };
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, };
51
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 };