@pagopa/io-app-design-system 1.17.1 → 1.17.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.
Files changed (51) hide show
  1. package/lib/commonjs/components/buttons/ButtonLink.js +14 -0
  2. package/lib/commonjs/components/buttons/ButtonLink.js.map +1 -1
  3. package/lib/commonjs/components/common/ScaleInOutAnimation.js +69 -0
  4. package/lib/commonjs/components/common/ScaleInOutAnimation.js.map +1 -0
  5. package/lib/commonjs/components/layout/ForceScrollDownView.js +161 -0
  6. package/lib/commonjs/components/layout/ForceScrollDownView.js.map +1 -0
  7. package/lib/commonjs/components/layout/HeaderFirstLevel.js +4 -4
  8. package/lib/commonjs/components/layout/HeaderFirstLevel.js.map +1 -1
  9. package/lib/commonjs/components/layout/__test__/ForceScrollDownView.test.js +94 -0
  10. package/lib/commonjs/components/layout/__test__/ForceScrollDownView.test.js.map +1 -0
  11. package/lib/commonjs/components/layout/__test__/__snapshots__/ForceScrollDownView.test.tsx.snap +23 -0
  12. package/lib/commonjs/components/layout/index.js +11 -0
  13. package/lib/commonjs/components/layout/index.js.map +1 -1
  14. package/lib/commonjs/core/IOStyles.js +3 -1
  15. package/lib/commonjs/core/IOStyles.js.map +1 -1
  16. package/lib/module/components/buttons/ButtonLink.js +15 -1
  17. package/lib/module/components/buttons/ButtonLink.js.map +1 -1
  18. package/lib/module/components/common/ScaleInOutAnimation.js +59 -0
  19. package/lib/module/components/common/ScaleInOutAnimation.js.map +1 -0
  20. package/lib/module/components/layout/ForceScrollDownView.js +153 -0
  21. package/lib/module/components/layout/ForceScrollDownView.js.map +1 -0
  22. package/lib/module/components/layout/HeaderFirstLevel.js +4 -4
  23. package/lib/module/components/layout/HeaderFirstLevel.js.map +1 -1
  24. package/lib/module/components/layout/__test__/ForceScrollDownView.test.js +90 -0
  25. package/lib/module/components/layout/__test__/ForceScrollDownView.test.js.map +1 -0
  26. package/lib/module/components/layout/__test__/__snapshots__/ForceScrollDownView.test.tsx.snap +23 -0
  27. package/lib/module/components/layout/index.js +1 -0
  28. package/lib/module/components/layout/index.js.map +1 -1
  29. package/lib/module/core/IOStyles.js +3 -1
  30. package/lib/module/core/IOStyles.js.map +1 -1
  31. package/lib/typescript/components/buttons/ButtonLink.d.ts +1 -1
  32. package/lib/typescript/components/buttons/ButtonLink.d.ts.map +1 -1
  33. package/lib/typescript/components/common/ScaleInOutAnimation.d.ts +14 -0
  34. package/lib/typescript/components/common/ScaleInOutAnimation.d.ts.map +1 -0
  35. package/lib/typescript/components/layout/ForceScrollDownView.d.ts +27 -0
  36. package/lib/typescript/components/layout/ForceScrollDownView.d.ts.map +1 -0
  37. package/lib/typescript/components/layout/__test__/ForceScrollDownView.test.d.ts +2 -0
  38. package/lib/typescript/components/layout/__test__/ForceScrollDownView.test.d.ts.map +1 -0
  39. package/lib/typescript/components/layout/index.d.ts +1 -0
  40. package/lib/typescript/components/layout/index.d.ts.map +1 -1
  41. package/lib/typescript/core/IOStyles.d.ts +2 -0
  42. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  43. package/package.json +2 -1
  44. package/src/components/buttons/ButtonLink.tsx +17 -1
  45. package/src/components/common/ScaleInOutAnimation.tsx +68 -0
  46. package/src/components/layout/ForceScrollDownView.tsx +210 -0
  47. package/src/components/layout/HeaderFirstLevel.tsx +4 -4
  48. package/src/components/layout/__test__/ForceScrollDownView.test.tsx +106 -0
  49. package/src/components/layout/__test__/__snapshots__/ForceScrollDownView.test.tsx.snap +23 -0
  50. package/src/components/layout/index.tsx +1 -0
  51. package/src/core/IOStyles.ts +5 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layout/index.tsx"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/layout/index.tsx"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
