• Stars
    star
    260
  • Rank 157,189 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸŒ²β˜€οΈ Customizable, lightweight React Native carousel component with accessibility support.

Pinar

Customizable, lightweight React Native carousel component with accessibility support.


Platform - Android and iOS NPM version Build Status Tests - Unit and e2e Downloads per month contributions welcome

Pinar is a lightweight and customizable React Native carousel component that works well when creating simple image sliders or app onboarding flows.

If you need more advanced things like animations, lazy loading of images, or parallax, then please consider using a library like react-native-reanimated-carousel.

Table of contents

Install

yarn add pinar --save

## or
## npm install pinar --save

Basic example

import React from "react";
import { Text, View } from "react-native";
import Carousel from "pinar";

const styles = {
  slide1: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#a3c9a8"
  },
  slide2: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#84b59f"
  },
  slide3: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#69a297"
  },
  text: {
    color: "#1f2d3d",
    opacity: 0.7,
    fontSize: 48,
    fontWeight: "bold"
  }
};

export default () => (
  <Carousel>
    <View style={styles.slide1}>
      <Text style={styles.text}>1</Text>
    </View>
    <View style={styles.slide2}>
      <Text style={styles.text}>2</Text>
    </View>
    <View style={styles.slide3}>
      <Text style={styles.text}>3</Text>
    </View>
  </Carousel>
);

Result:

Basic carousel example

More examples

The /examples folder has a React Native app that you can run on your machine to see the carousel being used with a lot of different options.

If you don't want to run the app, you can have a look at the components folder for example components.

Properties

Basic carousel properties

Property Default Type Description
horizontal true boolean Set to false for a vertical carousel.
loop false boolean Set to true to enable continuous loop mode.
index 0 number Index number of initial slide.
showsControls true boolean Set to false to hide prev/next buttons.
showsDots true boolean Set to false to hide pagination dots.
autoplay false boolean Set to true enable autoplay mode.
autoplayInterval 3000 number Delay between autoplay page changes (in milliseconds).
width - number If not specified, the default fullscreen mode is enabled using flex: 1.
height - number If not specified, the default fullscreen mode is enabled using flex: 1.
accessibility true boolean Set to false to disable accessibility features (not recommended).
accessibilityLabelPrev Previous string Accessibility label for the prev button.
accessibilityLabelNext Next string Accessibility label for the next button.
mergeStyles false boolean Set to true to merge your custom styles with the default styles.

Callbacks

Use these properties to be notified when the user scrolls the carousel or changes the page.

Property Parameters Type Description
onIndexChanged ({ index, total }) => void function Called with the new page index when the user changes a page.
onLayout (event) => void function Called when layout changes for the main <View> wrapper element.
onScroll (event) => void function Called when <ScrollView> is scrolled.
onMomentumScrollEnd (event) => void function Called when <ScrollView>'s momentum scroll finishes.

Methods

To use methods you need to get a reference to the carousel inside your React class component.

<Carousel
  ref={carousel => {
    this.carousel = carousel;
  }}
/>

You can then call the method from outside the carousel:

<Button
  title="scroll to next page"
  onPress={() => {
    this.carousel.scrollToNext();
  }}
/>
Method Arguments Type Description
scrollToPrev None function Scroll to the previous page.
scrollToNext None function Scroll to the next page.
scrollBy {index: number, animated: boolean} function Scroll by a number of pages. The number can be negative to scroll backwards.
scrollToIndex {index: number, animated: boolean} function Scroll to a page index (0 based).
startAutoplay None function Starts carousel autoplay.
stopAutoplay None function Stops carousel autoplay.

Custom styling properties

Use these properties to customize how the carousel is styled.

Set the mergeStyles property to true if you want to merge your custom styles with the default ones instead of having define all the needed styles. You can also import { defaulStyles } from "pinar" to get access to the default styles and use them as defaults.

