react-native-reanimated-bottom-sheet icon indicating copy to clipboard operation
react-native-reanimated-bottom-sheet copied to clipboard

Slider not working on BottomSheet renderContent

Open hovoaep opened this issue 5 years ago • 9 comments

Hello guys.

I have this type BottomSheet

 <BottomSheet
              callbackNode={fall}
              ref={sheetRef}
              snapPoints={[99, Dimensions.get("window").height + 50]}
              borderRadius={0}
              renderContent={renderContent}
            />

And in renderContent have this track status component

import React, { useEffect, useState } from "react";
import { View, Text } from "react-native";
import TrackPlayer from "react-native-track-player";
import { useTrackPlayerProgress } from "react-native-track-player/lib/hooks";
import Slider from "@react-native-community/slider";
import useAudio from "../../hooks/useAudio";
import { getFormattedTime } from "../../utils";

export const TrackStatus = () => {
  const { playerConfig } = useAudio();

  //the value of the slider should be between 0 and 1
  const [sliderValue, setSliderValue] = useState(0);

  //flag to check whether the use is sliding the seekbar or not
  const [isSeeking, setIsSeeking] = useState(false);

  //useTrackPlayerProgress is a hook which provides the current position and duration of the track player.
  //These values will update every 250ms
  const { position, duration } = useTrackPlayerProgress(250);

  //this hook updates the value of the slider whenever the current position of the song changes
  useEffect(() => {
    if (!isSeeking && position && duration) {
      setSliderValue(position / duration);
    }
  }, [position, duration]);

  //this function is called when the user starts to slide the seekbar
  const slidingStarted = () => {
    setIsSeeking(true);
  };
  //this function is called when the user stops sliding the seekbar
  const slidingCompleted = async (value) => {
    await TrackPlayer.seekTo(value * duration);
    setSliderValue(value);
    setIsSeeking(false);
  };

  return (
    <View style={{ zIndex: 100000, elevation: 100000 }}>
      <View
        style={{
          flexDirection: "row",
          paddingHorizontal: 0,
          alignItems: "center",
          height: 40,
          zIndex: 1,
          elevation: 1,
          zIndex: 10000000,
          elevation: 100000000,
        }}
      >
        <Slider
          minimumValue={0}
          maximumValue={1}
          thumbTintColor="#ffffff"
          minimumTrackTintColor="#000000"
          maximumTrackTintColor="#808080"
          onSlidingStart={slidingStarted}
          onSlidingComplete={slidingCompleted}
          value={sliderValue}
          style={{ width: "100%", zIndex: 100000, elevation: 100000 }}
        />
      </View>
      <View style={{ flexDirection: "row", justifyContent: "space-between" }}>
        <Text
          style={{
            width: 40,
            textAlign: "center",
            fontSize: 12,
            color: "#ffffff",
          }}
        >
          {getFormattedTime(position)}
        </Text>
        <Text
          style={{
            width: 40,
            textAlign: "center",
            fontSize: 12,
            color: "#ffffff",
          }}
        >
          {getFormattedTime(duration)}
        </Text>
      </View>
    </View>
  );
};

I can't seek the Slider progress value. No actions fired, no move.

Without BottomSheet Slider working correct but in renderContent have no action.

Can you suggest what the problem?

Thanks.

hovoaep avatar Nov 02 '20 17:11 hovoaep

Hello guys.

I have this type BottomSheet

 <BottomSheet
              callbackNode={fall}
              ref={sheetRef}
              snapPoints={[99, Dimensions.get("window").height + 50]}
              borderRadius={0}
              renderContent={renderContent}
            />

And in renderContent have this track status component

import React, { useEffect, useState } from "react";
import { View, Text } from "react-native";
import TrackPlayer from "react-native-track-player";
import { useTrackPlayerProgress } from "react-native-track-player/lib/hooks";
import Slider from "@react-native-community/slider";
import useAudio from "../../hooks/useAudio";
import { getFormattedTime } from "../../utils";

export const TrackStatus = () => {
  const { playerConfig } = useAudio();

  //the value of the slider should be between 0 and 1
  const [sliderValue, setSliderValue] = useState(0);

  //flag to check whether the use is sliding the seekbar or not
  const [isSeeking, setIsSeeking] = useState(false);

  //useTrackPlayerProgress is a hook which provides the current position and duration of the track player.
  //These values will update every 250ms
  const { position, duration } = useTrackPlayerProgress(250);

  //this hook updates the value of the slider whenever the current position of the song changes
  useEffect(() => {
    if (!isSeeking && position && duration) {
      setSliderValue(position / duration);
    }
  }, [position, duration]);

  //this function is called when the user starts to slide the seekbar
  const slidingStarted = () => {
    setIsSeeking(true);
  };
  //this function is called when the user stops sliding the seekbar
  const slidingCompleted = async (value) => {
    await TrackPlayer.seekTo(value * duration);
    setSliderValue(value);
    setIsSeeking(false);
  };

  return (
    <View style={{ zIndex: 100000, elevation: 100000 }}>
      <View
        style={{
          flexDirection: "row",
          paddingHorizontal: 0,
          alignItems: "center",
          height: 40,
          zIndex: 1,
          elevation: 1,
          zIndex: 10000000,
          elevation: 100000000,
        }}
      >
        <Slider
          minimumValue={0}
          maximumValue={1}
          thumbTintColor="#ffffff"
          minimumTrackTintColor="#000000"
          maximumTrackTintColor="#808080"
          onSlidingStart={slidingStarted}
          onSlidingComplete={slidingCompleted}
          value={sliderValue}
          style={{ width: "100%", zIndex: 100000, elevation: 100000 }}
        />
      </View>
      <View style={{ flexDirection: "row", justifyContent: "space-between" }}>
        <Text
          style={{
            width: 40,
            textAlign: "center",
            fontSize: 12,
            color: "#ffffff",
          }}
        >
          {getFormattedTime(position)}
        </Text>
        <Text
          style={{
            width: 40,
            textAlign: "center",
            fontSize: 12,
            color: "#ffffff",
          }}
        >
          {getFormattedTime(duration)}
        </Text>
      </View>
    </View>
  );
};

I can't seek the Slider progress value. No actions fired, no move.

Without BottomSheet Slider working correct but in renderContent have no action.

Can you suggest what the problem?

Thanks.

any idea? facing the same issue

ShumGG avatar Nov 25 '20 17:11 ShumGG

Facing the same issue. Any updates?

avgupta456 avatar Nov 29 '20 23:11 avgupta456

@osdnk can you please help us?

hovoaep avatar Nov 30 '20 13:11 hovoaep

@avgupta456 @hovoaep , I solved adding enabledContentGestureInteraction = {false}

ShumGG avatar Nov 30 '20 15:11 ShumGG

@ShumGG it's still not working for me with enabledContentGestureInteraction = {false}

hovoaep avatar Dec 01 '20 09:12 hovoaep

It works when enabledContentGestureInteraction = {false} for me. However, I'm still having trouble dymanically setting it to false becuase of the same issue.

david03g avatar Jan 08 '21 01:01 david03g

I have fixed the issue with enableContentPanningGesture={false}

ajoykarmakar avatar Nov 22 '21 09:11 ajoykarmakar

add enabledContentGestureInteraction={false} in <BottomSheet /> and it's working with me.

zhenguet avatar Feb 15 '22 07:02 zhenguet

I have fixed the issue with enableContentPanningGesture={false}

It worked for me. Thanks a lot!! BTW, this issue was specific to Android devices in my case.

dheeraj-m-kipl avatar Sep 08 '23 10:09 dheeraj-m-kipl