@adalo/react-native-multi-slider 中文文档教程

发布于 3 年前 浏览 9 项目主页 更新于 2 年前

react-native-multi-slider

纯 JS 反应本机滑块组件与一个或两个标记。 用于自定义轨道、触摸区域并为触摸事件和值更改提供客户标记和回调的选项。

Examples

cd example/Basic
npm install
react-native run-ios
react-native run-android

Example

Getting Started

Installation

$ npm install --save @ptomasroos/react-native-multi-slider

Usage in a ScrollView

 enableScroll = () => this.setState({ scrollEnabled: true });
 disableScroll = () => this.setState({ scrollEnabled: false });

 render() {
   return (
     <ScrollView scrollEnabled={this.state.scrollEnabled}>
      <MultiSlider
        ...
        onValuesChangeStart={this.disableScroll}
        onValuesChangeFinish={this.enableScroll}
      />
    </ScrollView>
    );

shape up CustomMarker as left and right

为了在标记上制作不同的样式,您可以设置isMarkersSeparated 为true,在MultiSlider 中定义customMarkerLeft 和customMarkerRight。 例如:

<MultiSlider
    ...
    isMarkersSeparated={true}

    customMarkerLeft={(e) => {
         return (<CustomSliderMarkerLeft
          currentValue={e.currentValue}/>)
    }}

    customMarkerRight={(e) => {
         return (<CustomSliderMarkerRight
         currentValue={e.currentValue}/>)
    }}
/>

Partial report of the props

随时为文档的这一部分做出贡献。

Prop nameDefault valueTypePurpouse
values[0]array of numbersPrefixed values of the slider.
onValuesChangeStart() => {}functionCallback when the value starts changing
onValuesChange() => {}functionCallback when the value changes
onValuesChangeFinish(values) => {}functionCallback when the value stops changing
sliderLength280numberLength of the slider (?)
touchDimensions{height: 50,width: 50,borderRadius: 15,slipDisplacement: 200}object(?)
enableLabelfunctionEnable the label rendering
customLabelfunctionComponent used for rendering a label above the cursors.
customMarkerfunctionComponent used for the cursor.
customMarkerLeftfunctionComponent used for the left cursor.
customMarkerRightfunctionComponent used for the right cursor.
isMarkersSeparatedbooleanSee explaination above in the README.md
min0numberMinimum value available in the slider.
max10numberMaximum value available in the slider.
step1numberStep value of the slider.
optionsArrayarray of numbersPossible values of the slider. Ignores min and max.
{container/track/selected/unselected/ markerContainer/marker/pressedMarker} Stylestyle objectStyles for the slider
valuePrefixstringPrefix added to the value.
valueSuffixstringSuffix added to the value.
enabledOnetruebooleanEnables the first cursor
enabledTwotruebooleanEnables the second cursor
onToggleOneundefinedfunction callbackListener when first cursor toggles.
onToggleTwoundefinedfunction callbackListener when second cursor toggles.
allowOverlapfalsebooleanAllow the overlap within the cursors.
snappedfalsebooleanUse this when you want a fixed position for your markers, this will split the slider in N specific positions
verticalfalsebooleanUse vertical orientation instead of horizontal.
markerOffsetX0numberOffset the cursor(s) on the X axis
markerOffsetY0numberOffset the cursor(s) on the Y axis
minMarkerOverlapDistance0numberif this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other. This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near.
imageBackgroundSourceundefinedstringSpecifies the source as required by ImageBackground

react-native-multi-slider

Pure JS react native slider component with one or two markers. Options to customize track, touch area and provide customer markers and callbacks for touch events and value changes.

Examples

cd example/Basic
npm install
react-native run-ios
react-native run-android

Example

Getting Started

Installation

$ npm install --save @ptomasroos/react-native-multi-slider

Usage in a ScrollView

 enableScroll = () => this.setState({ scrollEnabled: true });
 disableScroll = () => this.setState({ scrollEnabled: false });

 render() {
   return (
     <ScrollView scrollEnabled={this.state.scrollEnabled}>
      <MultiSlider
        ...
        onValuesChangeStart={this.disableScroll}
        onValuesChangeFinish={this.enableScroll}
      />
    </ScrollView>
    );

shape up CustomMarker as left and right

In order to make different styles on markers you can set isMarkersSeparated to true, define customMarkerLeft and customMarkerRight in MultiSlider. for example:

<MultiSlider
    ...
    isMarkersSeparated={true}

    customMarkerLeft={(e) => {
         return (<CustomSliderMarkerLeft
          currentValue={e.currentValue}/>)
    }}

    customMarkerRight={(e) => {
         return (<CustomSliderMarkerRight
         currentValue={e.currentValue}/>)
    }}
/>

Partial report of the props

Feel free to contribute to this part of the documentation.

Prop nameDefault valueTypePurpouse
values[0]array of numbersPrefixed values of the slider.
onValuesChangeStart() => {}functionCallback when the value starts changing
onValuesChange() => {}functionCallback when the value changes
onValuesChangeFinish(values) => {}functionCallback when the value stops changing
sliderLength280numberLength of the slider (?)
touchDimensions{height: 50,width: 50,borderRadius: 15,slipDisplacement: 200}object(?)
enableLabelfunctionEnable the label rendering
customLabelfunctionComponent used for rendering a label above the cursors.
customMarkerfunctionComponent used for the cursor.
customMarkerLeftfunctionComponent used for the left cursor.
customMarkerRightfunctionComponent used for the right cursor.
isMarkersSeparatedbooleanSee explaination above in the README.md
min0numberMinimum value available in the slider.
max10numberMaximum value available in the slider.
step1numberStep value of the slider.
optionsArrayarray of numbersPossible values of the slider. Ignores min and max.
{container/track/selected/unselected/ markerContainer/marker/pressedMarker} Stylestyle objectStyles for the slider
valuePrefixstringPrefix added to the value.
valueSuffixstringSuffix added to the value.
enabledOnetruebooleanEnables the first cursor
enabledTwotruebooleanEnables the second cursor
onToggleOneundefinedfunction callbackListener when first cursor toggles.
onToggleTwoundefinedfunction callbackListener when second cursor toggles.
allowOverlapfalsebooleanAllow the overlap within the cursors.
snappedfalsebooleanUse this when you want a fixed position for your markers, this will split the slider in N specific positions
verticalfalsebooleanUse vertical orientation instead of horizontal.
markerOffsetX0numberOffset the cursor(s) on the X axis
markerOffsetY0numberOffset the cursor(s) on the Y axis
minMarkerOverlapDistance0numberif this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other. This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near.
imageBackgroundSourceundefinedstringSpecifies the source as required by ImageBackground
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文