Have a look at the "custom styles" component and "custom styles with merge" component for an example.

Property Default Type Description
style {...} StyleProp<ViewStyle> See default style in the source code.
ScrollView
containerStyle {...} StyleProp<ViewStyle> See default style in the source code.
contentContainerStyle {...} StyleProp<ViewStyle> See default container style in the source code.
Prev/Next buttons
controlsContainerStyle {...} StyleProp<ViewStyle> Custom style for the prev/next buttons container.
controlsButtonStyle {...} StyleProp<ViewStyle> Custom style for the prev/next button.
controlsTextStyle {...} StyleProp<TextStyle> Custom style for the prev/next button text.
Pagination dots
dotsContainerStyle {...} StyleProp<ViewStyle> Custom style for the pagination dots container.
dotStyle {...} StyleProp<ViewStyle> Custom style for a single pagination dot.
activeDotStyle {...} StyleProp<ViewStyle> Custom style for the active pagination dot.

Custom render properties

Use these properties to provide your own functions render custom elements instead of the default ones. Have a look at the custom rendering component for an example.

Property Function parameters Type Description
Pagination dots
renderDots ({ index, total, context }) => void function Use to render custom pagination dots.
renderDot ({ index }) => void function Use to render custom dot (not active).
renderActiveDot ({ index }) => void function Use to render custom active dot.
Prev/Next buttons
renderControls ({ scrollToPrev, scrollToNext }) => void function Use to render custom prev/next controls.
renderPrev ({ scrollToPrev }) => void function Use to render custom prev control.
renderNext ({ scrollToNext }) => void function Use to render custom next control.

Properties of <ScrollView />

These properties are exposed from <ScrollView />. You can provide your own properties if you want to customize it.

Property Default Type Description
automaticallyAdjustContentInsets false bool Controls whether iOS should automatically adjust the content inset for scroll views that are placed behind a navigation bar or tab bar/ toolbar.
bounces false bool If true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the alwaysBounce* props are true.
contentContainerStyle undefined StyleProp<ViewStyle> These styles will be applied to the scroll view content container which wraps all of the child views.
onMomentumScrollEnd undefined function Called when the momentum scroll ends (scroll which occurs as the ScrollView glides to a stop).
onScroll undefined function Fires at most once per frame during scrolling. The frequency of the events can be controlled using the scrollEventThrottle prop.
pagingEnabled true bool When true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination.
removeClippedSubviews true bool When true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen. This can improve scrolling performance on long lists.
scrollEnabled true bool When false, the view cannot be scrolled via touch interaction.
scrollEventThrottle 16 number This controls how often the scroll event will be fired while scrolling (as a time interval in ms). A lower number yields better accuracy for code that is tracking the scroll position, but can lead to scroll performance problems due to the volume of information being send over the bridge. You will not notice a difference between values set between 1-16 as the JS run loop is synced to the screen refresh rate. If you do not need precise scroll position tracking, set this value higher to limit the information being sent across the bridge.
scrollsToTop false bool When true, the scroll view scrolls to top when the status bar is tapped.
showsHorizontalScrollIndicator false bool When true, shows a horizontal scroll indicator. The default value is true.
showsVerticalScrollIndicator false bool When true, shows a vertical scroll indicator. The default value is true.

for more info: http://facebook.github.io/react-native/docs/scrollview.html

Dependencies

No other dependencies than React Native.

Development

If you want help out with the development of this library, bug reports and fixes are very welcome. If you are thinking about a new feature, please open a feature request issue first to verify that implementing it makes sense.

How to develop locally

First make sure that you have Node.js, Yarn and React Native installed. It is also a good idea to have Xcode and/or Android Studio installed to be able to run the iOS simulators / Android emulators.

If you choose to install emulators or simulators, you can use the example app to test your changes in a React Native app.

Automated tests

