@pagopa/io-app-design-system 5.11.11 → 5.11.13-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.
Files changed (24) hide show
  1. package/lib/commonjs/components/templates/ForceScrollDownView.js +43 -73
  2. package/lib/commonjs/components/templates/ForceScrollDownView.js.map +1 -1
  3. package/lib/commonjs/components/toast/ToastProvider.js +5 -1
  4. package/lib/commonjs/components/toast/ToastProvider.js.map +1 -1
  5. package/lib/module/components/templates/ForceScrollDownView.js +45 -75
  6. package/lib/module/components/templates/ForceScrollDownView.js.map +1 -1
  7. package/lib/module/components/toast/ToastProvider.js +6 -2
  8. package/lib/module/components/toast/ToastProvider.js.map +1 -1
  9. package/lib/typescript/components/templates/ForceScrollDownView.d.ts +7 -1
  10. package/lib/typescript/components/templates/ForceScrollDownView.d.ts.map +1 -1
  11. package/lib/typescript/components/toast/ToastProvider.d.ts.map +1 -1
  12. package/package.json +1 -1
  13. package/src/components/templates/ForceScrollDownView.tsx +72 -104
  14. package/src/components/toast/ToastProvider.tsx +13 -1
  15. package/lib/commonjs/components/templates/__test__/ForceScrollDownView.test.js +0 -115
  16. package/lib/commonjs/components/templates/__test__/ForceScrollDownView.test.js.map +0 -1
  17. package/lib/commonjs/components/templates/__test__/__snapshots__/ForceScrollDownView.test.tsx.snap +0 -18
  18. package/lib/module/components/templates/__test__/ForceScrollDownView.test.js +0 -113
  19. package/lib/module/components/templates/__test__/ForceScrollDownView.test.js.map +0 -1
  20. package/lib/module/components/templates/__test__/__snapshots__/ForceScrollDownView.test.tsx.snap +0 -18
  21. package/lib/typescript/components/templates/__test__/ForceScrollDownView.test.d.ts +0 -2
  22. package/lib/typescript/components/templates/__test__/ForceScrollDownView.test.d.ts.map +0 -1
  23. package/src/components/templates/__test__/ForceScrollDownView.test.tsx +0 -106
  24. package/src/components/templates/__test__/__snapshots__/ForceScrollDownView.test.tsx.snap +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-app-design-system",
3
- "version": "5.11.11",
3
+ "version": "5.11.13-0",
4
4
  "description": "The library defining the core components of the design system of @pagopa/io-app",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,23 +1,20 @@
1
- import React, {
2
- ComponentProps,
3
- ReactNode,
4
- useCallback,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- useState
9
- } from "react";
10
- import {
11
- LayoutChangeEvent,
12
- NativeScrollEvent,
13
- NativeSyntheticEvent,
14
- ScrollView,
15
- ScrollViewProps,
16
- StyleSheet
17
- } from "react-native";
1
+ import React, { ComponentProps, ReactNode, useCallback } from "react";
2
+ import { LayoutChangeEvent, ScrollViewProps, StyleSheet } from "react-native";
3
+ import Animated, {
4
+ AnimatedRef,
5
+ interpolate,
6
+ runOnJS,
7
+ runOnUI,
8
+ scrollTo,
9
+ useAnimatedReaction,
10
+ useAnimatedRef,
11
+ useAnimatedStyle,
12
+ useScrollViewOffset,
13
+ useSharedValue,
14
+ withSpring
15
+ } from "react-native-reanimated";
18
16
  import { IOSpringValues, IOVisualCostants } from "../../core";
19
17
  import { IconButtonSolid } from "../buttons";
20
- import { ScaleInOutAnimation } from "../common/ScaleInOutAnimation";
21
18
  import { FooterActions, useFooterActionsInlineMeasurements } from "../layout";
22
19
 