@@ -10,6 +10,8 @@ interface IOVisualCostants {
10
10
  avatarSizeSmall: number;
11
11
  avatarSizeMedium: number;
12
12
  iconContainedSizeDefault: number;
13
+ scrollDownButtonRight: number;
14
+ scrollDownButtonBottom: number;
13
15
  }
14
16
  export declare const IOVisualCostants: IOVisualCostants;
15
17
  export declare const IOStyles: {
@@ -1 +1 @@
1
- {"version":3,"file":"IOStyles.d.ts","sourceRoot":"","sources":["../../../src/core/IOStyles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,WAAW,EAGX,QAAQ,EACR,cAAc,EACf,MAAM,aAAa,CAAC;AAGrB;;GAEG;AAEH,UAAU,gBAAgB;IACxB,gBAAgB,EAAE,WAAW,CAAC;IAE9B,YAAY,EAAE,MAAM,CAAC;IAErB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wBAAwB,EAAE,MAAM,CAAC;CAClC;AAED,eAAO,MAAM,gBAAgB,EAAE,gBAM9B,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDnB,CAAC;AAeH,eAAO,MAAM,iBAAiB,EAAE,MAAuB,CAAC;AAGxD,eAAO,MAAM,gBAAgB,EAAE,MAAW,CAAC;AAE3C,eAAO,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AAEF,eAAO,MAAM,oBAAoB,EAAE,oBASlC,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,iCAI7C,CAAC;AAEJ,UAAU,+BAA+B;IACvC,eAAe,EAAE,cAAc,CAAC;IAChC,iBAAiB,EAAE,WAAW,CAAC;IAC/B,UAAU,EAAE,cAAc,CAAC;IAC3B,YAAY,EAAE,QAAQ,CAAC;IACvB,QAAQ,EAAE,eAAe,CAAC;IAC1B,iBAAiB,EAAE,QAAQ,CAAC;CAC7B;AAED,eAAO,MAAM,+BAA+B,EAAE,+BAQ3C,CAAC;AAEJ,eAAO,MAAM,yBAAyB;;;;;;;;;;;CAWpC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-app-design-system",
3
- "version": "1.17.1",
3
+ "version": "1.17.2",
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",
@@ -72,6 +72,7 @@
72
72
  "@svgr/core": "^8.1.0",
73
73
  "@svgr/plugin-jsx": "^8.1.0",
74
74
  "@svgr/plugin-svgo": "^8.1.0",
75
+ "@testing-library/react-native": "^12.4.0",
75
76
  "@types/jest": "^28.1.2",
76
77
  "@types/lodash": "^4.14.157",
77
78
  "@types/react": "~17.0.38",
@@ -15,6 +15,7 @@ import {
15
15
  IOColors,
16
16
  IOScaleValues,
17
17
  IOSpringValues,
18
+ hexToRgba,
18
19
  useIOExperimentalDesign
19
20
  } from "../../core";
20
21
  import { makeFontStyleObject } from "../../utils/fonts";
@@ -28,7 +29,8 @@ import {
28
29
  import { HSpacer } from "../spacer/Spacer";
29
30
  import { buttonTextFontSize } from "../typography";
30
31
 
31
- export type ColorButtonLink = "primary";
32
+ export type ColorButtonLink = "primary" | "contrast";
33
+
32
34
  export type ButtonLinkProps = WithTestID<{
33
35
  color?: ColorButtonLink;
34
36
  label: string;
@@ -62,6 +64,13 @@ const mapColorStates: Record<
62
64
  pressed: IOColors["blueIO-600"],
63
65
  disabled: IOColors["grey-700"]
64
66
  }
67
+ },
68
+ contrast: {
69
+ label: {
70
+ default: IOColors.white,
71
+ pressed: hexToRgba(IOColors.white, 0.85),
72
+ disabled: hexToRgba(IOColors.white, 0.5)
73
+ }
65
74
  }
66
75
  };
67
76
 
@@ -77,6 +86,13 @@ const mapLegacyColorStates: Record<
77
86
  pressed: IOColors["blue-600"],
78
87
  disabled: IOColors["grey-700"]
79
88
  }
89
+ },
90
+ contrast: {
91
+ label: {
92
+ default: IOColors.white,
93
+ pressed: hexToRgba(IOColors.white, 0.85),
94
+ disabled: hexToRgba(IOColors.white, 0.5)
95
+ }
80
96
  }
