1.1.3 • Published 7 years ago

nativescript-na-slider v1.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

NativeScript NA Slider plugin

NOTE! Android is currently not supported.

A NativeScript slider. The successor of my previous, deprecated slideshow plugin, nativescript-na-slideshow.

Installation

$ tns plugin add nativescript-na-slider

Usage

Slides can be added statically inside the XML as below:

<Page xmlns:NASlider="nativescript-na-slider">
  
  <NASlider:NASlider id="slider">
    <NASlider:NASliderContainer>
      <NASlider:NASliderSlide>
        <Label text="Slide 1" />
      </NASlider:NASliderSlide>
      <NASlider:NASliderSlide>
        <Label text="Slide 2" />
      </NASlider:NASliderSlide>
      <NASlider:NASliderSlide>
        <Label text="Slide 3" />
      </NASlider:NASliderSlide>
    </NASlider:NASliderContainer>
  </NASlider:NASlider>
  
</Page>

Using <Repeater>

For a more dynamic slider, a <Repeater> can be used:

<Page xmlns:NASlider="nativescript-na-slider">
  
  <NASlider:NASlider items="{{ slides }}">
    <Repeater>
      <Repeater.itemsLayout>
        <NASlider:NASliderContainer />
      </Repeater.itemsLayout>
      <Repeater.itemTemplate>
        <NASlider:NASliderSlide>
          <Label text="{{ text }}" />
        </NASlider:NASliderSlide>
      </Repeater.itemTemplate>
    </Repeater>
  </NASlider:NASlider>
  
</Page>

This way, a slider can simply be set up with an ObservableArray. The <NASliderContainer> will act as the Repeater's itemsLayout, while a <NASliderSlide> becomes the wrapper itemTemplate of the Repeater.

Properties

<NASlider>

PropertyTypeDescription
bounceBoolean (default: false)Gets or sets scroll bouncing effect.
currentSlideView<NASliderSlide> (read-only)Gets the current slide view.
currentSlideIndexInteger (read-only)Gets the current slide index.
forceFirstIndicatorVisibilityBoolean (default: false)Gets or sets the visibility of the first indicator if there is only one slide available.
showIndicatorsBoolean (default: true)Gets or sets the indicators' visibility.
indicatorBorderColorString (default: "#404040")Gets or sets indicators' border color.
indicatorBorderWidthFloat (default: 0)Gets or sets indicators' border width.
indicatorColorString (default: "808080")Gets or sets the indicator color for all slides.
indicatorColorActiveString (default: null)Gets or sets the indicator color for all slides when active (current visible slide).
indicatorHorizontalAlignmentString (default: null)Gets or sets indicators' horizontal alignment. Overrides indicatorPosition property.
indicatorPositionString (default: "bottom")Gets or sets indicators' position.
indicatorSizeFloat (default: 8)Gets or sets indicators' size.
indicatorVerticalAlignmentString (default: null)Gets or sets indicators' vertical alignment. Overrides indicatorPosition property.
itemsArray (default: undefined)Gets or sets the items array for a <Repeater>.
orientationString (default: "horizontal")Gets or sets the slider orientation. Can be either "horizontal" or "vertical".
scrollPositionFloat (read-only)Gets the current scroll position.
slidesCountInteger (read-only)Gets the total amount of slides.

<NASliderSlide>

PropertyTypeDescription
indicatorColorString (default: null)Gets or sets the indicator color for specific slide.
indicatorColorActiveString (default: null)Gets or sets the indicator color for specific slide when active (current visible slide).

Methods

getSlideAt

getSlideAt(index: integer): <NASliderSlide>

Returns the slide at specified index.

ParameterTypeDescription
indexIntegerThe index position of the slide to return.

insertSlide

insertSlide(view: <View>, props: object): Promise<NASliderSlide>

Insert new slide with optional properties. Returns a Promise with the new slide.

ParameterTypeDescription
view<View>The view to insert as slide.
propsObject (optional)Optional properties.
props
PropertyTypeDescription
atIndexInteger (default: this.slidesCount)Sets the index position. If not specified, the slide will become last.
indicatorColorString (default: null)Sets the indicator color for specific slide.
indicatorColorActiveString (default: null)Sets the indicator color for specific slide when active (current visible slide).

removeSlide

removeSlide(slide: <NASliderSlide>): Promise

Remove the specified slide. Returns a Promise.

ParameterTypeDescription
slide<NASliderSlide>The slide to remove.

removeSlideAt

removeSlideAt(index : integer): Promise

Remove slide at specified index. Returns a Promise.

ParameterTypeDescription
indexIntegerThe index position of the slide to remove.

removeSlides

removeSlides(): Promise

Removes all slides. Returns a Promise.

Will not work if <NASlider> instance is maintained by a Repeater.


scrollToSlideAt

scrollToSlideAt(index : integer, animated : boolean): void

Scrolls to slide at specified index. Animated or not.

ParameterTypeDescription
indexIntegerThe slide to remove.
animatedBoolean (default: false)Animates the scrolling effect.

Events

The following events can be observed with on() and addEventListener():

slide

Fired when sliding.

Event data
PropertyTypeDescription
eventNameStringGets the name of the event.
objectObjectGets the <NASlider> instance.
scrollPositionFloatGets the current scroll position. Will be either the horizontal or vertical position depending on orientation of the <NASlider> instance.

slideChange

Fired when the <NASlider> instance has changed slide.

Event data
PropertyTypeDescription
eventNameStringGets the name of the event.
objectObjectGets the <NASlider> instance.
slide<NASliderSlide>Gets the current visible slide.

Known issues

  • No Android compatibility, yet.

History

Version 1.1.3 (February 10, 2017)

  • Fixed crash when navigating within the frame's backstack.

Version 1.1.2 (February 8, 2017)

  • Stability improvements.
  • Slides should now dynamically adapt to slider's dimensions.

Version 1.1.0 (February 7, 2017)

  • removeAllSlides method has been renamed to removeSlides.
  • Fixed Repeater not working as expected. Check documentation for the new way to use <NASlider>.

Version 1.0.2 (February 6, 2017)

  • Documentation fixes.

Version 1.0.0 (February 6, 2017)

  • First release!

Credits

License

MIT - for {N} version 2.5.0+

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago