-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* (PC-31740) chore: upgrade reanimated to 3.15 * fix: issues with carousel * fix: patch react-native-reanimated-carousel (dohooo/react-native-reanimated-carousel#576) * test: fix tests * fix: OfferPreviewModal .web file --------- Co-authored-by: Mathieu Meissonnier <mathieu.meissonnier@passculture.app>
- Loading branch information
1 parent
1d0a545
commit b13810e
Showing
14 changed files
with
546 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { forwardRef, useEffect, useImperativeHandle } from 'react' | ||
import { FlatList, ListRenderItem } from 'react-native' | ||
import { TCarouselProps } from 'react-native-reanimated-carousel' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export default forwardRef< | ||
any, | ||
Omit<TCarouselProps, 'onProgressChange'> & { | ||
onProgressChange: (offsetProgress: number, absoluteProgress: number) => void | ||
} | ||
>(function Carousel( | ||
{ renderItem, data, testID, width, height, onProgressChange, defaultIndex = 0 }, | ||
ref | ||
) { | ||
useImperativeHandle(ref, () => ({ | ||
next: jest.fn(), | ||
prev: jest.fn(), | ||
scrollTo: ({ index }: { index: number }) => { | ||
onProgressChange(0, index) | ||
}, | ||
getCurrentIndex: jest.fn(), | ||
})) | ||
|
||
useEffect(() => { | ||
if (defaultIndex > 0) { | ||
onProgressChange(0, defaultIndex) | ||
} | ||
}, [defaultIndex, onProgressChange]) | ||
|
||
return ( | ||
<FlatList | ||
ref={ref} | ||
testID={testID} | ||
renderItem={renderItem as unknown as ListRenderItem<unknown>} | ||
data={data} | ||
keyExtractor={(_, index) => index.toString()} | ||
style={{ width, height }} | ||
/> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
patches/react-native-reanimated-carousel+4.0.0-alpha.12.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
diff --git a/node_modules/react-native-reanimated-carousel/src/components/ScrollViewGesture.tsx b/node_modules/react-native-reanimated-carousel/src/components/ScrollViewGesture.tsx | ||
index 80a3fe0..ff03ed6 100644 | ||
--- a/node_modules/react-native-reanimated-carousel/src/components/ScrollViewGesture.tsx | ||
+++ b/node_modules/react-native-reanimated-carousel/src/components/ScrollViewGesture.tsx | ||
@@ -65,7 +65,7 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => { | ||
const maxPage = dataLength; | ||
const isHorizontal = useDerivedValue(() => !vertical, [vertical]); | ||
const max = useSharedValue(0); | ||
- const panOffset = useSharedValue(0); | ||
+ const panOffset = useSharedValue<number | undefined>(undefined); | ||
const touching = useSharedValue(false); | ||
const validStart = useSharedValue(false); | ||
const scrollEndTranslation = useSharedValue(0); | ||
@@ -291,6 +291,10 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => { | ||
const onGestureUpdate = useCallback((e: PanGestureHandlerEventPayload) => { | ||
"worklet"; | ||
|
||
+ if (panOffset.value === undefined) { | ||
+ return; | ||
+ } | ||
+ | ||
if (validStart.value) { | ||
validStart.value = false; | ||
cancelAnimation(translation); | ||
@@ -335,6 +339,10 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => { | ||
const onGestureEnd = useCallback((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>, _success: boolean) => { | ||
"worklet"; | ||
|
||
+ if (panOffset.value === undefined) { | ||
+ return; | ||
+ } | ||
+ | ||
const { velocityX, velocityY, translationX, translationY } = e; | ||
const scrollEndVelocityValue = isHorizontal.value | ||
? velocityX | ||
@@ -381,6 +389,8 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => { | ||
|
||
if (!loop) | ||
touching.value = false; | ||
+ | ||
+ panOffset.value = undefined; | ||
}, [ | ||
size, | ||
loop, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.