简体   繁体   English

如何在 React-native 中以时间格式制作 RangeSlider?

[英]How to make a RangeSlider in time format in React-native?

In my React-native project , I am using a RangeSlider.在我的 React-native 项目中,我使用的是 RangeSlider。 According to the documentation from the below link-根据以下链接中的文档-

https://www.npmjs.com/package/rn-range-slider https://www.npmjs.com/package/rn-range-slider

I worked with this code-我使用此代码-

    <RangeSlider
    style={{width: 160, height: 80}}
    gravity={'center'}
    min={200}
    max={1000}
    step={20}
    selectionColor="#3df"
    blankColor="#f618"
    onValueChanged={(low, high, fromUser) => {
        this.setState({rangeLow: low, rangeHigh: high})
    }}/> 

It works well but the problem is-它运作良好,但问题是 -

I want this slider to work in time format from the range 00:00:00 to 23:59:00我希望这个 slider 能够以00:00:00 到 23:59:00范围内的时间格式工作

from the above mentioned document link, I am not understanding how should I set the valueType and TextFormat .从上面提到的文档链接中,我不明白应该如何设置valueTypeTextFormat

So, I need help to implement the RangeSlider to time format from the Range 00:00:00 to 23:59:00所以,我需要帮助将 RangeSlider 实现为从 Range 00:00:00 到 23:59:00的时间格式

Simply Add as follows valueType='time' textFormat='HH:mm:ss' min={0} max={82744000} and you are good to go.只需添加如下valueType='time' textFormat='HH:mm:ss' min={0} max={82744000}就可以了 go。

I agree, the documentation in this area is vague.我同意,这方面的文档很模糊。 But you have to use a numeric value that would get you closest to the time period you need and 82744000 timestamp will get you there.但是您必须使用一个数值来让您最接近您需要的时间段,并且82744000时间戳会让您到达那里。

To learn more about the text formatting, checkout the links: Android iOS要了解有关文本格式的更多信息,请查看以下链接: Android iOS

    <RangeSlider
        style={{width: 160, height: 80}}
        gravity={'center'}
        min={0}
        max={82744000}
        valueType='time'
        textFormat='HH:mm:ss'
        step={20}
        selectionColor="#3df"
        blankColor="#f618"
        onValueChanged={(low, high, fromUser) => {
            this.setState({rangeLow: low, rangeHigh: high})
        }}
    /> 

You can do it like this:你可以这样做:

<RangeSlider
  valueType="time"
  step={60000}
/>
import React, { Component } from 'react';

class YourComponent extends Component {

    constructor(props) {
        super(props);

        const now = new Date(1995, 11, 31, 0, 0, 0, 0);
        this.state = {
            broadcasting: false,
            astbeltProgress: 0,
            rangeLow: now,
            rangeHigh: now,
            min: now,
            max: new Date(now.getTime() + 1000 * 60 * 60 * 24-1),
        };
    }

    render() {
        const { broadcasting, astbeltProgress, rangeLow, rangeHigh, min, max } = this.state
        return (
            <View style={styles.container}>

                <RangeSlider
                    valueType="time"
                    ref={component => this._slider = component}
                    gravity={'center'}
                    labelStyle={'bubble'}
                    style={{width: screenWidth, height: 70}}
                    min={min}
                    max={max}
                    selectionColor="#3df"
                    blankColor="#f618"
                    step={1}
                    textFormat="HH:mm"
                    onValueChanged={(low, high, fromUser) => {
                        this.setState({rangeLow: low, rangeHigh: high})
                    }}
                />


            </View>
        );
    }
}

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

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