react-native-multi-slider icon indicating copy to clipboard operation
react-native-multi-slider copied to clipboard

Slider Smoothness inside Modal.

Open rajeevrocker7 opened this issue 5 years ago • 13 comments

Steps to Reproduce

Create a Component CustomModal for Modal,

in constructor(props) { super(props); this.state = { selectedMin: 1, selectedMax: 5 };

}

and inside that component CustomModal's render() -->

render() {

    return (
        <Modal
            ref={ref => this.modalRef = ref}
            animationType="none"
            transparent={true}
            animated={true}
            hardwareAccelerated={true}
            style={[containerStyle]}>

            <View style={overlayCon}
                ref={ref => { this.overLayRef = ref; }}>

                <MultiSlider
                    values={[
                        this.state.selectedMin,
                        this.state.selectedMax
                    ]}
                    sliderLength={isPlatformANDROID ? widthScale(270) : widthScale(270)}
                    onValuesChange={this.sliderOnValuesChange}
                    min={1}
                    max={5}
                    step={1}
                    allowOverlap={false}
                    snapped={true}
                    minMarkerOverlapDistance={56}
                    customMarker={CustomMarker}
                    touchDimensions={{
                        height: 40,
                        width: 40,
                        borderRadius: 20,
                        slipDisplacement: 40
                    }}
                    selectedStyle={{ backgroundColor: COLORS_.PRIMARY_GREEN_BLUE }}
                    unselectedStyle={{ backgroundColor: COLORS_.SLIDER_GREY_FILTER }}
                    enabledOne={true}
                    enabledTwo={true}
                    containerStyle={{
                        width: widthScale(270),
                        height: heightScale(12),
                        marginTop: heightScale(16),
                        alignSelf: 'center',
                        justifyContent: 'center',
                        backgroundColor: COLORS_.FULL_TRANSPARENT
                    }}
                />

            </View>
        </Modal>
    );

}

Expected Behavior

MultiSlider should be smooth, even it is snapped inside a Modal.

Actual Behavior

@ptomasroos MultiSlider not smooth, even it is snapped inside a Modal. touchDimensions not actually works.. it is quite hard to touch and drag it inside a modal.

rajeevrocker7 avatar May 17 '19 07:05 rajeevrocker7

We are experiencing the same issue, have you ever found a fix to this?

mwillems1994 avatar Feb 20 '20 15:02 mwillems1994

same for me

edritech93 avatar Apr 21 '20 04:04 edritech93

Me too...I think it has something to do with blocking the gesture or pan responder...something related to that...I'm going to try to see if I can wrap it with some kind of View with some options on it, will report back.

Aryk avatar May 03 '20 20:05 Aryk

This hack made it work for me. I basically uncontrolled the component...

import React, {useState} from "react";
import MultiSlider from "@ptomasroos/react-native-multi-slider/MultiSlider";

// Super hacky fix for https://github.com/ptomasroos/react-native-multi-slider/issues/124
// Perhaps when it gets fixed we won't have to resort this awful hack...
const ModalSafeMultiSlider = ({
  values: initialValues,
  onValuesChange: _onValuesChange,
  onValuesChangeFinish: _onValuesChangeFinish,
  ...props
}: any) => {
  const [lastValues, setLastValues] = useState(initialValues);
  const [values, setValues]         = useState(initialValues);

  const onValuesChangeFinish = (v) => {
    setValues(lastValues);
    if (_onValuesChangeFinish) _onValuesChangeFinish(v);
  };

  const onValuesChange = (v) => {
    setLastValues(v);
    if (_onValuesChange) _onValuesChange(v);
  };

  return <MultiSlider {...props} {...{values, onValuesChangeFinish, onValuesChange}} />;
};

export { ModalSafeMultiSlider };

Aryk avatar May 06 '20 19:05 Aryk

use onValuesChangeFinish instead of onValuesChange works for me.

skynetcmg47 avatar Aug 05 '20 16:08 skynetcmg47

use onValuesChangeFinish instead of onValuesChange works for me.

Right but that is completely different behavior especially if you need a function to run while the user is moving the slider (like with a debounce).

My solution is the only working solution if you want that behavior.

Aryk avatar Aug 05 '20 18:08 Aryk

I tried @Aryk's solution and can't get it to work. multi slider won't slide correctly inside of a modal. does anyone have any solutions to this problem? I need a slider with multiple a min/max otherwise Id use @react-native-community/slider. here is a GIF of the problem:

bug

here is my code:

import React, { useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import MultiSlider from '@ptomasroos/react-native-multi-slider';
import Slider from '@react-native-community/slider';

// Super hacky fix for https://github.com/ptomasroos/react-native-multi-slider/issues/124
// Perhaps when it gets fixed we won't have to resort this awful hack...
const ModalSafeMultiSlider = ({
  values: initialValues,
  onValuesChange: _onValuesChange,
  onValuesChangeFinish: _onValuesChangeFinish,
  ...props
}) => {
  const [lastValues, setLastValues] = useState(initialValues);
  const [values, setValues] = useState(initialValues);

  const onValuesChangeFinish = (v) => {
    setValues(lastValues);
    if (_onValuesChangeFinish) _onValuesChangeFinish(v);
  };

  const onValuesChange = (v) => {
    setLastValues(v);
    if (_onValuesChange) _onValuesChange(v);
  };

  return <MultiSlider {...props} {...{ values, onValuesChangeFinish, onValuesChange }} />;
};

const Filters = () => {
  const [max, setMax] = useState(10);
  const [min, setMin] = useState(0);
  return (
    <View style={styles.container}>
      <Text>@ptomasroos/react-native-multi-slider (does not work)</Text>
      <ModalSafeMultiSlider
        values={[min, max]}
        min={0}
        max={10}
        snapped={false}
        allowOverlap
      />
      <Text>@react-native-community/slider (works correctly)</Text>
      <Slider
        style={{ width: 200, height: 40 }}
        minimumValue={0}
        maximumValue={1}
        minimumTrackTintColor="#FFFFFF"
        maximumTrackTintColor="#000000"
        step={0.1}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    padding: 100,
    alignItems: 'center',
  },
});

export default Filters;

KyleAsaff avatar Jan 03 '21 19:01 KyleAsaff

@KyleAsaff If that is react-native-bottom-sheet, you should disable its content panning gesture. In other words:

enableContentPanningGesture={false}

Then the multi-slider will work.

barahonam1 avatar Jun 20 '21 16:06 barahonam1

Any solution for this. Facing the same issue in ios with modal. Also tried gestureEnabled={false}

urvashichhabra avatar Aug 05 '21 06:08 urvashichhabra

@KyleAsaff If that is react-native-bottom-sheet, you should disable its content panning gesture. In other words:

enableContentPanningGesture={false}

Then the multi-slider will work.

Thanks, @barahonam1. It was exactly my scenario and your suggestion worked!

wilmersondasilva avatar Oct 26 '21 17:10 wilmersondasilva

Any solution for this. Facing the same issue in ios with modal. Also tried gestureEnabled={false}

Anyone find solution for this?

igorwessel avatar Nov 04 '21 11:11 igorwessel

Same problem with react navigation'a modal iOS Any solution? Tried gesturesEnabled but did not work

kanelloc avatar Mar 19 '22 14:03 kanelloc

@KyleAsaff If that is react-native-bottom-sheet, you should disable its content panning gesture. In other words:

enableContentPanningGesture={false}

Then the multi-slider will work.

Yes but that kills the ability to pan down to close.

Aryk avatar Nov 26 '22 18:11 Aryk