├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets ├── react-native-stepper-ui-1.png ├── react-native-stepper-ui-2.png └── react-native-stepper-ui-3.png ├── babel.config.js ├── example ├── app.json ├── babel.config.js ├── index.js ├── metro.config.js ├── package.json ├── src │ └── App.tsx ├── webpack.config.js └── yarn.lock ├── package.json ├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .idea 35 | .gradle 36 | local.properties 37 | android.iml 38 | 39 | # Cocoapods 40 | # 41 | example/ios/Pods 42 | 43 | # node.js 44 | # 45 | node_modules/ 46 | npm-debug.log 47 | yarn-debug.log 48 | yarn-error.log 49 | 50 | # BUCK 51 | buck-out/ 52 | \.buckd/ 53 | android/app/libs 54 | android/keystores/debug.keystore 55 | 56 | # Expo 57 | .expo/* 58 | 59 | # generated by bob 60 | lib/ 61 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | yarn.lock 3 | assets 4 | example -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.autoFixOnSave": true, 3 | "eslint.validate": [ 4 | "javascript", 5 | "javascriptreact", 6 | { 7 | "language": "typescript", 8 | "autoFix": true 9 | }, 10 | { 11 | "language": "typescriptreact", 12 | "autoFix": true 13 | } 14 | ], 15 | "editor.formatOnSave": true, 16 | "[javascript]": { 17 | "editor.formatOnSave": false 18 | }, 19 | "[javascriptreact]": { 20 | "editor.formatOnSave": false 21 | }, 22 | "[typescript]": { 23 | "editor.formatOnSave": false 24 | }, 25 | "[typescriptreact]": { 26 | "editor.formatOnSave": false 27 | }, 28 | "editor.codeActionsOnSave": { 29 | "source.fixAll.eslint": true 30 | } 31 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn bootstrap` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn bootstrap 11 | ``` 12 | 13 | While developing, you can run the [example app](/example/) to test your changes. 14 | 15 | To start the packager: 16 | 17 | ```sh 18 | yarn example start 19 | ``` 20 | 21 | To run the example app on Android: 22 | 23 | ```sh 24 | yarn example android 25 | ``` 26 | 27 | To run the example app on iOS: 28 | 29 | ```sh 30 | yarn example ios 31 | ``` 32 | 33 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 34 | 35 | ```sh 36 | yarn typescript 37 | yarn lint 38 | ``` 39 | 40 | To fix formatting errors, run the following: 41 | 42 | ```sh 43 | yarn lint --fix 44 | ``` 45 | 46 | Remember to add tests for your change if possible. Run the unit tests by: 47 | 48 | ```sh 49 | yarn test 50 | ``` 51 | 52 | To edit the Objective-C files, open `example/ios/StepperUiExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-stepper-ui`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativestepperui` under `Android`. 55 | 56 | ### Commit message convention 57 | 58 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 59 | 60 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 61 | - `feat`: new features, e.g. add new method to the module. 62 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 63 | - `docs`: changes into documentation, e.g. add usage example for the module.. 64 | - `test`: adding or updating tests, eg add integration tests using detox. 65 | - `chore`: tooling changes, e.g. change CI config. 66 | 67 | Our pre-commit hooks verify that your commit message matches this format when committing. 68 | 69 | ### Linting and tests 70 | 71 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 72 | 73 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 74 | 75 | Our pre-commit hooks verify that the linter and tests pass when committing. 76 | 77 | ### Scripts 78 | 79 | The `package.json` file contains various scripts for common tasks: 80 | 81 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 82 | - `yarn typescript`: type-check files with TypeScript. 83 | - `yarn lint`: lint files with ESLint. 84 | - `yarn test`: run unit tests with Jest. 85 | - `yarn example start`: start the Metro server for the example app. 86 | - `yarn example android`: run the example app on Android. 87 | - `yarn example ios`: run the example app on iOS. 88 | 89 | ### Sending a pull request 90 | 91 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). 92 | 93 | When you're sending a pull request: 94 | 95 | - Prefer small pull requests focused on one change. 96 | - Verify that linters and tests are passing. 97 | - Review the documentation to make sure it looks good. 98 | - Follow the pull request template when opening a pull request. 99 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 100 | 101 | ## Code of Conduct 102 | 103 | ### Our Pledge 104 | 105 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 106 | 107 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 108 | 109 | ### Our Standards 110 | 111 | Examples of behavior that contributes to a positive environment for our community include: 112 | 113 | - Demonstrating empathy and kindness toward other people 114 | - Being respectful of differing opinions, viewpoints, and experiences 115 | - Giving and gracefully accepting constructive feedback 116 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 117 | - Focusing on what is best not just for us as individuals, but for the overall community 118 | 119 | Examples of unacceptable behavior include: 120 | 121 | - The use of sexualized language or imagery, and sexual attention or 122 | advances of any kind 123 | - Trolling, insulting or derogatory comments, and personal or political attacks 124 | - Public or private harassment 125 | - Publishing others' private information, such as a physical or email 126 | address, without their explicit permission 127 | - Other conduct which could reasonably be considered inappropriate in a 128 | professional setting 129 | 130 | ### Enforcement Responsibilities 131 | 132 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 133 | 134 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 135 | 136 | ### Scope 137 | 138 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 139 | 140 | ### Enforcement 141 | 142 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 143 | 144 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 145 | 146 | ### Enforcement Guidelines 147 | 148 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 149 | 150 | #### 1. Correction 151 | 152 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 153 | 154 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 155 | 156 | #### 2. Warning 157 | 158 | **Community Impact**: A violation through a single incident or series of actions. 159 | 160 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 161 | 162 | #### 3. Temporary Ban 163 | 164 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 165 | 166 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 167 | 168 | #### 4. Permanent Ban 169 | 170 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 171 | 172 | **Consequence**: A permanent ban from any sort of public interaction within the community. 173 | 174 | ### Attribution 175 | 176 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 177 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 178 | 179 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 180 | 181 | [homepage]: https://www.contributor-covenant.org 182 | 183 | For answers to common questions about this code of conduct, see the FAQ at 184 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 185 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 danilrafiqi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-stepper-ui 2 | 3 | [![Platform](https://img.shields.io/badge/platform-react--native-lightgrey.svg)](http://facebook.github.io/react-native/) 4 | [![Version](http://img.shields.io/npm/v/react-native-stepper-ui.svg)](https://www.npmjs.com/package/react-native-stepper-ui) 5 | [![Download](http://img.shields.io/npm/dm/react-native-stepper-ui.svg)](https://www.npmjs.com/package/react-native-stepper-ui) 6 | [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.github.com/danilrafiqi/react-native-stepper-ui/master/LICENSE) 7 | 8 | A simple and fully customizable React Native component to create stepper ui. 9 | 10 | - Work for android and IOS 11 | - Support typescript 12 | - Customizable 13 | 14 | ## Table of contents 15 | 16 | - [react-native-stepper-ui](#react-native-stepper-ui) 17 | - [Table of contents](#table-of-contents) 18 | - [Example](#example) 19 | - [Installation](#installation) 20 | - [Usage](#usage) 21 | - [Props](#props) 22 | 23 | ## Example 24 | 25 | | Example One | Example Two | Example Three | 26 | | :---------------------------------------: | :---------------------------------------: | :---------------------------------------: | 27 | | ![](assets/react-native-stepper-ui-1.png) | ![](assets/react-native-stepper-ui-2.png) | ![](assets/react-native-stepper-ui-3.png) | 28 | 29 | ## Installation 30 | 31 | If using yarn: 32 | 33 | ``` 34 | yarn add react-native-stepper-ui 35 | ``` 36 | 37 | If using npm: 38 | 39 | ``` 40 | npm i react-native-stepper-ui 41 | ``` 42 | 43 | ## Usage 44 | 45 | ```javascript 46 | import React, { useState } from 'react'; 47 | import { Text, View } from 'react-native'; 48 | 49 | import Stepper from 'react-native-stepper-ui'; 50 | 51 | const MyComponent = (props) => { 52 | return ( 53 | 54 | {props.title} 55 | 56 | ); 57 | }; 58 | 59 | const content = [ 60 | , 61 | , 62 | , 63 | ]; 64 | 65 | const App = () => { 66 | const [active, setActive] = useState(0); 67 | 68 | return ( 69 | 70 | setActive((p) => p - 1)} 74 | onFinish={() => alert('Finish')} 75 | onNext={() => setActive((p) => p + 1)} 76 | /> 77 | 78 | ); 79 | }; 80 | 81 | export default App; 82 | ``` 83 | 84 | ## Props 85 | 86 | | Name | Type | Description | Default | 87 | | ------------------ | :------------: | ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | 88 | | `active` | number | index stepper active | `undefined` | 89 | | `content` | ReactElement[] | Component that render to stepper | `undefined` | 90 | | `onNext` | Function | Function called when the next step button is pressed | `undefined` | 91 | | `onBack` | Function | Function called when the back step button is pressed | `undefined` | 92 | | `onFinish` | Function | Function called when the finish step button is pressed | `undefined` | 93 | | `wrapperStyle?` | ViewStyle | Wrapper component style | `{}` | 94 | | `stepStyle?` | ViewStyle | Step component style | `{backgroundColor: '#1976d2', width: 30, height: 30, borderRadius: 30, justifyContent: 'center', alignItems: 'center', opacity: 1}` | 95 | | `stepTextStyle?` | TextStyle | Step Text component style | `{color: 'white'}` | 96 | | `buttonStyle?` | ViewStyle | Button component style | `{ padding: 10, borderRadius: 4, alignSelf: 'flex-start', marginRight: 10, backgroundColor: '#a1a1a1'}` | 97 | | `buttonTextStyle?` | TextStyle | Button Text component style | `{color: 'white'}` | 98 | | `showButton?` | boolean | show button | `true` | 99 | -------------------------------------------------------------------------------- /assets/react-native-stepper-ui-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilrafiqi/react-native-stepper-ui/a82cdfe7ff561844b53d1ab41f1af26562dde9e3/assets/react-native-stepper-ui-1.png -------------------------------------------------------------------------------- /assets/react-native-stepper-ui-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilrafiqi/react-native-stepper-ui/a82cdfe7ff561844b53d1ab41f1af26562dde9e3/assets/react-native-stepper-ui-2.png -------------------------------------------------------------------------------- /assets/react-native-stepper-ui-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilrafiqi/react-native-stepper-ui/a82cdfe7ff561844b53d1ab41f1af26562dde9e3/assets/react-native-stepper-ui-3.png -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-stepper-ui-example", 3 | "displayName": "StepperUi Example", 4 | "expo": { 5 | "name": "react-native-stepper-ui-example", 6 | "slug": "react-native-stepper-ui-example", 7 | "description": "Example app for react-native-stepper-ui", 8 | "privacy": "public", 9 | "version": "1.0.0", 10 | "platforms": [ 11 | "ios", 12 | "android", 13 | "web" 14 | ], 15 | "ios": { 16 | "supportsTablet": true 17 | }, 18 | "assetBundlePatterns": [ 19 | "**/*" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = function (api) { 5 | api.cache(true); 6 | 7 | return { 8 | presets: ['babel-preset-expo'], 9 | plugins: [ 10 | [ 11 | 'module-resolver', 12 | { 13 | alias: { 14 | // For development, we want to alias the library to the source 15 | [pak.name]: path.join(__dirname, '..', pak.source), 16 | }, 17 | }, 18 | ], 19 | ], 20 | }; 21 | }; 22 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { registerRootComponent } from 'expo'; 2 | 3 | import App from './src/App'; 4 | 5 | // registerRootComponent calls AppRegistry.registerComponent('main', () => App); 6 | // It also ensures that whether you load the app in the Expo client or in a native build, 7 | // the environment is set up appropriately 8 | registerRootComponent(App); 9 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/blacklist'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-stepper-ui-example", 3 | "description": "Example app for react-native-stepper-ui", 4 | "version": "0.0.1", 5 | "private": true, 6 | "main": "index", 7 | "scripts": { 8 | "android": "expo start --android", 9 | "ios": "expo start --ios", 10 | "web": "expo start --web", 11 | "start": "expo start", 12 | "test": "jest" 13 | }, 14 | "dependencies": { 15 | "expo": "^38.0.0", 16 | "expo-splash-screen": "^0.3.1", 17 | "react": "16.11.0", 18 | "react-dom": "16.11.0", 19 | "react-native": "0.62.2", 20 | "react-native-unimodules": "~0.10.1", 21 | "react-native-web": "^0.12.3" 22 | }, 23 | "devDependencies": { 24 | "@babel/core": "^7.9.6", 25 | "@babel/runtime": "^7.9.6", 26 | "babel-plugin-module-resolver": "^4.0.0", 27 | "babel-preset-expo": "^8.2.3", 28 | "expo-cli": "^3.21.12" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { Alert, Text, View } from 'react-native'; 3 | import Stepper from 'react-native-stepper-ui'; 4 | 5 | const MyComponent = (props: { title: string }) => { 6 | return ( 7 | 8 | {props.title} 9 | 10 | ); 11 | }; 12 | 13 | const content = [ 14 | , 15 | , 16 | , 17 | ]; 18 | 19 | const App = () => { 20 | const [active, setActive] = useState(0); 21 | 22 | return ( 23 | 24 | setActive((p) => p - 1)} 28 | onFinish={() => Alert.alert('Finish')} 29 | onNext={() => setActive((p) => p + 1)} 30 | /> 31 | 32 | ); 33 | }; 34 | 35 | export default App; 36 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const createExpoWebpackConfigAsync = require('@expo/webpack-config'); 3 | const { resolver } = require('./metro.config'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const node_modules = path.join(__dirname, 'node_modules'); 7 | 8 | module.exports = async function (env, argv) { 9 | const config = await createExpoWebpackConfigAsync(env, argv); 10 | 11 | config.module.rules.push({ 12 | test: /\.(js|ts|tsx)$/, 13 | include: path.resolve(root, 'src'), 14 | use: 'babel-loader', 15 | }); 16 | 17 | // We need to make sure that only one version is loaded for peerDependencies 18 | // So we alias them to the versions in example's node_modules 19 | Object.assign(config.resolve.alias, { 20 | ...resolver.extraNodeModules, 21 | 'react-native-web': path.join(node_modules, 'react-native-web'), 22 | }); 23 | 24 | return config; 25 | }; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-stepper-ui", 3 | "version": "0.1.0", 4 | "description": "Stepper Component for React Native", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/src/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "react-native-stepper-ui.podspec", 17 | "!lib/typescript/example", 18 | "!**/__tests__", 19 | "!**/__fixtures__", 20 | "!**/__mocks__" 21 | ], 22 | "scripts": { 23 | "test": "jest", 24 | "typescript": "tsc --noEmit", 25 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 26 | "prepare": "bob build", 27 | "release": "release-it", 28 | "example": "yarn --cwd example", 29 | "pods": "cd example && pod-install --quiet", 30 | "bootstrap": "yarn example && yarn && yarn pods" 31 | }, 32 | "keywords": [ 33 | "react-native", 34 | "ios", 35 | "android" 36 | ], 37 | "repository": "https://github.com/danilrafiqi/react-native-stepper-ui", 38 | "author": "danilrafiqi (https://github.com/danilrafiqi)", 39 | "license": "MIT", 40 | "bugs": { 41 | "url": "https://github.com/danilrafiqi/react-native-stepper-ui/issues" 42 | }, 43 | "homepage": "https://github.com/danilrafiqi/react-native-stepper-ui#readme", 44 | "devDependencies": { 45 | "@commitlint/config-conventional": "^8.3.4", 46 | "@react-native-community/bob": "^0.16.2", 47 | "@react-native-community/eslint-config": "^2.0.0", 48 | "@release-it/conventional-changelog": "^1.1.4", 49 | "@types/jest": "^26.0.0", 50 | "@types/react": "^16.9.19", 51 | "@types/react-native": "0.62.13", 52 | "commitlint": "^8.3.5", 53 | "eslint": "^7.2.0", 54 | "eslint-config-prettier": "^6.11.0", 55 | "eslint-plugin-prettier": "^3.1.3", 56 | "husky": "^4.2.5", 57 | "jest": "^26.0.1", 58 | "pod-install": "^0.1.0", 59 | "prettier": "^2.0.5", 60 | "react": "16.11.0", 61 | "react-native": "0.62.2", 62 | "release-it": "^13.5.8", 63 | "typescript": "^3.8.3" 64 | }, 65 | "peerDependencies": { 66 | "react": "*", 67 | "react-native": "*" 68 | }, 69 | "jest": { 70 | "preset": "react-native", 71 | "modulePathIgnorePatterns": [ 72 | "/example/node_modules", 73 | "/lib/" 74 | ] 75 | }, 76 | "husky": { 77 | "hooks": { 78 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 79 | "pre-commit": "yarn lint && yarn typescript" 80 | } 81 | }, 82 | "commitlint": { 83 | "extends": [ 84 | "@commitlint/config-conventional" 85 | ] 86 | }, 87 | "release-it": { 88 | "git": { 89 | "commitMessage": "chore: release ${version}", 90 | "tagName": "v${version}" 91 | }, 92 | "npm": { 93 | "publish": true 94 | }, 95 | "github": { 96 | "release": true 97 | }, 98 | "plugins": { 99 | "@release-it/conventional-changelog": { 100 | "preset": "angular" 101 | } 102 | } 103 | }, 104 | "eslintConfig": { 105 | "extends": [ 106 | "@react-native-community", 107 | "prettier" 108 | ], 109 | "rules": { 110 | "prettier/prettier": [ 111 | "error", 112 | { 113 | "quoteProps": "consistent", 114 | "singleQuote": true, 115 | "tabWidth": 2, 116 | "trailingComma": "es5", 117 | "useTabs": false 118 | } 119 | ] 120 | } 121 | }, 122 | "eslintIgnore": ["node_modules/", "lib/"], 123 | "prettier": { 124 | "quoteProps": "consistent", 125 | "singleQuote": true, 126 | "tabWidth": 2, 127 | "trailingComma": "es5", 128 | "useTabs": false 129 | }, 130 | "@react-native-community/bob": { 131 | "source": "src", 132 | "output": "lib", 133 | "targets": ["commonjs", "module", "typescript"] 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, useState, ReactElement, useEffect } from 'react'; 2 | import { 3 | View, 4 | Text, 5 | TouchableOpacity, 6 | ViewStyle, 7 | TextStyle, 8 | ScrollView, 9 | } from 'react-native'; 10 | 11 | export interface StepperProps { 12 | active: number; 13 | content: ReactElement[]; 14 | onNext: Function; 15 | onBack: Function; 16 | onFinish: Function; 17 | wrapperStyle?: ViewStyle; 18 | stepStyle?: ViewStyle; 19 | stepLine?:ViewStyle; 20 | stepTextStyle?: TextStyle; 21 | buttonNextStyle?: ViewStyle; 22 | buttonBackStyle?: ViewStyle; 23 | buttonFinishStyle?: ViewStyle; 24 | buttonTextStyle?: TextStyle; 25 | showButton?: boolean; 26 | nextButtonLabel?: string; 27 | backButtonLabel?: string; 28 | finishButtonLabel?: string; 29 | } 30 | 31 | const search = (keyName: number, myArray: number[]): boolean => { 32 | return myArray.some((val) => val === keyName); 33 | }; 34 | 35 | const Stepper: FC = (props) => { 36 | const { 37 | active, 38 | content, 39 | onBack, 40 | onNext, 41 | onFinish, 42 | wrapperStyle, 43 | stepLine, 44 | stepStyle, 45 | stepTextStyle, 46 | buttonNextStyle, 47 | buttonBackStyle, 48 | buttonFinishStyle, 49 | buttonTextStyle, 50 | showButton = true, 51 | nextButtonLabel, 52 | backButtonLabel, 53 | finishButtonLabel 54 | } = props; 55 | const [step, setStep] = useState([0]); 56 | const pushData = (val: number) => { 57 | setStep((prev) => [...prev, val]); 58 | }; 59 | 60 | const removeData = () => { 61 | setStep((prev) => { 62 | prev.pop(); 63 | return prev; 64 | }); 65 | }; 66 | 67 | useEffect(() => { 68 | if (step[step.length - 1] > active) { 69 | removeData(); 70 | } else { 71 | pushData(active); 72 | } 73 | }, [active]); 74 | 75 | return ( 76 | 77 | 84 | {content.map((_, i) => { 85 | return ( 86 | 87 | {i !== 0 && ( 88 | 97 | )} 98 | 112 | {search(i, step) ? ( 113 | 121 | ✓ 122 | 123 | ) : ( 124 | 132 | {i + 1} 133 | 134 | )} 135 | 136 | 137 | ); 138 | })} 139 | 140 | 141 | {content[active]} 142 | 143 | {showButton && ( 144 | 149 | {active !== 0 && ( 150 | { 164 | // removeData(); 165 | onBack(); 166 | }} 167 | > 168 | { backButtonLabel } 169 | 170 | )} 171 | {content.length - 1 !== active && ( 172 | { 184 | // pushData(active + 1); 185 | onNext(); 186 | }} 187 | > 188 | { nextButtonLabel } 189 | 190 | )} 191 | {content.length - 1 === active && ( 192 | onFinish()} 203 | > 204 | { finishButtonLabel } 205 | 206 | )} 207 | 208 | )} 209 | 210 | ); 211 | }; 212 | 213 | export default Stepper; 214 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "react-native-stepper-ui": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "importsNotUsedAsValues": "error", 11 | "forceConsistentCasingInFileNames": true, 12 | "jsx": "react", 13 | "lib": ["esnext"], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "strict": true, 25 | "target": "esnext" 26 | } 27 | } 28 | --------------------------------------------------------------------------------