23
20
  type ForceScrollDownViewActions = {
@@ -54,6 +51,11 @@ export type ForceScrollDownView = {
54
51
  * is passed a boolean indicating whether the threshold has been crossed (`true`) or not (`false`).
55
52
  */
56
53
  onThresholdCrossed?: (crossed: boolean) => void;
54
+ /**
55
+ * Optional Animated ref to be used with `useScrollViewOffset`
56
+ * (outside this component)
57
+ */
58
+ animatedRef?: AnimatedRef<Animated.ScrollView>;
57
59
  } & ForceScrollDownViewSlot &
58
60
  Pick<
59
61
  ScrollViewProps,
@@ -73,9 +75,11 @@ const ForceScrollDownView = ({
73
75
  style,
74
76
  contentContainerStyle,
75
77
  scrollEnabled = true,
76
- onThresholdCrossed
78
+ onThresholdCrossed,
79
+ animatedRef
77
80
  }: ForceScrollDownView) => {
78
- const scrollViewRef = useRef<ScrollView>(null);
81
+ const internalAnimatedRef = useAnimatedRef<Animated.ScrollView>();
82
+ const scrollViewRef = animatedRef ?? internalAnimatedRef;
79
83
 
80
84
  const {
81
85
  footerActionsInlineMeasurements,
@@ -86,134 +90,98 @@ const ForceScrollDownView = ({
86
90
  ? footerActionsInlineMeasurements.safeBottomAreaHeight
87
91
  : customThreshold;
88
92
 
89
- /**
90
- * The height of the scroll view, used to determine whether or not the scrollable content fits inside
91
- * the scroll view and whether the "scroll to bottom" button should be displayed.
92
- */
93
- const [scrollViewHeight, setScrollViewHeight] = useState<number>(0);
94
-
95
- /**
96
- * The height of the scrollable content, used to determine whether or not the "scroll to bottom" button
97
- * should be displayed.
98
- */
99
- const [contentHeight, setContentHeight] = useState<number>(0);
100
-
101
- /**
102
- * Whether or not the scroll view has crossed the threshold from the bottom.
103
- */
104
- const [isThresholdCrossed, setThresholdCrossed] = useState(false);
105
-
106
93
  /**
107
94
  * Whether or not the "scroll to bottom" button should be visible. This is controlled by the threshold
108
95
  * and the current scroll position.
109
96
  */
110
- const [isButtonVisible, setButtonVisible] = useState(true);
97
+ // const [isButtonVisible, setButtonVisible] = useState(true);
111
98
 
112
- /**
113
- * A callback that is called whenever the scroll view is scrolled. It checks whether or not the
114
- * scroll view has crossed the threshold from the bottom and updates the state accordingly.
115
- * The callback is designed to update button visibility only when crossing the threshold.
116
- */
117
- const handleScroll = useCallback(
118
- (event: NativeSyntheticEvent<NativeScrollEvent>) => {
119
- const { layoutMeasurement, contentOffset, contentSize } =
120
- event.nativeEvent;
121
-
122
- const thresholdCrossed =
123
- layoutMeasurement.height + contentOffset.y >=
124
- contentSize.height - (threshold ?? 0);
125
-
126
- if (isThresholdCrossed !== thresholdCrossed) {
127
- setThresholdCrossed(thresholdCrossed);
128
- setButtonVisible(!thresholdCrossed);
99
+ const isButtonVisible = useSharedValue(1);
100
+ const scrollViewHeight = useSharedValue(0);
101
+ const contentHeight = useSharedValue(0);
102
+ const offsetY = useScrollViewOffset(scrollViewRef);
103
+
104
+ useAnimatedReaction(
105
+ () =>
106
+ scrollViewHeight.value + Math.max(offsetY.value, 0) >=
107
+ contentHeight.value - (threshold ?? 0),
108
+ (crossed, previous) => {
109
+ if (crossed !== previous) {
110
+ // eslint-disable-next-line functional/immutable-data
111
+ isButtonVisible.value = withSpring(
112
+ crossed && scrollEnabled ? 0 : 1,
113
+ IOSpringValues.button
114
+ );
115
+ if (onThresholdCrossed) {
116
+ runOnJS(onThresholdCrossed)(crossed);
117
+ }
129
118
  }
130
- },
131
- [threshold, isThresholdCrossed]
119
+ }
132
120
  );
133
121
 
134
- /**
135
- * A side effect that calls the `onThresholdCrossed` callback whenever the value of `isThresholdCrossed` changes.
136
- */
137
- useEffect(() => {
138
- onThresholdCrossed?.(isThresholdCrossed);
139
- }, [onThresholdCrossed, isThresholdCrossed]);
140
-
141
122
  /**
142
123
  * A callback that is called whenever the size of the scrollable content changes. It updates the
143
124
  * state with the new content height.
144
125
  */
145
126
  const handleContentSizeChange = useCallback(
146
- (_contentWidth: number, contentHeight: number) => {
147
- setContentHeight(contentHeight);
148
- },
149
- []
127
+ // eslint-disable-next-line functional/immutable-data
128
+ (_w: number, h: number) => (contentHeight.value = h),
129
+ [contentHeight]
150
130
  );
151
131
 
152
132
  /**
153
133
  * A callback that is called whenever the size of the scroll view changes. It updates the state
154
134
  * with the new scroll view height.
155
135
  */
156
- const handleLayout = useCallback((event: LayoutChangeEvent) => {
157
- setScrollViewHeight(event.nativeEvent.layout.height);
158
- }, []);
136
+ const handleLayout = useCallback(
137
+ (event: LayoutChangeEvent) =>
138
+ // eslint-disable-next-line functional/immutable-data
139
+ (scrollViewHeight.value = event.nativeEvent.layout.height),
140
+ [scrollViewHeight]
141
+ );
159
142
 
160
143
  /**
161
144
  * A callback that is called when the "scroll to bottom" button is pressed. It scrolls the
162
145
  * scroll view to the bottom and hides the button.
163
146
  */
164
147
  const handleScrollDownPress = useCallback(() => {
165
- setButtonVisible(false);
166
- scrollViewRef.current?.scrollToEnd();
167
- }, [scrollViewRef]);
148
+ runOnUI(() => {
149
+ "worklet";
150
+ // eslint-disable-next-line functional/immutable-data
151
+ isButtonVisible.value = withSpring(0, IOSpringValues.button);
152
+ const targetY = Math.max(0, contentHeight.value - scrollViewHeight.value);
153
+ scrollTo(scrollViewRef, 0, targetY, true);
154
+ })();
155
+ }, [scrollViewRef, contentHeight, scrollViewHeight, isButtonVisible]);
168
156
 
169
157
  /**
170
- * Whether or not the "scroll to bottom" button needs to be displayed. It is only displayed
171
- * when the scrollable content cannot fit inside the scroll view and the button is enabled
172
- * (`scrollEnabled` is `true`).
158
+ * The "scroll to bottom" button component. It is wrapped in a reanimated View
159
+ * and has animated style applied to it.
173
160
  */
174
- const needsScroll = useMemo(
175
- () =>
176
- scrollViewHeight > 0 &&
177
- contentHeight > 0 &&
178
- scrollViewHeight < contentHeight,
179
- [scrollViewHeight, contentHeight]
180
- );
181
161
 
182
- /**
183
- * Whether or not to render the "scroll to bottom" button. It is only rendered when the scroll view
184
- * is enabled, needs to be scrolled, and the button is visible (`isButtonVisible` is `true`).
185
- */
186
- const shouldRenderScrollButton =
187
- scrollEnabled && needsScroll && isButtonVisible;
162
+ const buttonTransitionStyle = useAnimatedStyle(() => ({
163
+ opacity: isButtonVisible.value,
164
+ transform: [{ scale: interpolate(isButtonVisible.value, [0, 1], [0.5, 1]) }]
165
+ }));
188
166
 
189
- /**
190
- * The "scroll to bottom" button component. It is wrapped in a reanimated view and has enter and exit
191
- * animations applied to it.
192
- */
193
167
  const scrollDownButton = (
194
- <ScaleInOutAnimation
195
- springConfig={IOSpringValues.button}
196
- style={styles.scrollDownButton}
197
- visible={shouldRenderScrollButton}
198
- >
168
+ <Animated.View style={[styles.scrollDownButton, buttonTransitionStyle]}>
199
169
  <IconButtonSolid
200
170
  testID={"ScrollDownButton"}
201
171
  accessibilityLabel="Scroll to bottom"
202
172
  icon="arrowBottom"
203
173
  onPress={handleScrollDownPress}
204
174
  />
205
- </ScaleInOutAnimation>
175
+ </Animated.View>
206
176
  );
207
177
 
208
178
  return (
209
179
  <>
210
- <ScrollView
180
+ <Animated.ScrollView
211
181
  testID={"ScrollView"}
212
182
  ref={scrollViewRef}
213
183
  scrollEnabled={scrollEnabled}
214
184
  style={style}
215
- onScroll={handleScroll}
216
- scrollEventThrottle={8}
217
185
  onLayout={handleLayout}
218
186
  onContentSizeChange={handleContentSizeChange}
219
187
  contentContainerStyle={contentContainerStyle}
@@ -226,7 +194,7 @@ const ForceScrollDownView = ({
226
194
  fixed={false}
227
195
  />
228
196
  )}
229
- </ScrollView>
197
+ </Animated.ScrollView>
230
198
  {scrollDownButton}
231
199
  </>
232
200
  );
@@ -2,6 +2,7 @@ import { throttle } from "lodash";
2
2
  import React from "react";
3
3
  import {
4
4
  AccessibilityInfo,
5
+ Platform,
5
6
  SafeAreaView,
6
7
  StyleSheet,
7
8
  View
@@ -12,6 +13,7 @@ import Animated, {
12
13
  SlideInUp,
13
14
  SlideOutUp
14
15
  } from "react-native-reanimated";
16
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
15
17
  import { IOVisualCostants } from "../../core";
16
18
  import { triggerHaptic } from "../../functions";
17
19
  import { Dismissable } from "../templates";
@@ -116,10 +118,20 @@ export const ToastProvider = ({ children }: ToastProviderProps) => {
116
118
  [addToast, removeToast, removeAllToasts]
117
119
  );
118
120
 
121
+ const insets = useSafeAreaInsets();
122
+
119
123
  return (
120
124
  <ToastContext.Provider value={contextValue as ToastContext}>
121
125
  <InitializeToastRef />
122
- <SafeAreaView style={styles.container} pointerEvents="box-none">
126
+ <SafeAreaView
127
+ style={[
128
+ styles.container,
129
+ {
130
+ paddingTop: Platform.OS === "android" ? insets.top : 0
131
+ }
132
+ ]}
133
+ pointerEvents="box-none"
134
+ >
123
135
  <View
124
136
  style={{ padding: IOVisualCostants.appMarginDefault }}
125
137
  pointerEvents="box-none"
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- var _reactNative = require("@testing-library/react-native");
4
- var _react = _interopRequireDefault(require("react"));
5
- var _reactNative2 = require("react-native");
6
- var _ForceScrollDownView = require("../ForceScrollDownView");
7
- var _jsxRuntime = require("react/jsx-runtime");
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /* eslint-disable functional/immutable-data */
10
-
11
- const tContent = "Some content";
12
- describe("ForceScrollDownView", () => {
13
- jest.useFakeTimers();
14
- it("should match snapshot", () => {
15
- const tChildren = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative2.Text, {
16
- children: tContent
17
- });
18
- const component = (0, _reactNative.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_ForceScrollDownView.ForceScrollDownView, {
19
- threshold: 100,
20
- children: tChildren
21
- }));
22
- expect(component).toMatchSnapshot();
23
- });
24
- it("renders the content correctly", () => {
25
- const tChildren = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative2.Text, {
26
- children: tContent
27
- });
28
- const {
29
- getByText
30
- } = (0, _reactNative.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_ForceScrollDownView.ForceScrollDownView, {
31
- threshold: 100,
32
- children: tChildren
33
- }));
34
- expect(getByText(tContent)).toBeDefined();
35
- });
36
- it("displays the scroll down button when necessary", async () => {
37
- const tChildren = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative2.Text, {
38
- children: tContent
39
- });
40
- const tScreenHeight = 1000;
41
- const {
42
- getByTestId,
43
- queryByTestId
44
- } = (0, _reactNative.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_ForceScrollDownView.ForceScrollDownView, {
45
- threshold: 100,
46
- children: tChildren
47
- }));
48
- const scrollView = getByTestId("ScrollView");
49
-
50
- // Update scroll view height
51
- (0, _reactNative.fireEvent)(scrollView, "layout", {
52
- nativeEvent: {
53
- layout: {
54
- height: tScreenHeight
55
- }
56
- }
57
- });
58
-
59
- // Update scroll view content height
60
- (0, _reactNative.fireEvent)(scrollView, "contentSizeChange", null, tScreenHeight - 500);
61
-
62
- // Button should not be visible because content does not need scrolling
63
- const buttonBefore = queryByTestId("ScrollDownButton");
64
- expect(buttonBefore).toBeNull();
65
-
66
- // Increase content height to force button to be shown
67
- (0, _reactNative.fireEvent)(scrollView, "contentSizeChange", null, tScreenHeight + 500);
68
- jest.advanceTimersByTime(500);
69
-
70
- // Button should be visible now beacuse content needs scrolling
71
- const buttonAfter = queryByTestId("ScrollDownButton");
72
- expect(buttonAfter).not.toBeNull();
73
- });
74
- it("scrolls to the bottom when the button is pressed", () => {
75
- const tChildren = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative2.Text, {
76
- children: tContent
77
- });
78
- const tScreenHeight = 1000;
79
- const {
80
- getByTestId,
81
- queryByTestId
82
- } = (0, _reactNative.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_ForceScrollDownView.ForceScrollDownView, {
83
- threshold: 100,
84
- children: tChildren
85
- }));
86
- const scrollView = getByTestId("ScrollView");
87
-
88
- // Update scroll view height
89
- (0, _reactNative.fireEvent)(scrollView, "layout", {
90
- nativeEvent: {
91
- layout: {
92
- height: tScreenHeight
93
- }
94
- }
95
- });
96
-
97
- // Update scroll view content height
98
- (0, _reactNative.fireEvent)(scrollView, "contentSizeChange", null, tScreenHeight + 500);
99
-
100
- // Button should be visible
101
- const buttonBefore = getByTestId("ScrollDownButton");
102
- expect(buttonBefore).not.toBeNull();
103
-
104
- // Fire button press event
105
- _reactNative.fireEvent.press(buttonBefore);
106
-
107
- // Wait for the scroll animation
108
- jest.advanceTimersByTime(500);
109
-
110
- // Button should not be visible after scrolling
111
- const buttonAfter = queryByTestId("ScrollDownButton");
112
- expect(buttonAfter).toBeNull();
113
- });
114
- });
115
- //# sourceMappingURL=ForceScrollDownView.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_react","_interopRequireDefault","_reactNative2","_ForceScrollDownView","_jsxRuntime","e","__esModule","default","tContent","describe","jest","useFakeTimers","it","tChildren","jsx","Text","children","component","render","ForceScrollDownView","threshold","expect","toMatchSnapshot","getByText","toBeDefined","tScreenHeight","getByTestId","queryByTestId","scrollView","fireEvent","nativeEvent","layout","height","buttonBefore","toBeNull","advanceTimersByTime","buttonAfter","not","press"],"sourceRoot":"../../../../../src","sources":["components/templates/__test__/ForceScrollDownView.test.tsx"],"mappings":";;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,oBAAA,GAAAJ,OAAA;AAA6D,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAE,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAJ7D;;AAMA,MAAMG,QAAQ,GAAG,cAAc;AAE/BC,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpCC,IAAI,CAACC,aAAa,CAAC,CAAC;EAEpBC,EAAE,CAAC,uBAAuB,EAAE,MAAM;IAChC,MAAMC,SAAS,gBAAG,IAAAT,WAAA,CAAAU,GAAA,EAACZ,aAAA,CAAAa,IAAI;MAAAC,QAAA,EAAER;IAAQ,CAAO,CAAC;IAEzC,MAAMS,SAAS,GAAG,IAAAC,mBAAM,eACtB,IAAAd,WAAA,CAAAU,GAAA,EAACX,oBAAA,CAAAgB,mBAAmB;MAACC,SAAS,EAAE,GAAI;MAAAJ,QAAA,EAAEH;IAAS,CAAsB,CACvE,CAAC;IAEDQ,MAAM,CAACJ,SAAS,CAAC,CAACK,eAAe,CAAC,CAAC;EACrC,CAAC,CAAC;EAEFV,EAAE,CAAC,+BAA+B,EAAE,MAAM;IACxC,MAAMC,SAAS,gBAAG,IAAAT,WAAA,CAAAU,GAAA,EAACZ,aAAA,CAAAa,IAAI;MAAAC,QAAA,EAAER;IAAQ,CAAO,CAAC;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1,18 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`ForceScrollDownView should match snapshot 1`] = `
4
- <RCTScrollView
5
- onContentSizeChange={[Function]}
6
- onLayout={[Function]}
7
- onScroll={[Function]}
8
- scrollEnabled={true}
9
- scrollEventThrottle={8}
10
- testID="ScrollView"
11
- >
12
- <View>
13
- <Text>
14
- Some content
15
- </Text>
16
- </View>
17
- </RCTScrollView>
18
- `;
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable functional/immutable-data */
4
- import { fireEvent, render } from "@testing-library/react-native";
5
- import React from "react";
6
- import { Text } from "react-native";
7
- import { ForceScrollDownView } from "../ForceScrollDownView";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- const tContent = "Some content";
10
- describe("ForceScrollDownView", () => {
11
- jest.useFakeTimers();
12
- it("should match snapshot", () => {
13
- const tChildren = /*#__PURE__*/_jsx(Text, {
14
- children: tContent
15
- });
16
- const component = render(/*#__PURE__*/_jsx(ForceScrollDownView, {
17
- threshold: 100,
18
- children: tChildren
19
- }));
20
- expect(component).toMatchSnapshot();
21
- });
22
- it("renders the content correctly", () => {
23
- const tChildren = /*#__PURE__*/_jsx(Text, {
24
- children: tContent
25
- });
26
- const {
27
- getByText
28
- } = render(/*#__PURE__*/_jsx(ForceScrollDownView, {
29
- threshold: 100,
30
- children: tChildren
31
- }));
32
- expect(getByText(tContent)).toBeDefined();
33
- });
34
- it("displays the scroll down button when necessary", async () => {
35
- const tChildren = /*#__PURE__*/_jsx(Text, {
36
- children: tContent
37
- });
38
- const tScreenHeight = 1000;
39
- const {
40
- getByTestId,
41
- queryByTestId
42
- } = render(/*#__PURE__*/_jsx(ForceScrollDownView, {
43
- threshold: 100,
44
- children: tChildren
45
- }));
46
- const scrollView = getByTestId("ScrollView");
47
-
48
- // Update scroll view height
49
- fireEvent(scrollView, "layout", {
50
- nativeEvent: {
51
- layout: {
52
- height: tScreenHeight
53
- }
54
- }
55
- });
56
-
57
- // Update scroll view content height
58
- fireEvent(scrollView, "contentSizeChange", null, tScreenHeight - 500);
59
-
60
- // Button should not be visible because content does not need scrolling
61
- const buttonBefore = queryByTestId("ScrollDownButton");
62
- expect(buttonBefore).toBeNull();
63
-
64
- // Increase content height to force button to be shown
65
- fireEvent(scrollView, "contentSizeChange", null, tScreenHeight + 500);
66
- jest.advanceTimersByTime(500);
67
-
68
- // Button should be visible now beacuse content needs scrolling
69
- const buttonAfter = queryByTestId("ScrollDownButton");
70
- expect(buttonAfter).not.toBeNull();
71
- });
72
- it("scrolls to the bottom when the button is pressed", () => {
73
- const tChildren = /*#__PURE__*/_jsx(Text, {
74
- children: tContent
75
- });
76
- const tScreenHeight = 1000;
77
- const {
78
- getByTestId,
79
- queryByTestId
80
- } = render(/*#__PURE__*/_jsx(ForceScrollDownView, {
81
- threshold: 100,
82
- children: tChildren
83
- }));
84
- const scrollView = getByTestId("ScrollView");
85
-
86
- // Update scroll view height
87
- fireEvent(scrollView, "layout", {
88
- nativeEvent: {
89
- layout: {
90
- height: tScreenHeight
91
- }
92
- }
93
- });
94
-
95
- // Update scroll view content height
96
- fireEvent(scrollView, "contentSizeChange", null, tScreenHeight + 500);
97
-
98
- // Button should be visible
99
- const buttonBefore = getByTestId("ScrollDownButton");
100
- expect(buttonBefore).not.toBeNull();
101
-
102
- // Fire button press event
103
- fireEvent.press(buttonBefore);
104
-
105
- // Wait for the scroll animation
106
- jest.advanceTimersByTime(500);
107
-
108
- // Button should not be visible after scrolling
109
- const buttonAfter = queryByTestId("ScrollDownButton");
110
- expect(buttonAfter).toBeNull();
111
- });
112
- });
113
- //# sourceMappingURL=ForceScrollDownView.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["fireEvent","render","React","Text","ForceScrollDownView","jsx","_jsx","tContent","describe","jest","useFakeTimers","it","tChildren","children","component","threshold","expect","toMatchSnapshot","getByText","toBeDefined","tScreenHeight","getByTestId","queryByTestId","scrollView","nativeEvent","layout","height","buttonBefore","toBeNull","advanceTimersByTime","buttonAfter","not","press"],"sourceRoot":"../../../../../src","sources":["components/templates/__test__/ForceScrollDownView.test.tsx"],"mappings":";;AAAA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,+BAA+B;AACjE,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,mBAAmB,QAAQ,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE7D,MAAMC,QAAQ,GAAG,cAAc;AAE/BC,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpCC,IAAI,CAACC,aAAa,CAAC,CAAC;EAEpBC,EAAE,CAAC,uBAAuB,EAAE,MAAM;IAChC,MAAMC,SAAS,gBAAGN,IAAA,CAACH,IAAI;MAAAU,QAAA,EAAEN;IAAQ,CAAO,CAAC;IAEzC,MAAMO,SAAS,GAAGb,MAAM,cACtBK,IAAA,CAACF,mBAAmB;MAACW,SAAS,EAAE,GAAI;MAAAF,QAAA,EAAED;IAAS,CAAsB,CACvE,CAAC;IAEDI,MAAM,CAACF,SAAS,CAAC,CAACG,eAAe,CAAC,CAAC;EACrC,CAAC,CAAC;EAEFN,EAAE,CAAC,+BAA+B,EAAE,MAAM;IACxC,MAAMC,SAAS,gBAAGN,IAAA,CAACH,IAAI;MAAAU,QAAA,EAAEN;IAAQ,CAAO,CAAC;IAEzC,MAAM;MAAEW;IAAU,CAAC,GAAGjB,MAAM,cAC1BK,IAAA,CAACF,mBAAmB;MAACW,SAAS,EAAE,GAAI;MAAAF,QAAA,EAAED;IAAS,CAAsB,CACvE,CAAC;IAEDI,MAAM,CAACE,SAAS,CAACX,QAAQ,CAAC,CAAC,CAACY,WAAW,CAAC,CAAC;EAC3C,CAAC,CAAC;EAEFR,EAAE,CAAC,gDAAgD,EAAE,YAAY;IAC/D,MAAMC,SAAS,gBAAGN,IAAA,CAACH,IAAI;MAAAU,QAAA,EAAEN;IAAQ,CAAO,CAAC;IAEzC,MAAMa,a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B,SAAS,CAACuB,UAAU,EAAE,QAAQ,EAAE;MAC9BC,WAAW,EAAE;QACXC,MAAM,EAAE;UACNC,MAAM,EAAEN;QACV;MACF;IACF,CAAC,CAAC;;IAEF;IACApB,SAAS,CAACuB,UAAU,EAAE,mBAAmB,EAAE,IAAI,EAAEH,aAAa,GAAG,GAAG,CAAC;;IAErE;IACA,MAAMO,YAAY,GAAGN,WAAW,CAAC,kBAAkB,CAAC;IACpDL,MAAM,CAACW,YAAY,CAAC,CAACI,GAAG,CAACH,QAAQ,CAAC,CAAC;;IAEnC;IACA5B,SAAS,CAACgC,KAAK,CAACL,YAAY,CAAC;;IAE7B;IACAlB,IAAI,CAACoB,mBAAmB,CAAC,GAAG,CAAC;;IAE7B;IACA,MAAMC,WAAW,GAAGR,aAAa,CAAC,kBAAkB,CAAC;IACrDN,MAAM,CAACc,WAAW,CAAC,CAACF,QAAQ,CAAC,CAAC;EAChC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,18 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`ForceScrollDownView should match snapshot 1`] = `
4
- <RCTScrollView
5
- onContentSizeChange={[Function]}
6
- onLayout={[Function]}
7
- onScroll={[Function]}
8
- scrollEnabled={true}
9
- scrollEventThrottle={8}
10
- testID="ScrollView"
11
- >
12
- <View>
13
- <Text>
14
- Some content
15
- </Text>
16
- </View>
17
- </RCTScrollView>
18
- `;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ForceScrollDownView.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ForceScrollDownView.test.d.ts","sourceRoot":"","sources":["../../../../../src/components/templates/__test__/ForceScrollDownView.test.tsx"],"names":[],"mappings":""}