@applicaster/zapp-react-native-ui-components 16.0.0-rc.42 → 16.0.0-rc.44

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.
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import { PanGestureHandler } from "react-native-gesture-handler";
3
+ import { View } from "react-native";
4
+ import { useBottomSheet } from "@applicaster/zapp-react-native-utils/bottomSheet";
5
+
6
+ /**
7
+ * Turns its children into a drag zone for the enclosing DraggableBottomSheet:
8
+ * dragging here moves/dismisses the sheet (used for the modal header bar).
9
+ * Outside a sheet (no context) it renders children unchanged.
10
+ */
11
+ export const BottomSheetDragArea = ({
12
+ children,
13
+ }: {
14
+ children: React.ReactElement;
15
+ }) => {
16
+ const sheet = useBottomSheet();
17
+
18
+ // Outside a sheet (no context) render children unchanged.
19
+ if (!sheet) return children;
20
+
21
+ return (
22
+ <PanGestureHandler
23
+ simultaneousHandlers={[sheet.masterDrawerRef]}
24
+ shouldCancelWhenOutside={false}
25
+ onGestureEvent={sheet.onDragGestureEvent}
26
+ onHandlerStateChange={sheet.onDragStateChange}
27
+ >
28
+ {/* Old-API PanGestureHandler needs a host-component child; children may
29
+ be a function component (e.g. ModalHeader), so wrap in a View. */}
30
+ <View>{children}</View>
31
+ </PanGestureHandler>
32
+ );
33
+ };
@@ -6,11 +6,11 @@ import { ItemProps } from "./Button/Item";
6
6
  import { ItemLabelProps } from "./Button/ItemLabel";
7
7
  import { getItemIconProps, getItemLabelProps, getItemProps } from "./utils";
8
8
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
9
-
10
9
  import type { PluginConfiguration } from "./";
11
10
 
12
11
  import { ModalHeader as DefaultModalHeader } from "./Header";
13
12
  import { useSafeAreaInsets } from "react-native-safe-area-context";
13
+ import { BottomSheetDragArea } from "./BottomSheetDragArea";
14
14
 
15
15
  type ModalComponentProps = {
16
16
  items: any[];
@@ -55,8 +55,7 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
55
55
  dismiss,
56
56
  summary,
57
57
  title,
58
- headerComponent: ModalHeader = DefaultModalHeader,
59
-
58
+ headerComponent = DefaultModalHeader,
60
59
  scrollViewContent = null,
61
60
 
62
61
  buttonComponent: ButtonComponent = Button,
@@ -72,6 +71,8 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
72
71
  const paddingTop = Number(theme.modal_bottom_sheet_padding_top);
73
72
  const paddingBottom = Number(theme.modal_bottom_sheet_padding_bottom);
74
73
 
74
+ const Header = headerComponent;
75
+
75
76
  useEffect(() => {
76
77
  if (currentRoute !== route.current) {
77
78
  props.dismiss();
@@ -107,13 +108,20 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
107
108
  paddingTop: paddingTop,
108
109
  }}
109
110
  >
110
- <ModalHeader
111
- dismiss={dismiss}
112
- configuration={theme}
113
- summary={summary}
114
- title={title}
115
- />
111
+ {Header ? (
112
+ <BottomSheetDragArea>
113
+ <Header
114
+ dismiss={dismiss}
115
+ configuration={theme}
116
+ summary={summary}
117
+ title={title}
118
+ />
119
+ </BottomSheetDragArea>
120
+ ) : null}
116
121
  <ScrollView
122
+ overScrollMode="never"
123
+ bounces={false}
124
+ showsVerticalScrollIndicator={false}
117
125
  contentContainerStyle={{
118
126
  paddingBottom: paddingBottom + bottomInset,
119
127
  }}
@@ -123,7 +131,6 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
123
131
  scrollViewContent.renderItem(item, index)
124
132
  )
125
133
  : null}
126
-
127
134
  {!scrollViewContent &&
128
135
  items.map((item, index) =>
129
136
  item ? (
@@ -0,0 +1,74 @@
1
+ import React from "react";
2
+ import { Text } from "react-native";
3
+ import { render, screen } from "@testing-library/react-native";
4
+ import { BottomSheetDragArea } from "../BottomSheetDragArea";
5
+ import { BottomSheetContext } from "@applicaster/zapp-react-native-utils/bottomSheet";
6
+
7
+ // Reveal PanGestureHandler and capture its props.
8
+ jest.mock("react-native-gesture-handler", () => {
9
+ const { View } = require("react-native");
10
+ const actual = jest.requireActual("react-native-gesture-handler");
11
+
12
+ return {
13
+ __esModule: true,
14
+ ...actual,
15
+ PanGestureHandler: ({
16
+ children,
17
+ onGestureEvent,
18
+ onHandlerStateChange,
19
+ simultaneousHandlers,
20
+ }: any) => (
21
+ <View
22
+ testID="drag-pan"
23
+ onGestureEvent={onGestureEvent}
24
+ onHandlerStateChange={onHandlerStateChange}
25
+ simultaneousHandlers={simultaneousHandlers}
26
+ >
27
+ {children}
28
+ </View>
29
+ ),
30
+ };
31
+ });
32
+
33
+ const makeValue = () => ({
34
+ scrollRef: React.createRef<any>(),
35
+ masterDrawerRef: React.createRef<any>(),
36
+ drawerRef: React.createRef<any>(),
37
+ onScroll: jest.fn(),
38
+ setBodyDragEnabled: jest.fn(),
39
+ onDragGestureEvent: jest.fn(),
40
+ onDragStateChange: jest.fn(),
41
+ });
42
+
43
+ describe("BottomSheetDragArea", () => {
44
+ it("wraps children in a sheet-wired PanGestureHandler when inside a sheet", () => {
45
+ const value = makeValue();
46
+
47
+ render(
48
+ <BottomSheetContext.Provider value={value}>
49
+ <BottomSheetDragArea>
50
+ <Text testID="child">hi</Text>
51
+ </BottomSheetDragArea>
52
+ </BottomSheetContext.Provider>
53
+ );
54
+
55
+ const pan = screen.getByTestId("drag-pan");
56
+ expect(pan.props.onGestureEvent).toBe(value.onDragGestureEvent);
57
+ expect(pan.props.onHandlerStateChange).toBe(value.onDragStateChange);
58
+
59
+ expect(pan.props.simultaneousHandlers).toEqual([value.masterDrawerRef]);
60
+
61
+ expect(screen.getByTestId("child")).toBeTruthy();
62
+ });
63
+
64
+ it("renders children bare when used outside a sheet", () => {
65
+ render(
66
+ <BottomSheetDragArea>
67
+ <Text testID="child">hi</Text>
68
+ </BottomSheetDragArea>
69
+ );
70
+
71
+ expect(screen.queryByTestId("drag-pan")).toBeNull();
72
+ expect(screen.getByTestId("child")).toBeTruthy();
73
+ });
74
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.42",
3
+ "version": "16.0.0-rc.44",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-rc.42",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.42",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.42",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.42",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.44",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.44",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.44",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.44",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",