├── .circleci └── config.yml ├── .editorconfig ├── .eslintrc.js ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .yarnrc ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── example ├── app.json ├── babel.config.js ├── index.js ├── metro.config.js ├── package.json ├── src │ └── App.js ├── webpack.config.js └── yarn.lock ├── index.d.ts ├── package.json ├── scripts └── bootstrap.js ├── src ├── Steve.js ├── __tests__ │ └── index.test.tsx └── index.js ├── tsconfig.build.json ├── 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 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'eslint:recommended', 4 | 'plugin:react/recommended' 5 | ], 6 | root: true, 7 | rules: { 8 | 'comma-dangle': 'off', 9 | semi: [2, 'never'], 10 | indent: ['error', 4, { SwitchCase: 1 }], 11 | 'no-trailing-spaces': 'error', 12 | 'arrow-parens': 'off', 13 | 'react/prop-types': 'off', 14 | 'no-extra-semi': 'error', 15 | 'react/display-name': [2, { 'ignoreTranspilerName': true }], 16 | 'react/jsx-max-props-per-line': [1, { maximum: 1, when: 'multiline' }], 17 | 'react/jsx-one-expression-per-line': [2, { 'allow': 'none' }], 18 | 'react/jsx-sort-props': [ 19 | 2, 20 | { 21 | 'callbacksLast': false, 22 | 'shorthandFirst': false, 23 | 'shorthandLast': false, 24 | 'ignoreCase': false, 25 | 'noSortAlphabetically': true 26 | } 27 | ], 28 | 'react/boolean-prop-naming': [ 29 | 'error', 30 | { 31 | 'propTypeNames': ['bool'], 32 | 'rule': '^(is|has)[A-Z]([A-Za-z0-9]?)+', 33 | 'message': 'It is better if your prop ({{ propName }}) matches this pattern: ({{ pattern }})', 34 | 'validateNested': true 35 | } 36 | ], 37 | 'react/default-props-match-prop-types': [2, { 'allowRequiredDefaults': true }], 38 | 'react/jsx-curly-newline': [ 39 | 'error', 40 | { 41 | multiline: 'consistent', 42 | singleline: 'consistent' 43 | } 44 | ], 45 | 'react/jsx-handler-names': [ 46 | 'error', 47 | { 48 | checkLocalVariables: true, 49 | checkInlineFunction: true 50 | } 51 | ], 52 | 'react/jsx-indent-props': ['error', 4], 53 | 'react/jsx-props-no-multi-spaces': 'error', 54 | 'react/jsx-sort-default-props': 'error', 55 | 'react/jsx-tag-spacing': [ 56 | 'error', 57 | { 58 | 'beforeSelfClosing': 'never', 59 | 'beforeClosing': 'never' 60 | } 61 | ], 62 | 'react/jsx-wrap-multilines': [ 63 | 'error', 64 | { 65 | 'declaration': 'parens-new-line', 66 | 'assignment': 'parens-new-line', 67 | 'return': 'parens-new-line', 68 | 'arrow': 'parens-new-line', 69 | 'condition': 'parens-new-line', 70 | 'logical': 'parens-new-line', 71 | 'prop': 'parens-new-line' 72 | } 73 | ], 74 | 'react/prefer-stateless-function': 'error' 75 | }, 76 | parser: 'babel-eslint', 77 | settings: { 78 | 'import/resolver': { 79 | node: { 80 | extensions: ['.js', '.jsx', '.d.ts', '.ts', '.tsx'], 81 | moduleDirectory: ['node_modules', 'src'] 82 | } 83 | }, 84 | 'react': { 85 | 'createClass': 'createReactClass', 86 | 'pragma': 'React', 87 | 'fragment': 'Fragment', 88 | 'flowVersion': '0.53', 89 | 'version': '16.13.1' 90 | }, 91 | 'propWrapperFunctions': [ 92 | 'forbidExtraProps', 93 | { 'property': 'freeze', 'object': 'Object' }, 94 | { 'property': 'withDisplayName' } 95 | ], 96 | 'linkComponents': [ 97 | 'Hyperlink', 98 | { 'name': 'Link', 'linkAttribute': 'to' } 99 | ] 100 | }, 101 | 'env': { 102 | 'node': true, 103 | jest: true, 104 | es6: true 105 | } 106 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | # This workflow contains a single job called "build" 17 | release: 18 | # The type of runner that the job will run on 19 | runs-on: ubuntu-latest 20 | name: release 21 | 22 | # Steps represent a sequence of tasks that will be executed as part of the job 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v2 26 | with: 27 | fetch-depth: 0 28 | 29 | - name: Cache node_modules 30 | uses: actions/cache@v2 31 | with: 32 | path: '**/node_modules' 33 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} 34 | 35 | - name: Install packages 36 | run: yarn install 37 | 38 | - name: git config 39 | run: | 40 | git config user.name $GIT_USER 41 | git config user.email $GIT_EMAIL 42 | env: 43 | GIT_USER: ${{ secrets.GIT_USER }} 44 | GIT_EMAIL: ${{ secrets.GIT_EMAIL }} 45 | 46 | - name: npm config 47 | run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc 48 | env: 49 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 50 | 51 | - name: Release ${{ github.event.inputs.version }} 52 | run: yarn release 53 | env: 54 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /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` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 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/SteveExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-steve`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativesteve` 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, e.g. 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 Fatih Tasdemir 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-steve 2 | 3 | React Native horizontal scroll view component as seen on Clubhouse tags 4 | 5 | ![BUM](https://media.giphy.com/media/FFq4lKeqeAIFrh7CrI/giphy.gif) 6 | 7 | ## Installation 8 | 9 | ```sh 10 | npm install react-native-steve 11 | ``` 12 | 13 | or 14 | 15 | ```sh 16 | yarn add react-native-steve 17 | ``` 18 | 19 | ## Dependencies 20 | This library requires [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated) and [react-native-gesture-handler](https://github.com/software-mansion/react-native-gesture-handler) 21 | 22 | ### Important 23 | 24 | > This component uses [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/docs) v2 stable version so in order to use this component your app must be configured for reanimated v2 25 | 26 | ## Usage 27 | 28 | ```javascript 29 | import React from 'react' 30 | import { StyleSheet, Text, View } from 'react-native' 31 | import Steve from 'react-native-steve' 32 | 33 | const topics = [ 34 | { 35 | emoji: '🍻', 36 | text: 'Entertainment' 37 | }, 38 | { 39 | emoji: '🐈', 40 | text: 'Cats' 41 | }, 42 | { 43 | emoji: '🦾', 44 | text: 'Robots' 45 | }, 46 | { 47 | emoji: '🎉', 48 | text: 'Party' 49 | }, 50 | { 51 | emoji: '🌍', 52 | text: 'World' 53 | }, 54 | { 55 | emoji: '📚', 56 | text: 'Books' 57 | }, 58 | { 59 | emoji: '👘', 60 | text: 'Fashion' 61 | }, 62 | { 63 | emoji: '📱', 64 | text: 'Applications' 65 | }, 66 | { 67 | emoji: '📸', 68 | text: 'Photography' 69 | }, 70 | { 71 | emoji: '🧠', 72 | text: 'Ideas' 73 | }, 74 | { 75 | emoji: '⚔️', 76 | text: 'War' 77 | }, 78 | { 79 | emoji: '💼', 80 | text: 'Business' 81 | }, 82 | { 83 | emoji: '🎭', 84 | text: 'Theater' 85 | }, 86 | { 87 | emoji: '📮', 88 | text: 'Job' 89 | } 90 | ] 91 | 92 | export default function App() { 93 | const { 94 | topicContainer, 95 | topicText, 96 | title, 97 | container, 98 | steveContainer 99 | } = styles 100 | 101 | const renderTopic = ({ item }) => { 102 | const { emoji, text } = item 103 | return ( 104 | 105 | 106 | {emoji} 107 | 108 | 109 | {text} 110 | 111 | 112 | ) 113 | } 114 | 115 | return ( 116 | 117 | 118 | {'TOPICS TO EXPLORE'} 119 | 120 | item.text}/> 127 | 128 | ) 129 | } 130 | 131 | App.displayName = 'App' 132 | 133 | const styles = StyleSheet.create({ 134 | container: { 135 | flex: 1, 136 | backgroundColor: '#FFF', 137 | justifyContent: 'center' 138 | }, 139 | topicContainer: { 140 | borderWidth: 1, 141 | borderColor: '#ecd9d9', 142 | borderBottomWidth: 2, 143 | borderRadius: 10, 144 | paddingHorizontal: 10, 145 | height: 38, 146 | justifyContent: 'center', 147 | alignItems: 'center', 148 | flexDirection: 'row', 149 | backgroundColor: '#FFF' 150 | }, 151 | topicText: { 152 | fontSize: 14, 153 | fontWeight: '500', 154 | marginLeft: 5 155 | }, 156 | title: { 157 | fontSize: 13, 158 | color: 'rgb(134,130,119)', 159 | marginBottom: 5, 160 | marginLeft: 15, 161 | fontWeight: '600' 162 | }, 163 | steveContainer: { marginHorizontal: 5 } 164 | }) 165 | ``` 166 | 167 | ## Props 168 | 169 | | name | required | type | default | description | 170 | | ------------------------- | -------- | ---- | ------- | ------------| 171 | | data | yes | Array | | An array of items to render 172 | | renderItem | yes | Function | | Function that returns a component with given item and index. It is similar to FlatList's renderItem prop | 173 | |keyExtractor| yes | Function| | Function that returns an unique key for each item in the array. Notice that it is a must to provide a unique key since it's used to make calculations|| 174 | |containerStyle|no|Style Object| | Style object for root component | 175 | |isRTL|no|boolean|false|Whether the component is RTL layout| 176 | |itemStyle|no|Style Object| |Style object for parent component of each child| 177 | 178 | ## Contributing 179 | 180 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 181 | 182 | ## License 183 | 184 | MIT 185 | 186 | ## Author 187 | 188 | #### [tsdmrfth](https://twitter.com/tsdmrfth) 189 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'] 3 | } 4 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-steve-example", 3 | "displayName": "Steve Example", 4 | "expo": { 5 | "name": "react-native-steve-example", 6 | "slug": "react-native-steve-example", 7 | "description": "Example app for react-native-steve", 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 | extensions: ['.tsx', '.ts', '.js', '.json'], 14 | alias: { 15 | [pak.name]: path.join(__dirname, '..', pak.source) 16 | } 17 | } 18 | ], 19 | 'react-native-reanimated/plugin' 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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-steve-example", 3 | "description": "Example app for react-native-steve", 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": "^41.0.0-beta.2", 16 | "expo-splash-screen": "~0.10.0", 17 | "react": "16.13.1", 18 | "react-dom": "16.13.1", 19 | "react-native": "0.63.4", 20 | "react-native-gesture-handler": "~1.10.2", 21 | "react-native-reanimated": "~2.1.0", 22 | "react-native-unimodules": "~0.13.0", 23 | "react-native-web": "~0.13.12" 24 | }, 25 | "devDependencies": { 26 | "@babel/core": "~7.9.0", 27 | "@babel/runtime": "^7.9.6", 28 | "babel-plugin-module-resolver": "^4.0.0", 29 | "babel-preset-expo": "8.3.0", 30 | "expo-cli": "^4.0.13" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /example/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { StyleSheet, Text, View } from 'react-native' 3 | import Steve from 'react-native-steve' 4 | 5 | const topics = [ 6 | { 7 | emoji: '🍻', 8 | text: 'Entertainment' 9 | }, 10 | { 11 | emoji: '🐈', 12 | text: 'Cats' 13 | }, 14 | { 15 | emoji: '🦾', 16 | text: 'Robots' 17 | }, 18 | { 19 | emoji: '🎉', 20 | text: 'Party' 21 | }, 22 | { 23 | emoji: '🌍', 24 | text: 'World' 25 | }, 26 | { 27 | emoji: '📚', 28 | text: 'Books' 29 | }, 30 | { 31 | emoji: '👘', 32 | text: 'Fashion' 33 | }, 34 | { 35 | emoji: '📱', 36 | text: 'Applications' 37 | }, 38 | { 39 | emoji: '📸', 40 | text: 'Photography' 41 | }, 42 | { 43 | emoji: '🧠', 44 | text: 'Ideas' 45 | }, 46 | { 47 | emoji: '⚔️', 48 | text: 'War' 49 | }, 50 | { 51 | emoji: '💼', 52 | text: 'Business' 53 | }, 54 | { 55 | emoji: '🎭', 56 | text: 'Theater' 57 | }, 58 | { 59 | emoji: '📮', 60 | text: 'Job' 61 | } 62 | ] 63 | 64 | export default function App() { 65 | const { 66 | topicContainer, 67 | topicText, 68 | title, 69 | container, 70 | steveContainer 71 | } = styles 72 | 73 | const renderTopic = ({ item }) => { 74 | const { emoji, text } = item 75 | return ( 76 | 77 | 78 | {emoji} 79 | 80 | 81 | {text} 82 | 83 | 84 | ) 85 | } 86 | 87 | return ( 88 | 89 | 90 | {'TOPICS TO EXPLORE'} 91 | 92 | item.text}/> 100 | 101 | ) 102 | } 103 | 104 | App.displayName = 'App' 105 | 106 | const styles = StyleSheet.create({ 107 | container: { 108 | flex: 1, 109 | backgroundColor: '#FFF', 110 | justifyContent: 'center' 111 | }, 112 | topicContainer: { 113 | borderWidth: 1, 114 | borderColor: '#ecd9d9', 115 | borderBottomWidth: 2, 116 | borderRadius: 10, 117 | paddingHorizontal: 10, 118 | height: 38, 119 | justifyContent: 'center', 120 | alignItems: 'center', 121 | flexDirection: 'row', 122 | backgroundColor: '#FFF' 123 | }, 124 | topicText: { 125 | fontSize: 14, 126 | fontWeight: '500', 127 | marginLeft: 5 128 | }, 129 | title: { 130 | fontSize: 13, 131 | color: 'rgb(134,130,119)', 132 | marginBottom: 5, 133 | marginLeft: 15, 134 | fontWeight: '600' 135 | }, 136 | steveContainer: { marginHorizontal: 5 } 137 | }) -------------------------------------------------------------------------------- /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|jsx|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 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'react-native-steve' { 2 | import { ViewStyle } from 'react-native'; 3 | 4 | export interface SteveProps { 5 | data: T[], 6 | renderItem: ({item, index}: {item: T, index: number}) => JSX.Element, 7 | keyExtractor: (item: T, index: number) => string, 8 | containerStyle?: ViewStyle, 9 | isRTL?: boolean, 10 | itemStyle?: ViewStyle 11 | } 12 | const Steve: (props: SteveProps) => JSX.Element; 13 | 14 | export default Steve; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-steve", 3 | "version": "0.4.0", 4 | "description": "React Native horizontal scroll view component as seen on Clubhouse tags", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "./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-steve.podspec", 17 | "!lib/typescript/example", 18 | "!android/build", 19 | "!ios/build", 20 | "!**/__tests__", 21 | "!**/__fixtures__", 22 | "!**/__mocks__" 23 | ], 24 | "scripts": { 25 | "test": "jest", 26 | "typescript": "tsc --noEmit", 27 | "lint": "eslint \"src/*.{js,ts,tsx}\"", 28 | "prepare": "bob build", 29 | "release": "release-it", 30 | "example": "yarn --cwd example", 31 | "pods": "cd example && pod-install --quiet", 32 | "bootstrap": "yarn example && yarn && yarn pods" 33 | }, 34 | "keywords": [ 35 | "react-native", 36 | "ios", 37 | "android" 38 | ], 39 | "repository": "https://github.com/tsdmrfth/react-native-steve", 40 | "author": "Fatih Tasdemir (https://github.com/tsdmrfth)", 41 | "license": "MIT", 42 | "bugs": { 43 | "url": "https://github.com/tsdmrfth/react-native-steve/issues" 44 | }, 45 | "homepage": "https://github.com/tsdmrfth/react-native-steve#readme", 46 | "publishConfig": { 47 | "registry": "https://registry.npmjs.org/" 48 | }, 49 | "devDependencies": { 50 | "@commitlint/config-conventional": "^11.0.0", 51 | "@react-native-community/eslint-config": "^2.0.0", 52 | "@release-it/conventional-changelog": "^2.0.0", 53 | "@types/jest": "^26.0.0", 54 | "@types/react": "^16.9.19", 55 | "@types/react-native": "0.62.13", 56 | "commitlint": "^11.0.0", 57 | "eslint": "^7.2.0", 58 | "eslint-config-prettier": "^7.0.0", 59 | "eslint-plugin-prettier": "^3.1.3", 60 | "husky": "^4.2.5", 61 | "jest": "^26.0.1", 62 | "pod-install": "^0.1.0", 63 | "prettier": "^2.0.5", 64 | "react": "16.13.1", 65 | "react-native": "0.63.4", 66 | "react-native-builder-bob": "^0", 67 | "release-it": "^14.2.2", 68 | "typescript": "^4.1.3" 69 | }, 70 | "peerDependencies": { 71 | "react": "*", 72 | "react-native": "*", 73 | "react-native-gesture-handler": "^1.0.0", 74 | "react-native-reanimated": "^2.0.0" 75 | }, 76 | "jest": { 77 | "preset": "react-native", 78 | "modulePathIgnorePatterns": [ 79 | "/example/node_modules", 80 | "/lib/" 81 | ] 82 | }, 83 | "husky": { 84 | "hooks": { 85 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 86 | "pre-commit": "yarn lint && yarn typescript" 87 | } 88 | }, 89 | "commitlint": { 90 | "extends": [ 91 | "@commitlint/config-conventional" 92 | ] 93 | }, 94 | "release-it": { 95 | "git": { 96 | "commitMessage": "chore: release ${version}", 97 | "tagName": "v${version}" 98 | }, 99 | "npm": { 100 | "publish": true 101 | }, 102 | "github": { 103 | "release": true 104 | }, 105 | "plugins": { 106 | "@release-it/conventional-changelog": { 107 | "preset": "angular" 108 | } 109 | } 110 | }, 111 | "react-native-builder-bob": { 112 | "source": "src", 113 | "output": "lib", 114 | "targets": [ 115 | "commonjs", 116 | "module", 117 | [ 118 | "typescript", 119 | { 120 | "project": "tsconfig.build.json" 121 | } 122 | ] 123 | ] 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const child_process = require('child_process') 3 | 4 | const root = path.resolve(__dirname, '..') 5 | const args = process.argv.slice(2) 6 | const options = { 7 | cwd: process.cwd(), 8 | env: process.env, 9 | stdio: 'inherit', 10 | encoding: 'utf-8', 11 | } 12 | 13 | let result 14 | 15 | if (process.cwd() !== root || args.length) { 16 | // We're not in the root of the project, or additional arguments were passed 17 | // In this case, forward the command to `yarn` 18 | result = child_process.spawnSync('yarn', args, options) 19 | } else { 20 | // If `yarn` is run without arguments, perform bootstrap 21 | result = child_process.spawnSync('yarn', ['bootstrap'], options) 22 | } 23 | 24 | process.exitCode = result.status 25 | -------------------------------------------------------------------------------- /src/Steve.js: -------------------------------------------------------------------------------- 1 | import React, { useRef, useState } from 'react' 2 | import Animated, { 3 | useAnimatedGestureHandler, 4 | useSharedValue, 5 | withSpring, 6 | cancelAnimation, 7 | useAnimatedStyle, 8 | withDecay 9 | } from 'react-native-reanimated' 10 | import { Dimensions } from 'react-native' 11 | import { PanGestureHandler } from 'react-native-gesture-handler' 12 | 13 | const { width: screenWidth } = Dimensions.get('window') 14 | 15 | const getContainerHorizontalSpacing = style => { 16 | const { 17 | margin = 0, 18 | marginHorizontal = 0, 19 | marginLeft = 0, 20 | marginRight = 0, 21 | padding = 0, 22 | paddingHorizontal = 0, 23 | paddingLeft = 0, 24 | paddingRight = 0 25 | } = style 26 | return 2 * (margin + marginHorizontal + padding + paddingHorizontal) 27 | + (marginLeft + marginRight + paddingLeft + paddingRight) 28 | } 29 | 30 | export const Steve = ({ data, renderItem, keyExtractor, containerStyle, isRTL, itemStyle }) => { 31 | const itemLayoutsCache = useRef({}) 32 | const [itemLayouts, setItemLayouts] = useState({}) 33 | const containerHorizontalSpacing = getContainerHorizontalSpacing(containerStyle) 34 | const translateX = useSharedValue(0) 35 | const rtlStyle = isRTL ? { flexDirection: 'row-reverse' } : {} 36 | const onGestureEvent = useAnimatedGestureHandler({ 37 | onStart: (event, context) => { 38 | if (context.isDecayAnimationRunning) { 39 | context.isDecayAnimationRunning = false 40 | cancelAnimation(translateX) 41 | } 42 | }, 43 | onActive: (event, context) => { 44 | translateX.value = (context.offset || 0) + event.translationX 45 | }, 46 | onEnd: (event, context) => { 47 | context.offset = translateX.value 48 | const { offset } = context 49 | const { velocityX } = event 50 | const maximumLayerWidth = Math.max(...Object.values(itemLayouts.sumWidthOfLayer)) 51 | const levelDifference = screenWidth - maximumLayerWidth - containerHorizontalSpacing 52 | const leftBound = 0 53 | const rightBound = isRTL ? -levelDifference : levelDifference 54 | const firstCondition = isRTL ? (offset < leftBound) : (offset > leftBound) 55 | const secondCondition = isRTL ? (offset > rightBound) : (offset < rightBound) 56 | 57 | if (firstCondition) { 58 | context.offset = leftBound 59 | translateX.value = withSpring(leftBound, { 60 | velocity: velocityX, 61 | mass: 0.6, 62 | stiffness: 90 63 | }) 64 | } else if (secondCondition) { 65 | context.offset = rightBound 66 | translateX.value = withSpring(rightBound, { 67 | velocity: velocityX, 68 | mass: 0.6, 69 | stiffness: 90 70 | }) 71 | } else { 72 | context.isDecayAnimationRunning = true 73 | let clamp 74 | 75 | if (isRTL) { 76 | if (velocityX < 0) { 77 | clamp = [0, translateX.value] 78 | } else { 79 | clamp = [translateX.value, rightBound] 80 | } 81 | } else { 82 | if (velocityX < 0) { 83 | clamp = [rightBound, translateX.value] 84 | } else { 85 | clamp = [translateX.value, 0] 86 | } 87 | } 88 | 89 | translateX.value = withDecay( 90 | { 91 | velocity: velocityX, 92 | clamp 93 | }, 94 | () => { 95 | context.isDecayAnimationRunning = false 96 | context.offset = translateX.value 97 | } 98 | ) 99 | } 100 | } 101 | }) 102 | 103 | const Items = () => { 104 | return data.map((item, index) => { 105 | const itemKey = keyExtractor(item, index) 106 | return ( 107 | 110 | ) 111 | }) 112 | } 113 | 114 | // eslint-disable-next-line react/display-name 115 | const Item = ({ item, index, itemKey }) => { 116 | const style = useAnimatedStyle(() => { 117 | const { sumWidthOfLayer } = itemLayouts 118 | 119 | if (sumWidthOfLayer) { 120 | const currentLayerSumWidth = sumWidthOfLayer[itemLayouts[itemKey].layout.y] 121 | const levelDifference = screenWidth - currentLayerSumWidth 122 | const maxLevelDifference = screenWidth - Math.max(...Object.values(sumWidthOfLayer)) 123 | const translationX = levelDifference > 0 124 | ? translateX.value 125 | : (levelDifference * translateX.value) / maxLevelDifference 126 | 127 | return { 128 | transform: [ 129 | { 130 | translateX: translationX 131 | } 132 | ] 133 | } 134 | } 135 | return {} 136 | }, [itemLayouts]) 137 | 138 | return ( 139 | handleItemLayout(event, itemKey)}> 142 | {renderItem({ item, index })} 143 | 144 | ) 145 | } 146 | 147 | const handleItemLayout = (event, key) => { 148 | if (!itemLayoutsCache.current[key]) { 149 | itemLayoutsCache.current[key] = event.nativeEvent 150 | 151 | if (Object.keys(itemLayoutsCache.current).length === data.length) { 152 | finalizeLayoutSetUp() 153 | } 154 | } 155 | } 156 | 157 | const finalizeLayoutSetUp = () => { 158 | let spacingBetweenItems = 0 159 | itemLayoutsCache.current = Object 160 | .values(itemLayoutsCache.current) 161 | .reduce((accumulator, current, index) => { 162 | if (index === 0) { 163 | spacingBetweenItems = getSpacingBetweenItems() 164 | } 165 | 166 | if (!accumulator.sumWidthOfLayer) { 167 | accumulator.sumWidthOfLayer = {} 168 | } 169 | 170 | if (!accumulator.sumWidthOfLayer[current.layout.y]) { 171 | accumulator.sumWidthOfLayer[current.layout.y] = 0 172 | } 173 | 174 | accumulator.sumWidthOfLayer[current.layout.y] += current.layout.width + spacingBetweenItems 175 | return accumulator 176 | }, itemLayoutsCache.current) 177 | setItemLayouts(itemLayoutsCache.current) 178 | } 179 | 180 | const getSpacingBetweenItems = () => { 181 | if (data.length < 2) { 182 | return 0 183 | } 184 | 185 | const firstIndex = isRTL ? 1 : 0 186 | const secondIndex = isRTL ? 0 : 1 187 | const firstKey = keyExtractor(data[firstIndex], firstIndex) 188 | const secondKey = keyExtractor(data[secondIndex], secondIndex) 189 | const firstItem = itemLayoutsCache.current[firstKey] 190 | const secondItem = itemLayoutsCache.current[secondKey] 191 | return secondItem.layout.x - firstItem.layout.width - firstItem.layout.x 192 | } 193 | 194 | return ( 195 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | ) 205 | } 206 | 207 | const styles = { 208 | container: { 209 | flexWrap: 'wrap', 210 | flexDirection: 'row', 211 | width: screenWidth * 1.8 212 | } 213 | } 214 | 215 | Steve.displayName = 'Steve' 216 | Steve.defaultProps = { 217 | containerStyle: {}, 218 | isRTL: false 219 | } -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test') 2 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { Steve } from './Steve' 2 | 3 | export default Steve -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "react-native-steve": [ 6 | "./src/index" 7 | ] 8 | }, 9 | "allowUnreachableCode": false, 10 | "allowUnusedLabels": false, 11 | "esModuleInterop": true, 12 | "importsNotUsedAsValues": "error", 13 | "forceConsistentCasingInFileNames": true, 14 | "jsx": "react", 15 | "lib": [ 16 | "esnext" 17 | ], 18 | "module": "esnext", 19 | "moduleResolution": "node", 20 | "noFallthroughCasesInSwitch": true, 21 | "noImplicitReturns": true, 22 | "noImplicitUseStrict": false, 23 | "noStrictGenericChecks": false, 24 | "noUnusedLocals": true, 25 | "noUnusedParameters": true, 26 | "resolveJsonModule": true, 27 | "skipLibCheck": true, 28 | "strict": true, 29 | "target": "esnext" 30 | } 31 | } 32 | --------------------------------------------------------------------------------