Repository: silentcloud/react-native-page-control Branch: master Commit: 48fe527bcd2d Files: 11 Total size: 11.0 KB Directory structure: gitextract_0g9tg8ce/ ├── .babelrc ├── .gitignore ├── .npmignore ├── LICENSE ├── PageControl.js ├── README.md ├── index.android.js ├── index.d.ts ├── index.ios.js ├── index.js └── package.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets": ["react-native"] } ================================================ FILE: .gitignore ================================================ # OSX # .DS_Store .idea # Xcode # build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa .idea *.xcuserstate project.xcworkspace # node.js # node_modules/ npm-debug.log yarn.lock iOS android ================================================ FILE: .npmignore ================================================ # OSX # .DS_Store # Xcode build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa *.xcuserstate # node.js # node_modules/ npm-debug.log iOS android ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2015-2016 silentcloud Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: PageControl.js ================================================ var React = require('react'); var ReactNative = require('react-native'); var PropTypes = require('prop-types'); var createReactClass = require('create-react-class'); var { StyleSheet, View, TouchableWithoutFeedback, ViewPropTypes } = ReactNative; var PageControl = createReactClass({ propTypes: { numberOfPages: PropTypes.number.isRequired, currentPage: PropTypes.number, hidesForSinglePage: PropTypes.bool, pageIndicatorTintColor: PropTypes.string, currentPageIndicatorTintColor: PropTypes.string, indicatorSize: PropTypes.object, indicatorStyle: ViewPropTypes.style, currentIndicatorStyle: ViewPropTypes.style, onPageIndicatorPress: PropTypes.func }, getDefaultProps: function () { return { numberOfPages: 0, currentPage: 0, hidesForSinglePage: false, pageIndicatorTintColor: 'gray', currentPageIndicatorTintColor: 'white', indicatorSize: {width: 8, height: 8}, indicatorStyle: {}, currentIndicatorStyle: {}, onPageIndicatorPress: function() {} }; }, onPageIndicatorPress: function(idx) { this.props.onPageIndicatorPress(idx); }, render: function () { var { style, ...props } = this.props; var defaultStyle = { height: this.props.indicatorSize.height }; var indicatorItemStyle = { width: this.props.indicatorSize.width, height: this.props.indicatorSize.height, borderRadius: this.props.indicatorSize.height / 2, marginLeft: 5, marginRight: 5 }; var indicatorStyle = { ...indicatorItemStyle, ...this.props.indicatorStyle, ...{ backgroundColor: this.props.pageIndicatorTintColor } }; var currentIndicatorStyle = { ...indicatorItemStyle, ...this.props.currentIndicatorStyle, ...{ backgroundColor: this.props.currentPageIndicatorTintColor } }; var pages = []; for (var i = 0; i < this.props.numberOfPages; i++) { pages.push(i); } return ( this.props.hidesForSinglePage && pages.length <= 1 ? null : {pages.map((el, i) => )} ); } }); var styles = StyleSheet.create({ container: { backgroundColor: 'transparent', alignItems: 'center', justifyContent: 'center', flexDirection: 'row' } }); module.exports = PageControl; ================================================ FILE: README.md ================================================ # react-native-page-control Page Control for React Native, like iOS UIPageControl, APIs are same as UIPageControl ## Installation ```bash $ npm install react-native-page-control --save ``` ## Demo ![page control demo](http://silentcloud.github.io/upload/pagecontrol.gif) ## Example ```jsx import PageControl from 'react-native-page-control'; ``` ## API (props) | Prop | Required | Default | Type | Description | | :------------ |:---:|:---------------:| :---------------:| :-----| | numberOfPages | YES | `0` | `number` | The number of pages the receiver shows (as dots) | | currentPage | NO | `0` | `number` |The current page, shown by the receiver as a white dot | | hidesForSinglePage | NO | `false` | `bool` | A Boolean value that controls whether the page control is hidden when there is only one page | | pageIndicatorTintColor | NO | `gray` | `string` | The tint color to be used for the page indicator. | | currentPageIndicatorTintColor | NO |`white` | `string` | The tint color to be used for the current page indicator. | | indicatorStyle | NO | `{}` | `object` | style for the page indicator | | currentIndicatorStyle | NO |`{}` | `object` | style for the current page indicator. | | onPageIndicatorPress | NO | function(index){} | `func` | page indicator press hook function. `param: index` current press indicator index| ## Development ```bash $ yarn $ npm run init $ npm run start $ react-native run-ios ``` ================================================ FILE: index.android.js ================================================ require('./index.ios'); ================================================ FILE: index.d.ts ================================================ declare interface Props { /** Style for the current page indicator. */ currentIndicatorStyle?: object /** * The current page, shown by the receiver as a white dot. * * @default 0 */ currentPage?: number /** * The tint color to be used for the page indicator. * * @default 'white' */ currentPageIndicatorTintColor?: string /** * Whether the page control is hidden when there is only one page. * * @default false */ hidesForSinglePage?: boolean /** * Size of the page indicator. * * @default { width: 8, height: 8 } */ indicatorSize?: { width: number, height: number } /** Style for the page indicator. */ indicatorStyle?: object /** The number of pages the receiver shows (as dots). */ numberOfPages: number /** Callback when a specifc page indicator is pressed. */ onPageIndicatorPress?: (index: number) => void /** * The tint color to be used for the page indicator. * * @default 'gray' */ pageIndicatorTintColor?: string /** Style for the page control container. */ style?: object } declare const PageControl: React.FC export = PageControl ================================================ FILE: index.ios.js ================================================ /** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { AppRegistry, ScrollView, StyleSheet, View, Text } = ReactNative; var screen = require('Dimensions').get('window'); var createReactClass = require('create-react-class'); var PageControl = require('./'); var PageControlDemo = createReactClass({ getInitialState: function () { return { currentPage: 0 }; }, onScroll: function(event){ var offsetX = event.nativeEvent.contentOffset.x, pageWidth = screen.width - 10; this.setState({ currentPage: Math.floor((offsetX - pageWidth / 2) / pageWidth) + 1 }); }, onItemTap: function(index) { console.log(index); }, render: function() { return ( page1 page2 page3 ); } }); var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center' }, scrollView: { backgroundColor:'yellow' } }); AppRegistry.registerComponent('index', () => PageControlDemo); ================================================ FILE: index.js ================================================ var PageControl = require('./PageControl'); module.exports = PageControl; ================================================ FILE: package.json ================================================ { "name": "react-native-page-control", "version": "1.1.1", "description": "React native page control, like ios UIPageControl", "author": "silentcloud", "repository": { "type": "git", "url": "https://github.com/silentcloud/react-native-page-control.git" }, "keywords": [ "react", "react-native", "react-component", "page-control", "PageControl", "UIPageControl" ], "files": [ "index.d.ts", "index.js", "PageControl.js" ], "main": "index.js", "types": "index.d.ts", "readmeFilename": "README.md", "license": "MIT", "bugs": { "url": "https://github.com/silentcloud/react-native-page-control/issues" }, "homepage": "https://github.com/silentcloud/react-native-page-control", "dependencies": { "create-react-class": "^15.6.0", "prop-types": "^15.5.10" }, "devDependencies": { "babel-preset-react-native": "^2.1.0", "rc-tools": "6.x", "react": "^15.5.0", "react-dom": "^15.5.0", "react-native": "~0.42.0", "react-native-index-page": "~0.2.0" }, "scripts": { "init": "rc-tools run react-native-init", "start": "react-native start" } }