├── .gitignore ├── src ├── index.js ├── colors.js ├── nodeType.js ├── Button.js ├── renderNode.js ├── Badge.js ├── Controls.js └── Swiper.js ├── .npmignore ├── babel.config.js ├── package.json ├── CHANGELOG.md ├── index.d.ts └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | build 3 | node_modules 4 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export { Swiper as default } from './Swiper'; 2 | -------------------------------------------------------------------------------- /src/colors.js: -------------------------------------------------------------------------------- 1 | export default { 2 | primary: '#2089dc', 3 | grey3: '#86939e', 4 | }; 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | package-lock.json 4 | yarn.lock 5 | .gitignore 6 | babel.config.js 7 | -------------------------------------------------------------------------------- /src/nodeType.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types'; 2 | 3 | export const nodeType = PropTypes.oneOfType([ 4 | PropTypes.element, 5 | PropTypes.object, 6 | PropTypes.bool, 7 | PropTypes.func, 8 | ]); 9 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function(api) { 2 | api.cache(true); 3 | return { 4 | presets: ["minify"], 5 | plugins: [ 6 | "@babel/plugin-transform-react-jsx", 7 | "@babel/plugin-proposal-class-properties" 8 | ], 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /src/Button.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Text, TouchableOpacity, View } from 'react-native'; 3 | 4 | export const Button = ({ onPress, title, titleStyle }) => { 5 | return ( 6 | 7 | 8 | {title} 9 | 10 | 11 | ); 12 | }; 13 | -------------------------------------------------------------------------------- /src/renderNode.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export const renderNode = (Component, content, defaultProps) => { 4 | if (content == null || content === false) { 5 | return null; 6 | } 7 | if (React.isValidElement(content)) { 8 | return content; 9 | } 10 | if (typeof content === 'function') { 11 | return content(); 12 | } 13 | // Just in case 14 | if (content === true) { 15 | return ; 16 | } 17 | if (typeof content === 'string' || typeof content === 'number') { 18 | return {content}; 19 | } 20 | return ; 21 | }; 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-web-swiper", 3 | "version": "2.2.4", 4 | "homepage": "https://github.com/reactrondev/react-native-web-swiper#readme", 5 | "types": "./index.d.ts", 6 | "main": "build/index.js", 7 | "license": "MIT", 8 | "keywords": [ 9 | "react-native", 10 | "react-native-web", 11 | "swipe", 12 | "swiper", 13 | "slider" 14 | ], 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/reactrondev/react-native-web-swiper.git" 18 | }, 19 | "scripts": { 20 | "build": "rm -rf build && babel src --out-dir build", 21 | "prepare": "npm run build" 22 | }, 23 | "dependencies": { 24 | "prop-types": "^15.6.2" 25 | }, 26 | "peerDependencies": { 27 | "react-native": "*" 28 | }, 29 | "devDependencies": { 30 | "@babel/cli": "^7.2.3", 31 | "@babel/core": "^7.2.2", 32 | "@babel/plugin-proposal-class-properties": "^7.5.5", 33 | "@babel/plugin-transform-react-jsx": "^7.3.0", 34 | "babel-preset-minify": "^0.5.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | react-native-web-swiper 2 | 3 | # Change Log 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 2.2.4 - 2022-10-02 9 | 10 | - Updated `children` prop type. Support for React 18 @eungwang1 11 | ## 2.2.3 - 2022-01-25 12 | 13 | - Add `isActive` prop. @kopax 14 | - Add `activeIndex` prop to DotComponent. @kopax 15 | - Change DotComponent's generic props. @kopax 16 | 17 | ## 2.2.2 - 2021-12-13 18 | 19 | - Children re-rendering behaviour is updated per #74 by @jarredt 20 | 21 | ## 2.1.6 — 2020-07-27 22 | 23 | - This is a patch for 2.1.4 due to the failure of generating builds 24 | 25 | ## 2.1.5 — 2020-07-27 - DO NOT USE, use 2.1.6 and above instead 26 | 27 | - This is a patch for 2.1.4 due to the failure of generating builds 28 | 29 | ## 2.1.4 — 2020-07-27 - DO NOT USE, use 2.1.6 and above instead 30 | 31 | ### Fixed 32 | 33 | - Correct `gestureEnabled` prop ([#1c2d448](https://github.com/reactrondev/react-native-web-swiper/commit/1c2d448b2b4d882d57bb2a08efdf8522cb917376)) 34 | -------------------------------------------------------------------------------- /src/Badge.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { StyleSheet, Text, View, TouchableOpacity } from 'react-native'; 4 | 5 | import { renderNode } from './renderNode'; 6 | 7 | const Badge = props => { 8 | const { 9 | containerStyle, 10 | textStyle, 11 | badgeStyle, 12 | onPress, 13 | Component = onPress ? TouchableOpacity : View, 14 | value, 15 | theme, 16 | status, 17 | ...attributes 18 | } = props; 19 | 20 | const element = renderNode(Text, value, { 21 | style: StyleSheet.flatten([styles.text, textStyle && textStyle]), 22 | }); 23 | 24 | return ( 25 | 26 | 35 | {element} 36 | 37 | 38 | ); 39 | }; 40 | 41 | Badge.propTypes = { 42 | containerStyle: PropTypes.shape({ 43 | style: PropTypes.any, 44 | }), 45 | badgeStyle: PropTypes.shape({ 46 | style: PropTypes.any, 47 | }), 48 | textStyle: PropTypes.shape({ 49 | style: PropTypes.any, 50 | }), 51 | value: PropTypes.node, 52 | onPress: PropTypes.func, 53 | Component: PropTypes.func, 54 | theme: PropTypes.object, 55 | status: PropTypes.oneOf(['primary', 'success', 'warning', 'error']), 56 | }; 57 | 58 | Badge.defaultProps = { 59 | status: 'primary', 60 | }; 61 | 62 | const size = 18; 63 | const miniSize = 8; 64 | 65 | const styles = { 66 | badge: (theme, status) => ({ 67 | alignSelf: 'center', 68 | minWidth: size, 69 | height: size, 70 | borderRadius: size / 2, 71 | alignItems: 'center', 72 | justifyContent: 'center', 73 | backgroundColor: theme.colors[status], 74 | borderWidth: StyleSheet.hairlineWidth, 75 | borderColor: '#fff', 76 | }), 77 | miniBadge: { 78 | paddingHorizontal: 0, 79 | paddingVertical: 0, 80 | minWidth: miniSize, 81 | height: miniSize, 82 | borderRadius: miniSize / 2, 83 | }, 84 | text: { 85 | fontSize: 12, 86 | color: 'white', 87 | paddingHorizontal: 4, 88 | }, 89 | }; 90 | 91 | export { Badge }; 92 | -------------------------------------------------------------------------------- /src/Controls.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { StyleSheet, Text, View } from 'react-native'; 4 | 5 | import { nodeType } from './nodeType'; 6 | import { renderNode } from './renderNode'; 7 | 8 | import { Badge } from './Badge'; 9 | import { Button } from './Button'; 10 | 11 | import colors from './colors'; 12 | 13 | const cellPositions = [ 14 | 'top-left', 15 | 'top', 16 | 'top-right', 17 | 'left', 18 | 'center', 19 | 'right', 20 | 'bottom-left', 21 | 'bottom', 22 | 'bottom-right', 23 | ]; 24 | 25 | export default class DefaultControls extends React.Component { 26 | dotsPos = (() => this._getPos(this.props.dotsPos, 'bottom', 'right'))(); 27 | prevPos = (() => 28 | this._getPos(this.props.prevPos, 'bottom-left', 'top-right'))(); 29 | nextPos = (() => this._getPos(this.props.nextPos, 'bottom-right'))(); 30 | 31 | constructor(props) { 32 | super(props); 33 | 34 | this._renderRow = this._renderRow.bind(this); 35 | this._renderCell = this._renderCell.bind(this); 36 | this._renderDot = this._renderDot.bind(this); 37 | this._renderButton = this._renderButton.bind(this); 38 | } 39 | 40 | _getPos(prop, horizontalDefault, verticalDefault) { 41 | return prop === false 42 | ? null 43 | : prop 44 | ? prop 45 | : verticalDefault && this.props.vertical 46 | ? verticalDefault 47 | : horizontalDefault; 48 | } 49 | 50 | _renderDot({ isActive, onPress }) { 51 | const { dotProps = {}, dotActiveStyle } = this.props; 52 | const { containerStyle, badgeStyle, ...others } = dotProps; 53 | return ( 54 | 68 | ); 69 | } 70 | 71 | _renderDots() { 72 | const { 73 | vertical, 74 | count, 75 | activeIndex, 76 | dotsTouchable, 77 | dotsWrapperStyle, 78 | DotComponent = this._renderDot, 79 | goTo, 80 | } = this.props; 81 | return ( 82 | 88 | {Array.from({ length: count }, (v, i) => i).map(index => ( 89 | goTo(index)} 95 | /> 96 | ))} 97 | 98 | ); 99 | } 100 | 101 | _renderButton({ type, title, titleStyle, onPress, ...props }) { 102 | return ( 103 |