简体   繁体   English

如何创建范围滑块? (反应天然)

[英]How to create range slider? (react-native)

This is my range slider 这是我的范围滑块

But for change values user need to click on this value. 但是对于更改值,用户需要单击此值。 How to make, to be able to pull the slider? 如何制作,能够拉动滑块? Thanks. 谢谢。

If I were you, without any doubt, I'd search for a library to do the heavy lifting for me. 如果我是你,毫无疑问,我会寻找一个图书馆为我做繁重的工作。

Assuming you need cross-platform (iOS and Android) range slider solution, based on my research by the time of writing this answer, the plugin which gave the best results in terms of performance on both platforms and customizability options is @ptomasroos/react-native-multi-slider . 假设您需要跨平台(iOS和Android)范围滑块解决方案,根据我在编写本答案时的研究,在两个平台和可定制选项上的性能方面都能获得最佳结果的插件是@ ptomasroos / react-原生多滑块

It lacks good documentation, but there is example available . 它缺乏良好的文档,但有可用的例子 Here's the basic set-up: 这是基本设置:

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

class RangeSlider extends React.Component {
    state = {
        values: [3, 7],
    };

    multiSliderValuesChange = (values) => {
        this.setState({
            values,
        });
    }

    render() {
        return (
            <View>
                <MultiSlider
                    values={[this.state.values[0], this.state.values[1]]}
                    sliderLength={280}
                    onValuesChange={this.multiSliderValuesChange}
                    min={0}
                    max={10}
                    step={1}
                />
                <Text style={styles.text}>Two Markers:</Text>
                <Text style={styles.text}>{this.state.values[0]}</Text>
                <Text style={styles.text}>{this.state.values[1]}</Text>
            </View>
        )
    }
}

The creator of react-native-range-slider is here! react-native-range-slider的创建者就在这里!

You can use this module which is implemented natively and then ported to react-native, thus the great performance and smooth animation. 你可以使用这个本机实现的模块,然后移植到本地反应,从而获得出色的性能和流畅的动画效果。

here is an example: 这是一个例子:

import RangeSlider from 'react-native-range-slider'

<View style={{flex: 1, flexDirection: 'row'}}>
  <RangeSlider
    minValue={0}
    maxValue={100}
    tintColor={'#da0f22'}
    handleBorderWidth={1}
    handleBorderColor="#454d55"
    selectedMinimum={20}
    selectedMaximum={40}
    style={{ flex: 1, height: 70, padding: 10, backgroundColor: '#ddd' }}
    onChange={ (data)=>{ console.log(data);} }
  />
</View>

The only limitation and downside here is that it is only for iOS (currently). 这里唯一的限制和缺点是它仅适用于iOS (当前)。

You'll want to use PanResponder. 你会想要使用PanResponder。 Check out the UIExplorer demo for PanResponder. 查看PanResponder的UIExplorer演示。 http://www.reactnative.com/uiexplorer/ http://www.reactnative.com/uiexplorer/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM