react-native-reanimated-carousel 4.0.0-alpha.1 → 4.0.0-alpha.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.
|
@@ -5,16 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useCommonVariables = useCommonVariables;
|
|
7
7
|
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
11
9
|
|
|
12
10
|
var _computeNewIndexWhenDataChanges = require("../utils/computeNewIndexWhenDataChanges");
|
|
13
11
|
|
|
14
12
|
var _handleroffsetDirection = require("../utils/handleroffset-direction");
|
|
15
13
|
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
14
|
function useCommonVariables(props) {
|
|
19
15
|
const {
|
|
20
16
|
vertical,
|
|
@@ -26,17 +22,15 @@ function useCommonVariables(props) {
|
|
|
26
22
|
loop
|
|
27
23
|
} = props;
|
|
28
24
|
const size = vertical ? height : width;
|
|
29
|
-
const validLength = dataLength - 1;
|
|
30
25
|
const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);
|
|
31
26
|
|
|
32
27
|
const _handlerOffset = (0, _reactNativeReanimated.useSharedValue)(defaultHandlerOffsetValue);
|
|
33
28
|
|
|
34
29
|
const handlerOffset = defaultScrollOffsetValue !== null && defaultScrollOffsetValue !== void 0 ? defaultScrollOffsetValue : _handlerOffset;
|
|
35
30
|
const prevDataLength = (0, _reactNativeReanimated.useSharedValue)(dataLength);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, [vertical, handlerOffset, defaultHandlerOffsetValue]);
|
|
31
|
+
/**
|
|
32
|
+
* When data changes, we need to compute new index for handlerOffset
|
|
33
|
+
*/
|
|
40
34
|
|
|
41
35
|
(0, _reactNativeReanimated.useAnimatedReaction)(() => {
|
|
42
36
|
const previousLength = prevDataLength.value;
|
|
@@ -70,7 +64,7 @@ function useCommonVariables(props) {
|
|
|
70
64
|
}, [dataLength, loop]);
|
|
71
65
|
return {
|
|
72
66
|
size,
|
|
73
|
-
validLength,
|
|
67
|
+
validLength: dataLength - 1,
|
|
74
68
|
handlerOffset
|
|
75
69
|
};
|
|
76
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCommonVariables.ts"],"names":["useCommonVariables","props","vertical","height","width","dataLength","defaultIndex","defaultScrollOffsetValue","loop","size","
|
|
1
|
+
{"version":3,"sources":["useCommonVariables.ts"],"names":["useCommonVariables","props","vertical","height","width","dataLength","defaultIndex","defaultScrollOffsetValue","loop","size","defaultHandlerOffsetValue","Math","abs","_handlerOffset","handlerOffset","prevDataLength","previousLength","value","currentLength","isLengthChanged","shouldComputed","direction","validLength"],"mappings":";;;;;;;AACA;;AAIA;;AACA;;AAQO,SAASA,kBAAT,CACLC,KADK,EAEa;AAClB,QAAM;AACJC,IAAAA,QADI;AAEJC,IAAAA,MAFI;AAGJC,IAAAA,KAHI;AAIJC,IAAAA,UAJI;AAKJC,IAAAA,YALI;AAMJC,IAAAA,wBANI;AAOJC,IAAAA;AAPI,MAQFP,KARJ;AASA,QAAMQ,IAAI,GAAGP,QAAQ,GAAGC,MAAH,GAAYC,KAAjC;AACA,QAAMM,yBAAyB,GAAG,CAACC,IAAI,CAACC,GAAL,CAASN,YAAY,GAAGG,IAAxB,CAAnC;;AACA,QAAMI,cAAc,GAAG,2CAAuBH,yBAAvB,CAAvB;;AACA,QAAMI,aAAa,GAAGP,wBAAH,aAAGA,wBAAH,cAAGA,wBAAH,GAA+BM,cAAlD;AACA,QAAME,cAAc,GAAG,2CAAeV,UAAf,CAAvB;AAEA;AACF;AACA;;AACE,kDAAoB,MAAM;AACxB,UAAMW,cAAc,GAAGD,cAAc,CAACE,KAAtC;AACA,UAAMC,aAAa,GAAGb,UAAtB;AACA,UAAMc,eAAe,GAAGH,cAAc,KAAKE,aAA3C;AACA,UAAME,cAAc,GAAGD,eAAe,IAAIX,IAA1C;AAEA,QAAIY,cAAJ,EACEL,cAAc,CAACE,KAAf,GAAuBZ,UAAvB;AAEF,WAAO;AACLe,MAAAA,cADK;AAELJ,MAAAA,cAFK;AAGLE,MAAAA;AAHK,KAAP;AAKD,GAdD,EAcG,QAAuD;AAAA,QAAtD;AAAEE,MAAAA,cAAF;AAAkBJ,MAAAA,cAAlB;AAAkCE,MAAAA;AAAlC,KAAsD;;AACxD,QAAIE,cAAJ,EAAoB;AAClB;AACA,YAAMC,SAAS,GAAG,oDAAuBP,aAAvB,CAAlB;AAEAA,MAAAA,aAAa,CAACG,KAAd,GAAsB,oEAA+B;AACnDI,QAAAA,SADmD;AAEnDL,QAAAA,cAFmD;AAGnDE,QAAAA,aAHmD;AAInDT,QAAAA,IAJmD;AAKnDK,QAAAA,aAAa,EAAEA,aAAa,CAACG;AALsB,OAA/B,CAAtB;AAOD;AACF,GA3BD,EA2BG,CAACZ,UAAD,EAAaG,IAAb,CA3BH;AA6BA,SAAO;AACLC,IAAAA,IADK;AAELa,IAAAA,WAAW,EAAEjB,UAAU,GAAG,CAFrB;AAGLS,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import type Animated from \"react-native-reanimated\";\nimport { useSharedValue, useAnimatedReaction } from \"react-native-reanimated\";\n\nimport type { TInitializeCarouselProps } from \"./useInitProps\";\n\nimport { computeNewIndexWhenDataChanges } from \"../utils/computeNewIndexWhenDataChanges\";\nimport { handlerOffsetDirection } from \"../utils/handleroffset-direction\";\n\ninterface ICommonVariables {\n size: number\n validLength: number\n handlerOffset: Animated.SharedValue<number>\n}\n\nexport function useCommonVariables(\n props: TInitializeCarouselProps<any>,\n): ICommonVariables {\n const {\n vertical,\n height,\n width,\n dataLength,\n defaultIndex,\n defaultScrollOffsetValue,\n loop,\n } = props;\n const size = vertical ? height : width;\n const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);\n const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);\n const handlerOffset = defaultScrollOffsetValue ?? _handlerOffset;\n const prevDataLength = useSharedValue(dataLength);\n\n /**\n * When data changes, we need to compute new index for handlerOffset\n */\n useAnimatedReaction(() => {\n const previousLength = prevDataLength.value;\n const currentLength = dataLength;\n const isLengthChanged = previousLength !== currentLength;\n const shouldComputed = isLengthChanged && loop;\n\n if (shouldComputed)\n prevDataLength.value = dataLength;\n\n return {\n shouldComputed,\n previousLength,\n currentLength,\n };\n }, ({ shouldComputed, previousLength, currentLength }) => {\n if (shouldComputed) {\n // direction -> 1 | -1\n const direction = handlerOffsetDirection(handlerOffset);\n\n handlerOffset.value = computeNewIndexWhenDataChanges({\n direction,\n previousLength,\n currentLength,\n size,\n handlerOffset: handlerOffset.value,\n });\n }\n }, [dataLength, loop]);\n\n return {\n size,\n validLength: dataLength - 1,\n handlerOffset,\n };\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { useSharedValue, useAnimatedReaction } from "react-native-reanimated";
|
|
3
2
|
import { computeNewIndexWhenDataChanges } from "../utils/computeNewIndexWhenDataChanges";
|
|
4
3
|
import { handlerOffsetDirection } from "../utils/handleroffset-direction";
|
|
@@ -13,16 +12,16 @@ export function useCommonVariables(props) {
|
|
|
13
12
|
loop
|
|
14
13
|
} = props;
|
|
15
14
|
const size = vertical ? height : width;
|
|
16
|
-
const validLength = dataLength - 1;
|
|
17
15
|
const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);
|
|
18
16
|
|
|
19
17
|
const _handlerOffset = useSharedValue(defaultHandlerOffsetValue);
|
|
20
18
|
|
|
21
19
|
const handlerOffset = defaultScrollOffsetValue !== null && defaultScrollOffsetValue !== void 0 ? defaultScrollOffsetValue : _handlerOffset;
|
|
22
20
|
const prevDataLength = useSharedValue(dataLength);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* When data changes, we need to compute new index for handlerOffset
|
|
23
|
+
*/
|
|
24
|
+
|
|
26
25
|
useAnimatedReaction(() => {
|
|
27
26
|
const previousLength = prevDataLength.value;
|
|
28
27
|
const currentLength = dataLength;
|
|
@@ -55,7 +54,7 @@ export function useCommonVariables(props) {
|
|
|
55
54
|
}, [dataLength, loop]);
|
|
56
55
|
return {
|
|
57
56
|
size,
|
|
58
|
-
validLength,
|
|
57
|
+
validLength: dataLength - 1,
|
|
59
58
|
handlerOffset
|
|
60
59
|
};
|
|
61
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCommonVariables.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["useCommonVariables.ts"],"names":["useSharedValue","useAnimatedReaction","computeNewIndexWhenDataChanges","handlerOffsetDirection","useCommonVariables","props","vertical","height","width","dataLength","defaultIndex","defaultScrollOffsetValue","loop","size","defaultHandlerOffsetValue","Math","abs","_handlerOffset","handlerOffset","prevDataLength","previousLength","value","currentLength","isLengthChanged","shouldComputed","direction","validLength"],"mappings":"AACA,SAASA,cAAT,EAAyBC,mBAAzB,QAAoD,yBAApD;AAIA,SAASC,8BAAT,QAA+C,yCAA/C;AACA,SAASC,sBAAT,QAAuC,kCAAvC;AAQA,OAAO,SAASC,kBAAT,CACLC,KADK,EAEa;AAClB,QAAM;AACJC,IAAAA,QADI;AAEJC,IAAAA,MAFI;AAGJC,IAAAA,KAHI;AAIJC,IAAAA,UAJI;AAKJC,IAAAA,YALI;AAMJC,IAAAA,wBANI;AAOJC,IAAAA;AAPI,MAQFP,KARJ;AASA,QAAMQ,IAAI,GAAGP,QAAQ,GAAGC,MAAH,GAAYC,KAAjC;AACA,QAAMM,yBAAyB,GAAG,CAACC,IAAI,CAACC,GAAL,CAASN,YAAY,GAAGG,IAAxB,CAAnC;;AACA,QAAMI,cAAc,GAAGjB,cAAc,CAASc,yBAAT,CAArC;;AACA,QAAMI,aAAa,GAAGP,wBAAH,aAAGA,wBAAH,cAAGA,wBAAH,GAA+BM,cAAlD;AACA,QAAME,cAAc,GAAGnB,cAAc,CAACS,UAAD,CAArC;AAEA;AACF;AACA;;AACER,EAAAA,mBAAmB,CAAC,MAAM;AACxB,UAAMmB,cAAc,GAAGD,cAAc,CAACE,KAAtC;AACA,UAAMC,aAAa,GAAGb,UAAtB;AACA,UAAMc,eAAe,GAAGH,cAAc,KAAKE,aAA3C;AACA,UAAME,cAAc,GAAGD,eAAe,IAAIX,IAA1C;AAEA,QAAIY,cAAJ,EACEL,cAAc,CAACE,KAAf,GAAuBZ,UAAvB;AAEF,WAAO;AACLe,MAAAA,cADK;AAELJ,MAAAA,cAFK;AAGLE,MAAAA;AAHK,KAAP;AAKD,GAdkB,EAchB,QAAuD;AAAA,QAAtD;AAAEE,MAAAA,cAAF;AAAkBJ,MAAAA,cAAlB;AAAkCE,MAAAA;AAAlC,KAAsD;;AACxD,QAAIE,cAAJ,EAAoB;AAClB;AACA,YAAMC,SAAS,GAAGtB,sBAAsB,CAACe,aAAD,CAAxC;AAEAA,MAAAA,aAAa,CAACG,KAAd,GAAsBnB,8BAA8B,CAAC;AACnDuB,QAAAA,SADmD;AAEnDL,QAAAA,cAFmD;AAGnDE,QAAAA,aAHmD;AAInDT,QAAAA,IAJmD;AAKnDK,QAAAA,aAAa,EAAEA,aAAa,CAACG;AALsB,OAAD,CAApD;AAOD;AACF,GA3BkB,EA2BhB,CAACZ,UAAD,EAAaG,IAAb,CA3BgB,CAAnB;AA6BA,SAAO;AACLC,IAAAA,IADK;AAELa,IAAAA,WAAW,EAAEjB,UAAU,GAAG,CAFrB;AAGLS,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import type Animated from \"react-native-reanimated\";\nimport { useSharedValue, useAnimatedReaction } from \"react-native-reanimated\";\n\nimport type { TInitializeCarouselProps } from \"./useInitProps\";\n\nimport { computeNewIndexWhenDataChanges } from \"../utils/computeNewIndexWhenDataChanges\";\nimport { handlerOffsetDirection } from \"../utils/handleroffset-direction\";\n\ninterface ICommonVariables {\n size: number\n validLength: number\n handlerOffset: Animated.SharedValue<number>\n}\n\nexport function useCommonVariables(\n props: TInitializeCarouselProps<any>,\n): ICommonVariables {\n const {\n vertical,\n height,\n width,\n dataLength,\n defaultIndex,\n defaultScrollOffsetValue,\n loop,\n } = props;\n const size = vertical ? height : width;\n const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);\n const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);\n const handlerOffset = defaultScrollOffsetValue ?? _handlerOffset;\n const prevDataLength = useSharedValue(dataLength);\n\n /**\n * When data changes, we need to compute new index for handlerOffset\n */\n useAnimatedReaction(() => {\n const previousLength = prevDataLength.value;\n const currentLength = dataLength;\n const isLengthChanged = previousLength !== currentLength;\n const shouldComputed = isLengthChanged && loop;\n\n if (shouldComputed)\n prevDataLength.value = dataLength;\n\n return {\n shouldComputed,\n previousLength,\n currentLength,\n };\n }, ({ shouldComputed, previousLength, currentLength }) => {\n if (shouldComputed) {\n // direction -> 1 | -1\n const direction = handlerOffsetDirection(handlerOffset);\n\n handlerOffset.value = computeNewIndexWhenDataChanges({\n direction,\n previousLength,\n currentLength,\n size,\n handlerOffset: handlerOffset.value,\n });\n }\n }, [dataLength, loop]);\n\n return {\n size,\n validLength: dataLength - 1,\n handlerOffset,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated-carousel",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import type Animated from "react-native-reanimated";
|
|
3
2
|
import { useSharedValue, useAnimatedReaction } from "react-native-reanimated";
|
|
4
3
|
|
|
@@ -26,16 +25,14 @@ export function useCommonVariables(
|
|
|
26
25
|
loop,
|
|
27
26
|
} = props;
|
|
28
27
|
const size = vertical ? height : width;
|
|
29
|
-
const validLength = dataLength - 1;
|
|
30
28
|
const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);
|
|
31
29
|
const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);
|
|
32
30
|
const handlerOffset = defaultScrollOffsetValue ?? _handlerOffset;
|
|
33
31
|
const prevDataLength = useSharedValue(dataLength);
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
/**
|
|
34
|
+
* When data changes, we need to compute new index for handlerOffset
|
|
35
|
+
*/
|
|
39
36
|
useAnimatedReaction(() => {
|
|
40
37
|
const previousLength = prevDataLength.value;
|
|
41
38
|
const currentLength = dataLength;
|
|
@@ -67,7 +64,7 @@ export function useCommonVariables(
|
|
|
67
64
|
|
|
68
65
|
return {
|
|
69
66
|
size,
|
|
70
|
-
validLength,
|
|
67
|
+
validLength: dataLength - 1,
|
|
71
68
|
handlerOffset,
|
|
72
69
|
};
|
|
73
70
|
}
|