@applicaster/zapp-react-native-ui-components 12.0.0-alpha.8235014824 → 12.0.0-alpha.8310462382

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 (31) hide show
  1. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +13 -6
  2. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +1 -1
  3. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +111 -34
  4. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +5 -3
  5. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -1
  6. package/Components/MasterCell/DefaultComponents/Text/index.tsx +14 -2
  7. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  8. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +1 -3
  9. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +1 -1
  10. package/Components/MeasurmentsPortal/BasicMeasurementsPortal.tsx +11 -7
  11. package/Components/MeasurmentsPortal/MeasurementsPortal.tsx +10 -1
  12. package/Components/PlayerContainer/PlayerContainer.tsx +9 -5
  13. package/Components/River/ComponentsMap/ComponentsMap.tsx +86 -22
  14. package/Components/River/RefreshControl.tsx +55 -1
  15. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +4 -0
  16. package/Components/Screen/index.tsx +35 -24
  17. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +0 -5
  18. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +11 -4
  19. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +9 -2
  20. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +13 -2
  21. package/Components/VideoModal/VideoModal.tsx +19 -19
  22. package/Components/Viewport/ViewportTracker/ViewportTracker.tsx +1 -1
  23. package/Components/Viewport/ViewportTracker/index.tsx +1 -0
  24. package/Components/Viewport/utils.js +1 -1
  25. package/Contexts/MenuToggleContext/{index.js → index.ts} +16 -0
  26. package/Contexts/ScreenContext/__tests__/__snapshots__/index.test.tsx.snap +3 -0
  27. package/Contexts/ScreenContext/__tests__/index.test.tsx +27 -0
  28. package/Contexts/ScreenContext/index.tsx +94 -25
  29. package/events/index.ts +1 -0
  30. package/package.json +5 -5
  31. /package/Contexts/{index.js → index.ts} +0 -0
@@ -50,7 +50,11 @@ describe("getTransformedPreset should return the passed components if smartCompo
50
50
  );
51
51
 
52
52
  expect(transformed_preset).toBeDefined();
53
- expect(transformed_preset.id).toEqual("comp10"); // id was transformed
53
+
54
+ expect(transformed_preset.id).toEqual(
55
+ `${mockComp.id}-${mockPreset.feed_url}-0`
56
+ ); // id was transformed
57
+
54
58
  expect(transformed_preset.data.source).toEqual(mockPreset.feed_url); // source was replaced with preset feed_url.
55
59
  });
56
60
  });