When making changes to the code, please add a unit test or a functional test to verify that the code is working. The test runner that the project uses is Jest, Enzyme is used to test React Components, and Detox is used to run functional tests against the project's example app. The command to run unit tests is yarn test and the command to run functional tests is yarn functional.

Before you submit the code for a Pull Request, make sure that you run yarn test, yarn tsc, and yarn lint to verify that unit tests pass and both the Typescript type checking and ESLint linting are not printing any errors.

Special thanks

Special thanks for these libraries for providing inspiration for code and other things:


License

MIT

More Repositories

1

react-native-svg-transformer

Import SVG files in your React Native project the same way that you would in a Web application.
JavaScript
1,236
star
2

react-native-css-modules

Style React Native components using CSS, PostCSS, Sass, Less or Stylus.
290
star
3

normalize.scss

SCSS version of normalize.css
CSS
261
star
4

react-native-sass-transformer

Use Sass to style your React Native apps.
JavaScript
202
star
5

awesome-bundle-size

πŸ“ An awesome list of tools and techniques to make your web bundle size smaller and your web apps load faster.
182
star
6

umatrix-recipes

"uMatrix Recipes" is a collection of rules for uMatrix that you can use to fix some popular websites by whitelisting the 3rd-party requests that are critical for the websites to function.
99
star
7

stylelint-declaration-block-no-ignored-properties

Disallow property values that are ignored due to another property value in the same rule.
JavaScript
90
star
8

css-to-react-native-transform

Turn valid CSS into React Native Stylesheet objects.
JavaScript
86
star
9

stylelint-high-performance-animation

Stylelint rule for preventing the use of low performance animation and transition properties.
JavaScript
64
star
10

stylelint-react-native

A collection of React Native specific linting rules for stylelint (in a form of a plugin).
JavaScript
56
star
11

react-native-css-transformer

Use CSS to style your React Native apps.
JavaScript
34
star
12

react-native-svg-example

A simple example app that shows how you can use SVG files in React Native
Java
31
star
13

iOSBadge

iOS style notification badges for web
CoffeeScript
28
star
14

react-native-less-transformer

Use Less to style your React Native apps.
JavaScript
27
star
15

stylelint-config-react-native-styled-components

Shareable stylelint config for styled components when using React Native
JavaScript
26
star
16

react-native-css-modules-with-typescript-example

A simple example app that shows how you can use CSS modules + Typescript with React Native and React (for browser)
Java
18
star
17

stylelint-z-index-value-constraint

Stylelint rule for setting minimum and maximum constraint value for z-index.
JavaScript
18
star
18

react-native-css-modules-with-media-queries-example

An example app to show how CSS Media Queries work in React Native.
JavaScript
18
star
19

react-native-postcss-transformer

Use PostCSS to style your React Native apps.
JavaScript
17
star
20

react-native-css-modules-example

A simple example app that shows how you can use CSS modules with React Native and React (for browser)
JavaScript
15
star
21

travis-chrome

An example repo to show how to run tests with Karma runner using Chrome browser (with Xvfb) in Travis CI
JavaScript
14
star
22

karma-bdd-using

DRY your Karma + Jasmine or Mocha tests using the data provider pattern
JavaScript
14
star
23

react-native-stylus-transformer

Use Stylus to style your React Native apps.
JavaScript
13
star
24

babel-plugin-react-native-platform-specific-extensions

Allow react-native platform specific extensions to be used for other file types than Javascript.
JavaScript
13
star
25

react-native-types-for-css-modules

React Native Typescript types with an extra added type: className property
Ruby
13
star
26

react-native-css-media-query-processor

Match style objects containing CSS Media Queries with React Native
JavaScript
12
star
27

babel-plugin-react-native-classname-to-dynamic-style

Transform JSX className property to a style property that gets calculated at runtime in React Native. The plugin is used to match style objects containing parsed CSS media queries and CSS viewport units with React Native.
JavaScript
12
star
28

HTML-newsletter-builder