81
97
  };
82
98
 
@@ -0,0 +1,68 @@
1
+ /* eslint-disable functional/immutable-data */
2
+ import React from "react";
3
+ import { ViewStyle } from "react-native";
4
+ import Animated, {
5
+ LayoutAnimation,
6
+ WithSpringConfig,
7
+ withDelay,
8
+ withSpring,
9
+ withTiming
10
+ } from "react-native-reanimated";
11
+
12
+ type Props = {
13
+ visible?: boolean;
14
+ springConfig?: WithSpringConfig;
15
+ delayOut?: number;
16
+ delayIn?: number;
17
+ children: React.ReactNode;
18
+ style?: ViewStyle;
19
+ };
20
+
21
+ const ScaleInOutAnimation = ({
22
+ visible = true,
23
+ springConfig = { damping: 500, mass: 3, stiffness: 1000 },
24
+ delayOut = 0,
25
+ delayIn = 0,
26
+ children,
27
+ style
28
+ }: Props) => {
29
+ const enteringAnimation = (): LayoutAnimation => {
30
+ "worklet";
31
+ return {
32
+ initialValues: {
33
+ transform: [{ scale: 0 }]
34
+ },
35
+ animations: {
36
+ transform: [{ scale: withDelay(delayIn, withSpring(1, springConfig)) }]
37
+ }
38
+ };
39
+ };
40
+
41
+ const exitingAnimation = (): LayoutAnimation => {
42
+ "worklet";
43
+ return {
44
+ initialValues: {
45
+ transform: [{ scale: 1 }]
46
+ },
47
+ animations: {
48
+ transform: [{ scale: withDelay(delayOut, withTiming(0)) }]
49
+ }
50
+ };
51
+ };
52
+
53
+ if (!visible) {
54
+ return null;
55
+ }
56
+
57
+ return (
58
+ <Animated.View
59
+ style={style}
60
+ entering={enteringAnimation}
61
+ exiting={exitingAnimation}
62
+ >
63
+ {children}
64
+ </Animated.View>
65
+ );
66
+ };
67
+
68
+ export { ScaleInOutAnimation };
@@ -0,0 +1,210 @@
1
+ import React, {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState
7
+ } from "react";
8
+ import {
9
+ LayoutChangeEvent,
10
+ NativeScrollEvent,
11
+ NativeSyntheticEvent,
12
+ ScrollView,
13
+ ScrollViewProps,
14
+ StyleSheet
15
+ } from "react-native";
16
+ import { ScaleInOutAnimation } from "../common/ScaleInOutAnimation";
17
+ import { IOSpringValues, IOVisualCostants } from "../../core";
18
+ import { IconButtonSolid } from "../buttons";
19
+
20
+ type ForceScrollDownViewProps = {
21
+ /**
22
+ * The content to display inside the scroll view.
23
+ */
24
+ children: React.ReactNode;
25
+ /**
26
+ * The distance from the bottom of the scrollable content at which the "scroll to bottom" button
27
+ * should become hidden. Defaults to 100.
28
+ */
29
+ threshold?: number;
30
+ /**
31
+ * A callback that will be called whenever the scroll view crosses the threshold. The callback
32
+ * is passed a boolean indicating whether the threshold has been crossed (`true`) or not (`false`).
33
+ */
34
+ onThresholdCrossed?: (crossed: boolean) => void;
35
+ } & Pick<
36
+ ScrollViewProps,
37
+ "style" | "contentContainerStyle" | "scrollEnabled" | "testID"
38
+ >;
39
+
40
+ /**
41
+ * A React Native component that displays a scroll view with a button that scrolls to the bottom of the content
42
+ * when pressed. The button is hidden when the scroll view reaches a certain threshold from the bottom, which is
43
+ * configurable by the `threshold` prop. The button, and the scrolling, can also be disabled by setting the
44
+ * `scrollEnabled` prop to `false`.
45
+ */
46
+ const ForceScrollDownView = ({
47
+ children,
48
+ threshold = 100,
49
+ style,
50
+ contentContainerStyle,
51
+ scrollEnabled = true,
52
+ onThresholdCrossed
53
+ }: ForceScrollDownViewProps) => {
54
+ const scrollViewRef = useRef<ScrollView>(null);
55
+
56
+ /**
57
+ * The height of the scroll view, used to determine whether or not the scrollable content fits inside
58
+ * the scroll view and whether the "scroll to bottom" button should be displayed.
59
+ */
60
+ const [scrollViewHeight, setScrollViewHeight] = useState<number>();
61
+
62
+ /**
63
+ * The height of the scrollable content, used to determine whether or not the "scroll to bottom" button
64
+ * should be displayed.
65
+ */
66
+ const [contentHeight, setContentHeight] = useState<number>();
67
+
68
+ /**
69
+ * Whether or not the scroll view has crossed the threshold from the bottom.
70
+ */
71
+ const [isThresholdCrossed, setThresholdCrossed] = useState(false);
72
+
73
+ /**
74
+ * Whether or not the "scroll to bottom" button should be visible. This is controlled by the threshold
75
+ * and the current scroll position.
76
+ */
77
+ const [isButtonVisible, setButtonVisible] = useState(true);
78
+
79
+ /**
80
+ * A callback that is called whenever the scroll view is scrolled. It checks whether or not the
81
+ * scroll view has crossed the threshold from the bottom and updates the state accordingly.
82
+ * The callback is designed to updatr button visibility only when crossing the threshold.
83
+ */
84
+ const handleScroll = useCallback(
85
+ (event: NativeSyntheticEvent<NativeScrollEvent>) => {
86
+ const { layoutMeasurement, contentOffset, contentSize } =
87
+ event.nativeEvent;
88
+
89
+ const thresholdCrossed =
90
+ layoutMeasurement.height + contentOffset.y >=
91
+ contentSize.height - threshold;
92
+
93
+ setThresholdCrossed(previousState => {
94
+ if (!previousState && thresholdCrossed) {
95
+ setButtonVisible(false);
96
+ }
97
+ if (previousState && !thresholdCrossed) {
98
+ setButtonVisible(true);
99
+ }
100
+ return thresholdCrossed;
101
+ });
102
+ },
103
+ [threshold]
104
+ );
105
+
106
+ /**
107
+ * A side effect that calls the `onThresholdCrossed` callback whenever the value of `isThresholdCrossed` changes.
108
+ */
109
+ useEffect(() => {
110
+ onThresholdCrossed?.(isThresholdCrossed);
111
+ }, [onThresholdCrossed, isThresholdCrossed]);
112
+
113
+ /**
114
+ * A callback that is called whenever the size of the scrollable content changes. It updates the
115
+ * state with the new content height.
116
+ */
117
+ const handleContentSizeChange = useCallback(
118
+ (_contentWidth: number, contentHeight: number) => {
119
+ setContentHeight(contentHeight);
120
+ },
121
+ []
122
+ );
123
+
124
+ /**
125
+ * A callback that is called whenever the size of the scroll view changes. It updates the state
126
+ * with the new scroll view height.
127
+ */
128
+ const handleLayout = useCallback((event: LayoutChangeEvent) => {
129
+ setScrollViewHeight(event.nativeEvent.layout.height);
130
+ }, []);
131
+
132
+ /**
133
+ * A callback that is called when the "scroll to bottom" button is pressed. It scrolls the
134
+ * scroll view to the bottom and hides the button.
135
+ */
136
+ const handleScrollDownPress = useCallback(() => {
137
+ setButtonVisible(false);
138
+ scrollViewRef.current?.scrollToEnd();
139
+ }, [scrollViewRef]);
140
+
141
+ /**
142
+ * Whether or not the "scroll to bottom" button needs to be displayed. It is only displayed
143
+ * when the scrollable content cannot fit inside the scroll view and the button is enabled
144
+ * (`scrollEnabled` is `true`).
145
+ */
146
+ const needsScroll = useMemo(
147
+ () =>
148
+ scrollViewHeight != null &&
149
+ contentHeight != null &&
150
+ scrollViewHeight < contentHeight,
151
+ [scrollViewHeight, contentHeight]
152
+ );
153
+
154
+ /**
155
+ * Whether or not to render the "scroll to bottom" button. It is only rendered when the scroll view
156
+ * is enabled, needs to be scrolled, and the button is visible (`isButtonVisible` is `true`).
157
+ */
158
+ const shouldRenderScrollButton =
159
+ scrollEnabled && needsScroll && isButtonVisible;
160
+
161
+ /**
162
+ * The "scroll to bottom" button component. It is wrapped in a reanimated view and has enter and exit
163
+ * animations applied to it.
164
+ */
165
+ const scrollDownButton = (
166
+ <ScaleInOutAnimation
167
+ springConfig={IOSpringValues.button}
168
+ style={styles.scrollDownButton}
169
+ visible={shouldRenderScrollButton}
170
+ >
171
+ <IconButtonSolid
172
+ testID={"ScrollDownButton"}
173
+ accessibilityLabel="Scroll to bottom"
174
+ icon="arrowBottom"
175
+ onPress={handleScrollDownPress}
176
+ />
177
+ </ScaleInOutAnimation>
178
+ );
179
+
180
+ return (
181
+ <>
182
+ <ScrollView
183
+ testID={"ScrollView"}
184
+ ref={scrollViewRef}
185
+ scrollIndicatorInsets={{ right: 1 }}
186
+ scrollEnabled={scrollEnabled}
187
+ onScroll={handleScroll}
188
+ scrollEventThrottle={400}
189
+ style={style}
190
+ onLayout={handleLayout}
191
+ onContentSizeChange={handleContentSizeChange}
192
+ contentContainerStyle={contentContainerStyle}
193
+ >
194
+ {children}
195
+ </ScrollView>
196
+ {scrollDownButton}
197
+ </>
198
+ );
199
+ };
200
+
201
+ const styles = StyleSheet.create({
202
+ scrollDownButton: {
203
+ position: "absolute",
204
+ zIndex: 10,
205
+ right: IOVisualCostants.scrollDownButtonRight,
206
+ bottom: IOVisualCostants.scrollDownButtonBottom
207
+ }
208
+ });
209
+
210
+ export { ForceScrollDownView };
@@ -85,7 +85,7 @@ export const HeaderFirstLevel = ({
85
85
  <H3
86
86
  style={{ flexShrink: 1 }}
87
87
  numberOfLines={1}
88
- color={backgroundColor === "dark" ? "white" : undefined}
88
+ color={backgroundColor === "dark" ? "white" : "black"}
89
89
  >
90
90
  {title}
91
91
  </H3>
@@ -94,7 +94,7 @@ export const HeaderFirstLevel = ({
94
94
  <>
95
95
  <IconButton
96
96
  {...thirdAction}
97
- color={backgroundColor === "dark" ? "contrast" : "neutral"}
97
+ color={backgroundColor === "dark" ? "contrast" : "primary"}
98
98
  />
99
99
  {/* Ideally, with the "gap" flex property,
100
100
  we can get rid of these ugly constructs */}
@@ -105,7 +105,7 @@ export const HeaderFirstLevel = ({
105
105
  <>
106
106
  <IconButton
107
107
  {...secondAction}
108
- color={backgroundColor === "dark" ? "contrast" : "neutral"}
108
+ color={backgroundColor === "dark" ? "contrast" : "primary"}
109
109
  />
110
110
  {/* Same as above */}
111
111
  <HSpacer size={16} />
@@ -114,7 +114,7 @@ export const HeaderFirstLevel = ({
114
114
  {type !== "base" && (
115
115
  <IconButton
116
116
  {...firstAction}
117
- color={backgroundColor === "dark" ? "contrast" : "neutral"}
117
+ color={backgroundColor === "dark" ? "contrast" : "primary"}
118
118
  />
119
119
  )}
120
120
  </View>
@@ -0,0 +1,106 @@
1
+ /* eslint-disable functional/immutable-data */
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
+ import React from "react";
4
+ import { Text } from "react-native";
5
+ import { ForceScrollDownView } from "../ForceScrollDownView";
6
+
7
+ const tContent = "Some content";
8
+
9
+ describe("ForceScrollDownView", () => {
10
+ jest.useFakeTimers();
11
+
12
+ it("should match snapshot", () => {
13
+ const tChildren = <Text>{tContent}</Text>;
14
+
15
+ const component = render(
16
+ <ForceScrollDownView>{tChildren}</ForceScrollDownView>
17
+ );
18
+
19
+ expect(component).toMatchSnapshot();
20
+ });
21
+
22
+ it("renders the content correctly", () => {
23
+ const tChildren = <Text>{tContent}</Text>;
24
+
25
+ const { getByText } = render(
26
+ <ForceScrollDownView>{tChildren}</ForceScrollDownView>
27
+ );
28
+
29
+ expect(getByText(tContent)).toBeDefined();
30
+ });
31
+
32
+ it("displays the scroll down button when necessary", async () => {
33
+ const tChildren = <Text>{tContent}</Text>;
34
+
35
+ const tScreenHeight = 1000;
36
+
37
+ const { getByTestId, queryByTestId } = render(
38
+ <ForceScrollDownView>{tChildren}</ForceScrollDownView>
39
+ );
40
+
41
+ const scrollView = getByTestId("ScrollView");
42
+
43
+ // Update scroll view height
44
+ fireEvent(scrollView, "layout", {
45
+ nativeEvent: {
46
+ layout: {
47
+ height: tScreenHeight
48
+ }
49
+ }
50
+ });
51
+
52
+ // Update scroll view content height
53
+ fireEvent(scrollView, "contentSizeChange", null, tScreenHeight - 500);
54
+
55
+ // Button should not be visible because content does not need scrolling
56
+ const buttonBefore = queryByTestId("ScrollDownButton");
57
+ expect(buttonBefore).toBeNull();
58
+
59
+ // Increase content height to force button to be shown
60
+ fireEvent(scrollView, "contentSizeChange", null, tScreenHeight + 500);
61
+
62
+ jest.advanceTimersByTime(500);
63
+
64
+ // Button should be visible now beacuse content needs scrolling
65
+ const buttonAfter = queryByTestId("ScrollDownButton");
66
+ expect(buttonAfter).not.toBeNull();
67
+ });
68
+
69
+ it("scrolls to the bottom when the button is pressed", () => {
70
+ const tChildren = <Text>{tContent}</Text>;
71
+
72
+ const tScreenHeight = 1000;
73
+
74
+ const { getByTestId, queryByTestId } = render(
75
+ <ForceScrollDownView>{tChildren}</ForceScrollDownView>
76
+ );
77
+
78
+ const scrollView = getByTestId("ScrollView");
79
+
80
+ // Update scroll view height
81
+ fireEvent(scrollView, "layout", {
82
+ nativeEvent: {
83
+ layout: {
84
+ height: tScreenHeight
85
+ }
86
+ }
87
+ });
88
+
89
+ // Update scroll view content height
90
+ fireEvent(scrollView, "contentSizeChange", null, tScreenHeight + 500);
91
+
92
+ // Button should be visible
93
+ const buttonBefore = getByTestId("ScrollDownButton");
94
+ expect(buttonBefore).not.toBeNull();
95
+
96
+ // Fire button press event
97
+ fireEvent.press(buttonBefore);
98
+
99
+ // Wait for the scroll animation
100
+ jest.advanceTimersByTime(500);
101
+
102
+ // Button should not be visible after scrolling
103
+ const buttonAfter = queryByTestId("ScrollDownButton");
104
+ expect(buttonAfter).toBeNull();
105
+ });
106
+ });
@@ -0,0 +1,23 @@
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={400}
10
+ scrollIndicatorInsets={
11
+ {
12
+ "right": 1,
13
+ }
14
+ }
15
+ testID="ScrollView"
16
+ >
17
+ <View>
18
+ <Text>
19
+ Some content
20
+ </Text>
21
+ </View>
22
+ </RCTScrollView>
23
+ `;
@@ -3,5 +3,6 @@ export * from "./GradientScrollView";
3
3
  export * from "./GradientBottomActions";
4
4
  export * from "./HeaderFirstLevel";
5
5
  export * from "./HeaderSecondLevel";
6
+ export * from "./ForceScrollDownView";
6
7
  export * from "./FooterWithButtons";
7
8
  export * from "./BlockButtons";
@@ -22,6 +22,8 @@ interface IOVisualCostants {
22
22
  avatarSizeSmall: number;
23
23
  avatarSizeMedium: number;
24
24
  iconContainedSizeDefault: number;
25
+ scrollDownButtonRight: number;
26
+ scrollDownButtonBottom: number;
25
27
  }
26
28
 
27
29
  export const IOVisualCostants: IOVisualCostants = {
@@ -29,7 +31,9 @@ export const IOVisualCostants: IOVisualCostants = {
29
31
  headerHeight: 56,
30
32
  avatarSizeSmall: 44,
31
33
  avatarSizeMedium: 66,
32
- iconContainedSizeDefault: 44
34
+ iconContainedSizeDefault: 44,
35
+ scrollDownButtonRight: 24,
36
+ scrollDownButtonBottom: 24
33
37
  };
34
38
 
35
39
  export const IOStyles = StyleSheet.create({