@@ -117,7 +121,10 @@ describe("getTransformedPreset should return the passed components if smartCompo
117
121
 
118
122
  expect(Array.isArray(result)).toBe(true);
119
123
  expect(result).toHaveLength(2);
120
- expect(result[0].id).toEqual("smart10");
124
+
125
+ expect(result[0].id).toEqual(
126
+ `${mockSmartComp.id}-${mockFeeds.preset_source.data.entry[0].feed_url}-0`
127
+ );
121
128
 
122
129
  expect(result[0].data.source).toEqual(
123
130
  mockFeeds.preset_source.data.entry[0].feed_url
@@ -287,7 +294,7 @@ describe("getTransformedPreset should return the passed components if smartCompo
287
294
  mockComponents[0],
288
295
  {
289
296
  ...mockLayoutPresets.preset_one,
290
- id: mockComponents[1].id + 1,
297
+ id: `${mockComponents[1].id}-${mockPresetEntry[0].feed_url}-1`,
291
298
  data: { source: mockPresetEntry[0].feed_url },
292
299
  },
293
300
  ];
@@ -344,12 +351,12 @@ describe("getTransformedPreset should return the passed components if smartCompo
344
351
  const mockTransformedComponents = [
345
352
  {
346
353
  ...mockLayoutPresets.preset_one,
347
- id: mockComponents[0].id + 0,
354
+ id: `${mockComponents[0].id}-${mockPresetEntry1[0].feed_url}-0`,
348
355
  data: { source: mockPresetEntry1[0].feed_url },
349
356
  },
350
357
  {
351
358
  ...mockLayoutPresets.preset_one,
352
- id: mockComponents[1].id + 1,
359
+ id: `${mockComponents[1].id}-${mockPresetEntry2[0].feed_url}-1`,
353
360
  data: { source: mockPresetEntry2[0].feed_url },
354
361
  },
355
362
  ];
@@ -412,7 +419,7 @@ describe("getTransformedPreset should return the passed components if smartCompo
412
419
  const mockTransformedComponents = mockPresetEntry.map((preset, i) => {
413
420
  return {
414
421
  ...mockLayoutPresets[preset.preset_name],
415
- id: mockComponents[0].id + i,
422
+ id: `${mockComponents[0].id}-${preset.feed_url}-${i}`,
416
423
  data: { source: preset.feed_url },
417
424
  };
418
425
  });
@@ -41,7 +41,7 @@ export const getTransformedPreset = (
41
41
  }
42
42
 
43
43
  const updatedPresetComponent = produce(presetComponent, (draft) => {
44
- draft.id = `${componentId}${index}`;
44
+ draft.id = `${componentId}-${preset?.feed_url}-${index}`;
45
45
  draft.data.source = preset?.feed_url;
46
46
 
47
47
  if (draft.ui_components) {
@@ -7,30 +7,72 @@ type BorderPosition = "inside" | "outside" | "center";
7
7
  interface Props {
8
8
  style: ImageStyle | ViewStyle;
9
9
  borderPosition: BorderPosition;
10
- borderPadding: number;
11
10
  children: React.ReactNode;
12
11
  }
13
12
 
14
- const COLOR_TRANSPARENT = "transparent";
13
+ const MARGINS = [
14
+ "marginTop",
15
+ "marginBottom",
16
+ "marginLeft",
17
+ "marginRight",
18
+ ] as const;
15
19
 
16
- const styles = StyleSheet.create({
17
- container: {
18
- overflow: "visible",
19
- borderWidth: 0,
20
- borderColor: COLOR_TRANSPARENT,
21
- },
22
- });
20
+ const PADDINGS = [
21
+ "paddingTop",
22
+ "paddingBottom",
23
+ "paddingLeft",
24
+ "paddingRight",
25
+ ] as const;
23
26
 
24
- const getBorderPadding = (borderPosition: BorderPosition, borderWidth) => {
27
+ const isPercentageValue = (value: number | string) => {
28
+ if (typeof value === "string" && value.endsWith("%")) {
29
+ return true;
30
+ }
31
+
32
+ return false;
33
+ };
34
+
35
+ const calculateContainerSpacing = ({
36
+ spacingKey,
37
+ style,
38
+ additionalSpacing,
39
+ }: {
40
+ spacingKey: typeof MARGINS[number] | typeof PADDINGS[number];
41
+ style: ImageStyle | ViewStyle;
42
+ additionalSpacing: number;
43
+ }) => {
44
+ return {
45
+ [spacingKey]:
46
+ toNumberWithDefaultZero(style[spacingKey]) + additionalSpacing,
47
+ };
48
+ };
49
+
50
+ const getContainerBorderWidth = (
51
+ borderPosition: BorderPosition,
52
+ borderWidth
53
+ ) => {
25
54
  switch (borderPosition) {
26
55
  case "inside":
27
56
  return 0;
28
57
  case "center":
29
- return -borderWidth / 2;
58
+ return borderWidth / 2;
30
59
  case "outside":
31
- return -borderWidth;
60
+ return borderWidth;
32
61
  default:
33
- return -borderWidth;
62
+ return borderWidth;
63
+ }
64
+ };
65
+
66
+ const getContainerPadding = (borderPosition: BorderPosition, borderWidth) => {
67
+ switch (borderPosition) {
68
+ case "inside":
69
+ return borderWidth;
70
+ case "center":
71
+ return borderWidth / 2;
72
+ case "outside":
73
+ return 0;
74
+ default:
75
+ return 0;
34
76
  }
35
77
  };
36
78
 
@@ -41,49 +83,84 @@ const InsideBorder = ({
41
83
  style: ViewStyle;
42
84
  borderPosition: BorderPosition;
43
85
  }) => {
44
- if (!borderPosition) {
86
+ if (borderPosition === "outside") {
45
87
  return null;
46
88
  }
47
89
 
48
- const borderWidth = toNumberWithDefaultZero(style.borderWidth);
49
- const containerPadding = getBorderPadding(borderPosition, borderWidth);
50
-
51
- const borderRadius =
52
- toNumberWithDefaultZero(style.borderRadius) -
53
- getBorderPadding(borderPosition, borderWidth);
90
+ const insideBorderWidth =
91
+ borderPosition === "center" ? style.borderWidth / 2 : style.borderWidth;
54
92
 
55
93
  return (
56
94
  <View
57
95
  style={{
58
96
  ...StyleSheet.absoluteFillObject,
59
- right: containerPadding,
60
- bottom: containerPadding,
61
- left: containerPadding,
62
- top: containerPadding,
63
- borderWidth: borderWidth,
97
+ borderWidth: insideBorderWidth,
64
98
  borderColor: style.borderColor,
65
- borderRadius,
99
+ borderRadius: style.borderRadius,
66
100
  }}
67
101
  />
68
102
  );
69
103
  };
70
104
 
71
105
  export const BorderContainerView = (props: Props) => {
72
- const { borderPosition, borderPadding, style, children } = props;
106
+ const { style, children } = props;
107
+ // Return border position prop after re-implementing
108
+ const borderPosition = "outside";
109
+
110
+ const borderWidth = toNumberWithDefaultZero(style.borderWidth);
111
+ const spacing = getContainerPadding(borderPosition, borderWidth);
73
112
 
74
113
  const borderStyleForMissingBorder =
75
114
  style?.borderWidth === 0 || !style?.borderColor ? { borderRadius: 0 } : {};
76
115
 
77
- const padding =
78
- borderPosition === "outside" ? { padding: borderPadding } : {};
116
+ const updatedMargins = MARGINS.reduce((acc, margin) => {
117
+ const marginValue = calculateContainerSpacing({
118
+ spacingKey: margin,
119
+ style,
120
+ additionalSpacing: spacing,
121
+ });
122
+
123
+ return { ...acc, ...marginValue };
124
+ }, {});
125
+
126
+ const updatedPaddings = PADDINGS.reduce((acc, padding) => {
127
+ const paddingValue = calculateContainerSpacing({
128
+ spacingKey: padding,
129
+ style,
130
+ additionalSpacing: spacing,
131
+ });
132
+
133
+ return { ...acc, ...paddingValue };
134
+ }, {});
135
+
136
+ const updatedWidth = style.width
137
+ ? isPercentageValue(style.width)
138
+ ? style.width
139
+ : toNumberWithDefaultZero(style.width) - spacing * 2
140
+ : undefined;
141
+
142
+ const updatedHeight = style.height
143
+ ? isPercentageValue(style.height)
144
+ ? style.height
145
+ : toNumberWithDefaultZero(style.height) - spacing * 2
146
+ : undefined;
147
+
148
+ const containerStyle = {
149
+ borderWidth: getContainerBorderWidth(borderPosition, borderWidth),
150
+ padding: spacing,
151
+ ...updatedMargins,
152
+ ...updatedPaddings,
153
+ width: updatedWidth,
154
+ height: updatedHeight,
155
+ };
79
156
 
80
157
  return (
81
- <View
82
- {...props}
83
- style={[style, styles.container, borderStyleForMissingBorder, padding]}
84
- >
158
+ <View {...props} style={[style, containerStyle]}>
85
159
  {children}
86
- <InsideBorder style={style} borderPosition={borderPosition} />
160
+ <InsideBorder
161
+ style={{ ...style, ...borderStyleForMissingBorder }}
162
+ borderPosition={borderPosition}
163
+ />
87
164
  </View>
88
165
  );
89
166
  };
@@ -43,14 +43,16 @@ function Image({
43
43
  [source, error]
44
44
  );
45
45
 
46
+ const _source = shouldRenderImg
47
+ ? withDimensions(source)
48
+ : defaultPlaceHolderImage;
49
+
46
50
  return (
47
51
  // @ts-ignore
48
52
  <MemoizedImage
49
53
  style={style as ImageStyle}
50
54
  onError={() => setErrorState(true)}
51
- source={
52
- shouldRenderImg ? withDimensions(source) : defaultPlaceHolderImage
53
- }
55
+ source={_source?.uri ? _source : undefined}
54
56
  {...R.omit(["source"], otherProps)}
55
57
  />
56
58
  );
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import { isVideoPreviewEnabled } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/utils";
3
3
  import { LiveImage } from "../LiveImage";
4
4
  import PureImage from "../Image";
5
+ import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks";
5
6
 
6
7
  type Props = {
7
8
  enable_video_preview: boolean;
@@ -9,7 +10,10 @@ type Props = {
9
10
  };
10
11
 
11
12
  export const ImageContainer = (props: Props) => {
12
- const Component = isVideoPreviewEnabled(props) ? LiveImage : PureImage;
13
+ const isActive = useIsScreenActive();
14
+
15
+ const Component =
16
+ isVideoPreviewEnabled(props) && isActive ? LiveImage : PureImage;
13
17
 
14
18
  return <Component {...props} />;
15
19
  };
@@ -1,7 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Text } from "react-native";
3
3
  import { omit } from "ramda";
4
- import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
5
4
  import {
6
5
  textTransform,
7
6
  dateFormat,
@@ -9,6 +8,9 @@ import {
9
8
 
10
9
  import { useTextLabel, withFocusedStyles } from "./hooks";
11
10
  import { withScaledLineHeight } from "./utils";
11
+ import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";
12
+ import { MeasurementPortalContext } from "../../../MeasurmentsPortal";
13
+ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
12
14
 
13
15
  type Props = {
14
16
  style: any;
@@ -32,14 +34,24 @@ const _Text = ({
32
34
  ...otherProps
33
35
  }: Props) => {
34
36
  const _label = useTextLabel({ label, entry });
37
+ const isMeasurement = React.useContext(MeasurementPortalContext);
35
38
 
36
39
  if (isNilOrEmpty(_label)) {
37
40
  return null;
38
41
  }
39
42
 
43
+ // set maximum possible height for the text in case of measurement
44
+ const height =
45
+ isMeasurement && otherProps.numberOfLines && style.lineHeight
46
+ ? toNumber(otherProps.numberOfLines) * toNumber(style.lineHeight)
47
+ : undefined;
48
+
40
49
  return (
41
50
  <Text
42
- style={withScaledLineHeight(withFocusedStyles({ style, otherProps }))}
51
+ style={[
52
+ withScaledLineHeight(withFocusedStyles({ style, otherProps })),
53
+ { height },
54
+ ]}
43
55
  {...withoutLabel(otherProps)}
44
56
  >
45
57
  {dateTransformEnabled
@@ -39,6 +39,6 @@ describe("image with no source", () => {
39
39
  );
40
40
 
41
41
  const testInstance = testRenderer.root;
42
- expect(testInstance.findByType(Image).props.source).toEqual({ uri: "" });
42
+ expect(testInstance.findByType(Image).props.source).toBeUndefined();
43
43
  });
44
44
  });
@@ -51,9 +51,7 @@ export const CollapsibleTextContainer = ({
51
51
  func: (data) => {
52
52
  return getColorFromData({
53
53
  data,
54
- getValue,
55
- key: "background_color",
56
- defaultColor: additionalStyles.backgroundColor,
54
+ valueFromLayout: additionalStyles.backgroundColor,
57
55
  });
58
56
  },
59
57
  propName: "backgroundColor",
@@ -53,7 +53,7 @@ export const useAsyncRendering = (viewRef: React.RefObject<View>): Return => {
53
53
  measure(viewRef?.current, ({ width, height }) => {
54
54
  setDimensions({
55
55
  width,
56
- height,
56
+ height: Math.ceil(height),
57
57
  });
58
58
  });
59
59
  })
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
+ import { MeasurementPortalContext } from "./MeasurementsPortal";
3
4
 
4
5
  type Props = {
5
6
  Component: React.ElementType;
@@ -19,13 +20,16 @@ const _MeasurementsPortal = (
19
20
  { Component, onLayout, componentProps, containerStyle }: Props,
20
21
  ref
21
22
  ) => (
22
- <View
23
- onLayout={onLayout}
24
- style={[styles.container, containerStyle]}
25
- ref={ref}
26
- >
27
- <Component {...componentProps} />
28
- </View>
23
+ // hack for cell to determine if cell is in measurement mode
24
+ <MeasurementPortalContext.Provider value={{}}>
25
+ <View
26
+ onLayout={onLayout}
27
+ style={[styles.container, containerStyle]}
28
+ ref={ref}
29
+ >
30
+ <Component {...componentProps} />
31
+ </View>
32
+ </MeasurementPortalContext.Provider>
29
33
  );
30
34
 
31
35
  export const MeasurementsPortal = React.forwardRef(_MeasurementsPortal);
@@ -35,7 +35,16 @@ const MeasurementsPortal = ({ Component, onLayout, componentProps }: Props) => {
35
35
  );
36
36
  };
37
37
 
38
- const MeasurementPortalContext = React.createContext(null);
38
+ type MeasurementPortalContextType = {
39
+ measureComponent?: (
40
+ comp: React.ElementType,
41
+ props: Record<any, any>
42
+ ) => Promise<any>;
43
+ measuringInProgress?: boolean;
44
+ };
45
+
46
+ const MeasurementPortalContext =
47
+ React.createContext<null | MeasurementPortalContextType>(null);
39
48
 
40
49
  const MeasurementsPortalContextProvider = ({ children }) => {
41
50
  const Component = React.useRef(View);
@@ -54,7 +54,10 @@ import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";
54
54
  import { usePlayNextOverlay } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayNextOverlay";
55
55
  import { PlayNextState } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/OverlaysObserver";
56
56
 
57
- import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
57
+ import {
58
+ useModalAnimationContext,
59
+ PlayerAnimationStateEnum,
60
+ } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
58
61
 
59
62
  type Props = {
60
63
  Player: React.ComponentType<any>;
@@ -231,6 +234,9 @@ const PlayerContainerComponent = (props: Props) => {
231
234
  const screenData = useTargetScreenData(item);
232
235
  const { setVisible: showNavBar } = useSetNavbarState();
233
236
 
237
+ const { isActiveGesture, startComponentsAnimation, setPlayerAnimationState } =
238
+ useModalAnimationContext();
239
+
234
240
  const playerEvent = (event, ...args) => {
235
241
  playerManager.invokeHandler(event, ...args);
236
242
  };
@@ -448,7 +454,7 @@ const PlayerContainerComponent = (props: Props) => {
448
454
  if (disableMiniPlayer) {
449
455
  navigator.closeVideoModal();
450
456
  } else {
451
- navigator.minimiseVideoModal();
457
+ setPlayerAnimationState(PlayerAnimationStateEnum.minimize);
452
458
  }
453
459
  }
454
460
 
@@ -600,9 +606,6 @@ const PlayerContainerComponent = (props: Props) => {
600
606
  pluginConfiguration,
601
607
  };
602
608
 
603
- const { isActiveGesture, startComponentsAnimation } =
604
- useModalAnimationContext();
605
-
606
609
  return (
607
610
  <PlayerStateContext.Provider value={value}>
608
611
  <PlayerContainerContextProvider
@@ -668,6 +671,7 @@ const PlayerContainerComponent = (props: Props) => {
668
671
  setNextVideoPreloadThresholdPercentage={
669
672
  setNextVideoPreloadThresholdPercentage
670
673
  }
674
+ startComponentsAnimation={startComponentsAnimation}
671
675
  >
672
676
  {renderApplePlayer(applePlayerProps)}
673
677
  </Player>
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import * as R from "ramda";
3
- import { View, FlatList, StyleSheet, Platform } from "react-native";
3
+ import { View, StyleSheet, Platform, FlatList } from "react-native";
4
4
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
5
5
  import { RiverItem } from "../RiverItem";
6
6
  import { RiverFooter } from "../RiverFooter";
@@ -21,7 +21,8 @@ import {
21
21
  import { useScreenData } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenData";
22
22
  import { isLast } from "@applicaster/zapp-react-native-utils/arrayUtils";
23
23
  import { withComponentsMapProvider } from "@applicaster/zapp-react-native-ui-components/Decorators/ComponentsMapWrapper";
24
- import { useScreenScrollStore } from "@applicaster/zapp-react-native-utils/screenState";
24
+ import { useScreenContextV2 } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
25
+ import { useShallow } from "zustand/react/shallow";
25
26
 
26
27
  type Props = {
27
28
  feed: ZappFeed;
@@ -41,8 +42,10 @@ const styles = StyleSheet.create({
41
42
  },
42
43
  });
43
44
 
44
- const scrollIndicatorInsets = { right: 1 };
45
+ const getNearestValue = (value, optionA, optionB) =>
46
+ Math.abs(value - optionA) < Math.abs(value - optionB) ? optionA : optionB;
45
47
 
48
+ const scrollIndicatorInsets = { right: 1 };
46
49
  const keyExtractor = R.compose(String, R.prop("id"));
47
50
 
48
51
  function ComponentsMapComponent(props: Props) {
@@ -60,6 +63,7 @@ function ComponentsMapComponent(props: Props) {
60
63
  refreshingPipesV1,
61
64
  } = props;
62
65
 
66
+ const flatListRef = React.useRef<FlatList | null>(null);
63
67
  const screenConfig = useScreenConfiguration(riverId);
64
68
  const screenData = useScreenData(riverId);
65
69
  const pullToRefreshEnabled = screenData?.rules?.pull_to_refresh_enabled;
@@ -194,26 +198,81 @@ function ComponentsMapComponent(props: Props) {
194
198
  []
195
199
  );
196
200
 
197
- const onScrollFlatList = React.useCallback(
198
- ({ nativeEvent }, isScrollingDone = false) => {
199
- const {
200
- contentOffset: { y },
201
- } = nativeEvent;
201
+ const navBarStore = useScreenContextV2()._navBarStore;
202
202
 
203
- useScreenScrollStore.setState({
204
- scrollingVelocity: isScrollingDone ? 0 : 1,
205
- scrollPosition: y,
206
- });
207
- },
208
- []
203
+ const scrollY = navBarStore(
204
+ useShallow(({ scrollYAnimated }) => scrollYAnimated)
209
205
  );
210
206
 
211
- const onMomentumScrollEnd = React.useCallback(
212
- ({ nativeEvent }) => {
213
- onScrollFlatList({ nativeEvent }, true);
214
- },
215
- [onScrollFlatList]
216
- );
207
+ const canMomentum = React.useRef(false);
208
+
209
+ const onScrollBeginDrag = React.useCallback(() => {
210
+ canMomentum.current = true;
211
+ }, []);
212
+
213
+ /* onMomentumScrollEnd: Handling snap to expanded/collapsed state ( for navbar ) */
214
+ const _onMomentumScrollEnd = React.useCallback(({ nativeEvent }) => {
215
+ if (!canMomentum.current) return;
216
+ canMomentum.current = false;
217
+
218
+ const { height: headerHeight, scrollState } = navBarStore.getState();
219
+
220
+ const offsetY = Math.max(0, nativeEvent.contentOffset.y);
221
+
222
+ if (
223
+ !(scrollState === 0 || scrollState === -headerHeight) &&
224
+ flatListRef.current
225
+ ) {
226
+ const offset =
227
+ getNearestValue(Math.round(scrollState), -headerHeight, 0) ===
228
+ -headerHeight
229
+ ? Math.round(offsetY + scrollState + headerHeight)
230
+ : Math.round(offsetY + scrollState);
231
+
232
+ flatListRef.current.scrollToOffset({
233
+ animated: true,
234
+ offset,
235
+ });
236
+ }
237
+ }, []);
238
+
239
+ /* onScrollEnd: Handling snap to expanded/collapsed state ( for navbar ) */
240
+ const _onScrollEndDrag = React.useCallback(({ nativeEvent }) => {
241
+ const { height: headerHeight, scrollState } = navBarStore.getState();
242
+
243
+ const offsetY = Math.max(0, nativeEvent.contentOffset.y);
244
+
245
+ if (
246
+ !(scrollState === 0 || scrollState === -headerHeight) &&
247
+ flatListRef.current &&
248
+ nativeEvent.velocity.y === 0
249
+ ) {
250
+ const offset =
251
+ getNearestValue(Math.round(scrollState), -headerHeight, 0) ===
252
+ -headerHeight
253
+ ? Math.round(offsetY + scrollState + headerHeight)
254
+ : Math.round(offsetY + scrollState);
255
+
256
+ flatListRef.current.scrollToOffset({
257
+ animated: true,
258
+ offset,
259
+ });
260
+ }
261
+ }, []);
262
+
263
+ const onScroll = React.useCallback((event) => {
264
+ const {
265
+ nativeEvent: {
266
+ contentOffset: { y },
267
+ layoutMeasurement: { height },
268
+ contentSize: { height: contentHeight },
269
+ },
270
+ } = event;
271
+
272
+ if (y >= 0 && y + height <= contentHeight) {
273
+ scrollY.setValue(y);
274
+ }
275
+ }, []);
217
276
 
218
277
  if (shouldShowLoadingError) {
219
278
  return <RiverError />;
@@ -230,6 +289,9 @@ function ComponentsMapComponent(props: Props) {
230
289
  >
231
290
  <ViewportTracker>
232
291
  <FlatList
292
+ ref={(ref) => {
293
+ flatListRef.current = ref;
294
+ }}
233
295
  // Fix for WebView rerender crashes on Android API 28+
234
296
  // https://github.com/react-native-webview/react-native-webview/issues/1915#issuecomment-964035468
235
297
  overScrollMode={Platform.OS === "android" ? "never" : "auto"}
@@ -249,8 +311,10 @@ function ComponentsMapComponent(props: Props) {
249
311
  }
250
312
  ListFooterComponent={renderFooter}
251
313
  refreshControl={refreshControl}
252
- onScroll={onScrollFlatList}
253
- onMomentumScrollEnd={onMomentumScrollEnd}
314
+ onScrollBeginDrag={onScrollBeginDrag}
315
+ onScroll={onScroll}
316
+ onMomentumScrollEnd={_onMomentumScrollEnd}
317
+ onScrollEndDrag={_onScrollEndDrag}
254
318
  scrollEventThrottle={16}
255
319
  {...scrollViewExtraProps}
256
320
  />