A command line tool to help build and preprocess email newsletters
JavaScript
12
star
29

jQuery-Geolocator

A Geolocation API plugin for jQuery or Zepto
JavaScript
12
star
30

babel-plugin-react-native-classname-to-style

Transform JSX className property to style property in react-native.
JavaScript
10
star
31

observable-redux-json-api

Observables + Redux + JSON API
TypeScript
8
star
32

css-calc-transform

Tiny Javascript library to transform CSS properties with calc() function values to pixels based on window and element dimensions.
JavaScript
8
star
33

react-native-typed-sass-transformer

Sass transformer with Typescript support for React Native
JavaScript
7
star
34

babel-plugin-react-native-stylename-to-style

Transform styleName property to style property in react-native.
JavaScript
7
star
35

react-native-dynamic-style-processor

React Native dynamic style processor combines multiple runtime style transformations together.
JavaScript
6
star
36

placekeeper

Placekeeper is a HTML5 placeholder attribute polyfill for old browsers that lack support for it.
JavaScript
6
star
37

react-native-svg-expo-example

JavaScript
6
star
38

stylelint-config-react-native-css-modules

Shareable stylelint config for React Native CSS modules
JavaScript
5
star
39

bdd-using

DRY your Jasmine or Mocha tests using the data provider pattern
JavaScript
5
star
40

react-native-css-modules-stylename-example

A simple example app that shows how you can use CSS modules + styleName syntax with React Native and React (for browser)
JavaScript
4
star
41

observable-redux-json-api-typescript-example

A minimal example to show how to use observable-redux-json-api library using React, Typescript and Express.js.
JavaScript
3
star
42

react-native-orientation-change-provider

Simple React Native Provider component that forces a re-render when orientation changes.
JavaScript
3
star
43

css-viewport-units-transform

Transform CSS viewport units of a Javascript style object to pixels based on window dimensions
JavaScript
3
star
44

react-native-known-styling-properties

List of React Native specific styling properties.
JavaScript
3
star
45

react-native-typed-less-transformer

Less transformer with Typescript support for React Native
JavaScript
3
star
46

react-native-typed-postcss-transformer

PostCSS transformer with Typescript support for React Native
JavaScript
2
star
47

css-mod-stylus-setup

Objective-C
2
star
48

react-native-typed-css-transformer

CSS transformer with Typescript support for React Native
JavaScript
2
star
49

css-calc-proof-of-concept

An app for doing a proof of concept for using CSS calc() function in React Native
Java
2
star
50

react-native-0.59-svg-example

An example of using react-native-svg-transformer in React Native 0.59.x
Objective-C
2
star
51

rn-svg-rendering-issues

Objective-C
1
star
52

react-native-ios-13-view-or-image-inside-text-bug

Objective-C
1
star
53

react-native-text-transform-issue

A demo app to reproduce a bug with textTransform on Android
Objective-C
1
star
54

react-native-css-modules-with-viewport-units-example

An example app to show how CSS Viewport Units work in React Native.
Objective-C
1
star
55

adventures-in-webkit-land

JavaScript
1
star
56

react-native-typed-stylus-transformer

Stylus transformer with Typescript support for React Native
JavaScript
1
star
57

package-updater

JavaScript
1
star
58

rn-svg-crash

Objective-C
1
star
59

pinar-example-app

TypeScript
1
star
60

expo-scss-test

Objective-C
1
star
61

Test-iOS-Travis-CI

Test iOS Travis CI
Objective-C
1
star
62

react-native-css-modules-dss-example

Example app to show how to use DSS (https://dss-lang.com) and React Native CSS modules together
JavaScript
1
star
63

react-native-svg-debug-0.59.5

Objective-C
1
star
64

helsinkijs-may-2013-talk

JavaScript
1
star
65

observable-redux-json-api-example

A minimal example to show how to use observable-redux-json-api library using React and Express.js.
JavaScript
1
star