@quintype/native-components 2.20.4 → 2.20.5

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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [2.20.5](https://github.com/quintype/native-components/compare/v2.20.4...v2.20.5) (2023-03-21)
6
+
5
7
  ### [2.20.4](https://github.com/quintype/native-components/compare/v2.20.3...v2.20.4) (2023-02-01)
6
8
 
7
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/native-components",
3
- "version": "2.20.4",
3
+ "version": "2.20.5",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,4 +1,3 @@
1
-
2
1
  import PropTypes from "prop-types";
3
2
  import React, { useContext, useRef, useState } from "react";
4
3
  import { TouchableOpacity, View } from "react-native";
@@ -23,15 +22,15 @@ export const StorySlideshow = ({ card, cdn }) => {
23
22
 
24
23
  const moveNext = () => {
25
24
  if (!lastSlide) {
26
- flatlistRef.current.scrollToIndex({ index: currentIndex + 1 });
25
+ flatlistRef.current.scrollToIndex({ index: Math.floor(Math.min(currentIndex + 1, totalSlides - 1))});
27
26
  setCurrentTabIndex(currentIndex + 1);
28
27
  }
29
28
  };
30
29
 
31
30
  const movePrev = () => {
32
31
  if (!firstSlide) {
33
- flatlistRef.current.scrollToIndex({ index: currentIndex - 1 });
34
- setCurrentTabIndex(currentIndex - 1);
32
+ flatlistRef.current.scrollToIndex({ index: Math.ceil(Math.max(currentIndex - 1, 0)) });
33
+ setCurrentTabIndex(Math.max(currentIndex - 1, 0));
35
34
  }
36
35
  };
37
36
 
@@ -49,6 +48,23 @@ export const StorySlideshow = ({ card, cdn }) => {
49
48
  );
50
49
  };
51
50
 
51
+ const handleScroll = (event) => {
52
+ const xOffset = event.nativeEvent?.contentOffset?.x;
53
+ const contentWidth = event.nativeEvent?.contentSize?.width;
54
+ const layoutWidth = event.nativeEvent?.layoutMeasurement?.width;
55
+ const value = (xOffset / contentWidth);
56
+ const leftThreshold = contentWidth / ( 2 * totalSlides );
57
+ const rightThreshold = contentWidth - ( 1.5 ) * layoutWidth;
58
+
59
+ if((leftThreshold <= xOffset && (layoutWidth > xOffset || rightThreshold > xOffset ))){
60
+ setCurrentTabIndex(value * totalSlides);
61
+ } else if(xOffset < leftThreshold){
62
+ setCurrentTabIndex(0);
63
+ } else if(xOffset >= rightThreshold){
64
+ setCurrentTabIndex(totalSlides-1);
65
+ }
66
+ }
67
+
52
68
  return (
53
69
  <View style={styles.wrapper}>
54
70
  <Text primary style={styles.titleText}>
@@ -62,6 +78,7 @@ export const StorySlideshow = ({ card, cdn }) => {
62
78
  keyExtractor={(item) => item.id}
63
79
  horizontal
64
80
  extraData={currentIndex}
81
+ onScroll={handleScroll}
65
82
  />
66
83
 
67
84
  {!firstSlide && showArrow("left")}