-
-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【Android only】autoPlay does not work when scrolling up or down in a scroll view #587
Comments
The issue you're experiencing with import { Dimensions, ScrollView, Image, View } from "react-native";
import Carousel from "react-native-reanimated-carousel";
import { GestureHandlerRootView } from "react-native-gesture-handler";
export default function App(props) {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<ScrollView>
...
<Carousel
...
/>
...
</ScrollView>
</GestureHandlerRootView>
);
} This solution is based on feedback from similar issues reported in the Try these approaches and see if they address the issue. If you encounter further difficulties or need more assistance, feel free to ask. Sources
|
I also faced this issue. My Carousel Component is inside Scrollview. (BannerImageSlider Component) Problem 1 -> This slider stop between 2 items when scrolling initialize horizontally with a little bit of vertical scroll. Both Problem 1 and Problem 2 are solved. This solution may help you :) Problem 1 0-02-06-5535f28b5be5c3acea3512ec1d9032cca6ac51130d7cddc8677ef61d93bd5e6d_e9a927c5dfd77faa.mp4Problem 2 0-02-06-f8ea40f6fedfb564b27af64ea9dc3d1a61f4329d944f9dfdef3bcc7b19d1097f_95ce870f92a1f72a.mp4After fixed Problem 1 and Problem 2 0-02-06-e25c015139d625e677376a488f34c1cfd1467a69f876ce11f386cf055b5ee64d_4189b6d298690931.mp4// Solution import React, { useRef, useState } from "react";
import { Dimensions, View } from "react-native";
import { Text } from "react-native-paper";
import Carousel from "react-native-reanimated-carousel";
export default function BannerImageSlider({
leftSpacing = 0,
rightSpacing = 0,
}) {
const width = Dimensions.get("window").width;
const containerWidth = width - leftSpacing - rightSpacing;
const sliderRef = useRef(null);
const absoluteProgressRef = useRef(0);
const isScrolling = useRef(false);
const [isFailedGesture, setIsFailedGesture] = useState(false);
return (
<View style={{ alignItems: "center" }}>
<Carousel
loop
ref={sliderRef}
width={containerWidth}
height={containerWidth / 2}
// Manually control autoPlay based on isFailedGesture (state)
autoPlay={!isFailedGesture}
data={[...Array(5)]}
scrollAnimationDuration={300}
autoPlayInterval={1000}
onSnapToItem={(index) => {}}
windowSize={20}
onProgressChange={(offsetProgress, absoluteProgress) => {
absoluteProgressRef.current = absoluteProgress;
}}
panGestureHandlerProps={{
activeOffsetX: [-10, 10],
// Fixed Problem 1 by comparing absoluteProgress (Ref) and
// currentIndex then manually scroll item
onCancelled: (event) => {
const currentIndex = sliderRef.current.getCurrentIndex();
const absoluteProgress = absoluteProgressRef.current;
if (absoluteProgress > currentIndex) {
sliderRef.current.next();
} else {
sliderRef.current.prev();
}
setIsFailedGesture(true);
},
}}
// Fixed Problem 2 by setting isFailedGesture (state) on scroll begin
// and on scroll end then manually control autoPlay value based on
// this state
onScrollBegin={() => setIsFailedGesture(false)}
onScrollEnd={() => setIsFailedGesture(false)}
snapEnabled={false}
pagingEnabled={true}
renderItem={({ item, index }) => (
<View
style={{
flex: 1,
justifyContent: "center",
}}
>
<Text variant="titleLarge" style={{ textAlign: "center" }}>
{index}
</Text>
</View>
)}
/>
</View>
);
} |
@minhtet-ko Thank you for your answer. However, although the |
Describe the bug
As described above,
autoPlay
settings does not work when scrolling up or down with touches oncarousel
in a scroll view on Android. It works well on iOS.To Reproduce
Steps to reproduce the behavior:
react-native-reanimated-carousel
.Carousel
in a scroll view.autoPlay
andloop
astrue
.autoPlay
does not work on android, in other words, the autoPlay stops.Expected behavior
autoPlay
works well on Android even if when scrolling up or down.Screenshots
12_1713234373.mp4
Versions (please complete the following information):
Smartphone (please complete the following information):
Additional context
Codes
The text was updated successfully, but these errors were encountered: