├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── .github ├── FUNDING.yml └── workflows │ ├── publish.yml │ ├── build.yml │ └── review.yml ├── .eslintignore ├── .gitattributes ├── babel.config.js ├── assets ├── logo.png └── cover.gif ├── example ├── .storybook │ ├── preview.js │ └── main.js ├── src │ ├── stories │ │ ├── BetterImage.js │ │ ├── Reference.stories.mdx │ │ ├── BetterImage.stories.js │ │ └── GettingStarted.stories.mdx │ ├── assets │ │ └── logo.png │ └── App.tsx ├── assets │ └── place-holder.png ├── index.js ├── babel.config.js ├── app.json ├── webpack.config.js ├── metro.config.js └── package.json ├── .editorconfig ├── tsconfig.json ├── .gitignore ├── LICENSE ├── .circleci └── config.yml ├── package.json ├── README.md └── CONTRIBUTING.md /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: [buymeacoffee.com/daniakash] 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | lib 2 | node_modules 3 | storybook-static 4 | web-build 5 | coverage 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-native-toolkit/react-native-better-image/HEAD/assets/logo.png -------------------------------------------------------------------------------- /assets/cover.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-native-toolkit/react-native-better-image/HEAD/assets/cover.gif -------------------------------------------------------------------------------- /example/.storybook/preview.js: -------------------------------------------------------------------------------- 1 | 2 | export const parameters = { 3 | actions: { argTypesRegex: "^on[A-Z].*" }, 4 | } -------------------------------------------------------------------------------- /example/src/stories/BetterImage.js: -------------------------------------------------------------------------------- 1 | import BetterImage from 'react-native-better-image'; 2 | 3 | export default BetterImage; 4 | -------------------------------------------------------------------------------- /example/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-native-toolkit/react-native-better-image/HEAD/example/src/assets/logo.png -------------------------------------------------------------------------------- /example/assets/place-holder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-native-toolkit/react-native-better-image/HEAD/example/assets/place-holder.png -------------------------------------------------------------------------------- /example/.storybook/main.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "stories": [ 3 | "../src/**/*.stories.mdx", 4 | "../src/**/*.stories.@(js|jsx|ts|tsx)" 5 | ], 6 | "addons": [ 7 | "@storybook/addon-links", 8 | "@storybook/addon-essentials" 9 | ] 10 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-better-image-example", 3 | "displayName": "BetterImage Example", 4 | "expo": { 5 | "name": "Better Image Example", 6 | "slug": "react-native-better-image-example", 7 | "description": "Example app for react-native-better-image", 8 | "privacy": "public", 9 | "version": "1.0.0", 10 | "platforms": ["ios", "android", "web"], 11 | "splash": { 12 | "image": "./src/assets/logo.png", 13 | "resizeMode": "contain", 14 | "backgroundColor": "#ffffff" 15 | }, 16 | "icon": "./src/assets/logo.png", 17 | "ios": { 18 | "supportsTablet": true 19 | }, 20 | "assetBundlePatterns": ["**/*"] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "react-native-better-image": ["./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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # logs 2 | *.log 3 | 4 | # coverage 5 | coverage 6 | 7 | # OSX 8 | # 9 | .DS_Store 10 | 11 | # storybook 12 | storybook-static 13 | 14 | # XDE 15 | .expo/ 16 | web-build 17 | 18 | # VSCode 19 | .vscode/ 20 | jsconfig.json 21 | 22 | # Xcode 23 | # 24 | build/ 25 | *.pbxuser 26 | !default.pbxuser 27 | *.mode1v3 28 | !default.mode1v3 29 | *.mode2v3 30 | !default.mode2v3 31 | *.perspectivev3 32 | !default.perspectivev3 33 | xcuserdata 34 | *.xccheckout 35 | *.moved-aside 36 | DerivedData 37 | *.hmap 38 | *.ipa 39 | *.xcuserstate 40 | project.xcworkspace 41 | 42 | # Android/IJ 43 | # 44 | .idea 45 | .gradle 46 | local.properties 47 | android.iml 48 | 49 | # Cocoapods 50 | # 51 | example/ios/Pods 52 | 53 | # node.js 54 | # 55 | node_modules/ 56 | npm-debug.log 57 | yarn-debug.log 58 | yarn-error.log 59 | 60 | # BUCK 61 | buck-out/ 62 | \.buckd/ 63 | android/app/libs 64 | android/keystores/debug.keystore 65 | 66 | # Expo 67 | .expo/* 68 | 69 | # generated by bob 70 | lib/ 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 DaniAkash 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: publish 2 | on: 3 | release: 4 | types: [published] 5 | 6 | jobs: 7 | lint: 8 | name: lint 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - uses: actions/setup-node@master 13 | with: 14 | node-version: 12.x 15 | - run: npx yarn bootstrap 16 | - run: npx yarn typescript 17 | - run: npx yarn lint 18 | 19 | test: 20 | strategy: 21 | matrix: 22 | platform: [ubuntu-latest, macOS-latest] 23 | node: ['12.x'] 24 | name: test/node ${{ matrix.node }}/${{ matrix.platform }} 25 | runs-on: ${{ matrix.platform }} 26 | steps: 27 | - uses: actions/checkout@master 28 | - uses: actions/setup-node@master 29 | with: 30 | node-version: ${{ matrix.node }} 31 | - run: npx yarn bootstrap 32 | - run: npx yarn test 33 | 34 | publish: 35 | needs: [test, lint] 36 | name: Publish to npm 🚢📦 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@master 40 | - uses: actions/setup-node@master 41 | with: 42 | node-version: 12.x 43 | - run: npx yarn bootstrap 44 | - uses: JS-DevTools/npm-publish@v1 45 | with: 46 | token: ${{ secrets.NPM_TOKEN }} 47 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-better-image-example", 3 | "description": "Example app for react-native-better-image", 4 | "version": "0.0.2", 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 | "storybook": "start-storybook -p 6006", 14 | "build-storybook": "build-storybook", 15 | "chromatic": "npx chromatic" 16 | }, 17 | "dependencies": { 18 | "expo": "40.0.0", 19 | "expo-splash-screen": "0.8.1", 20 | "react": "17.0.1", 21 | "react-dom": "17.0.1", 22 | "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.0.tar.gz", 23 | "react-native-unimodules": "0.12.0", 24 | "react-native-web": "^0.14.9" 25 | }, 26 | "devDependencies": { 27 | "@babel/core": "^7.9.6", 28 | "@babel/runtime": "^7.9.6", 29 | "@expo/webpack-config": "^0.12.27", 30 | "@storybook/addon-actions": "^6.1.14", 31 | "@storybook/addon-essentials": "^6.1.14", 32 | "@storybook/addon-links": "^6.1.14", 33 | "@storybook/react": "^6.1.14", 34 | "babel-loader": "^8.1.0", 35 | "babel-plugin-module-resolver": "^4.0.0", 36 | "babel-preset-expo": "^8.2.3", 37 | "chromatic": "^5.1.0", 38 | "expo-cli": "4.0.17", 39 | "react-is": "17.0.1" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /example/src/stories/Reference.stories.mdx: -------------------------------------------------------------------------------- 1 | import { Meta } from '@storybook/addon-docs/blocks'; 2 | 3 | 4 | 5 | ## API 6 | 7 | `BetterImage` component is built on top of the existing `Image` component. It extends all of the [`Image` component props](https://reactnative.dev/docs/image.html#props) with the following additional props: 8 | 9 | ## `thumbnailSource?: ImageSourcePropType` 10 | 11 | Source of the thumbnail image. 12 | 13 | Provide a lower quality scaled down version of the original image (preferrably size <2kb) to act as the thumbnail. This thumbnail will be blurred & will fade out when the actual image loads, providing a progressive loading view 14 | 15 | ## `fallbackSource?: ImageSourcePropType` 16 | 17 | Source of the fallback placeholder image 18 | 19 | Incase, the original image fails to load, this image will be displayed as a fallback or a placeholder in its place. It is recommended to have a local asset in this prop which will ensure an image is displayed even during poor or no network conditions. 20 | 21 | ## `viewStyle?: StyleProp` 22 | 23 | Style prop for the `` component inside which the BetterImage component is implemented 24 | 25 | Usually, `style` prop is used for styling images. However, since a parent `` component is needed to implement fallback & thumbnails, `viewStyle` prop is needed to customize this image component. 26 | 27 | `style` prop still works but the styles are applied to the `` component inside the parent `` component hence it might not produce the required result. 28 | 29 | ## `thumbnailFadeDuration?: number` 30 | 31 | default value ﹣ 250 32 | 33 | Time in milliseconds, taken for the thumbnail to fade in while the actual image is loading (if the actual image is very large & connection is slow, increase this value slightly to increase the duration of fade animation) 34 | 35 | ## `imageFadeDuration?: number` 36 | 37 | default value ﹣ 250 38 | 39 | Time in milliseconds, taken for the original image to fade in when it is loaded 40 | 41 | ## `thumbnailBlurRadius?: number` 42 | 43 | default value ﹣ 1 44 | 45 | Blur radius of the thumbnail image 46 | 47 | ## `children?: ReactNode` 48 | 49 | BetterImage supports children. If a children is provided, it automatically switches `` component with `` component. 50 | -------------------------------------------------------------------------------- /example/src/stories/BetterImage.stories.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import BetterImage from 'react-native-better-image'; 3 | 4 | export default { 5 | title: 'Example/BetterImage', 6 | component: BetterImage, 7 | argTypes: {}, 8 | }; 9 | 10 | const Template = (args) => ; 11 | 12 | const imageStyle = { height: 200, width: 400 }; 13 | 14 | const validSource = () => ({ 15 | source: { 16 | uri: `https://unsplash.com/photos/yNvVnPcurD8/download?force=true&w=2400&bust=${Math.random()}`, 17 | }, 18 | thumbnailSource: { 19 | uri: `https://unsplash.com/photos/yNvVnPcurD8/download?force=true&w=24&bust=${Math.random()}`, 20 | }, 21 | fallbackSource: { 22 | uri: `https://unsplash.com/a/img/empty-states/photos.png?bust=${Math.random()}`, 23 | }, 24 | }); 25 | export const ValidImage = Template.bind({}); 26 | ValidImage.args = { 27 | ...validSource(), 28 | viewStyle: imageStyle, 29 | resizeMode: 'contain', 30 | }; 31 | 32 | const inValidSource = () => ({ 33 | source: { 34 | uri: `https://unsplash.com/photos/2347729843y7/download?force=true&w=2400&bust=${Math.random()}`, 35 | }, 36 | thumbnailSource: { 37 | uri: `https://unsplash.com/photos/2347729843y7/download?force=true&w=24&bust=${Math.random()}`, 38 | }, 39 | fallbackSource: { 40 | uri: `https://unsplash.com/a/img/empty-states/photos.png?bust=${Math.random()}`, 41 | }, 42 | }); 43 | 44 | export const InvalidImage = Template.bind({}); 45 | InvalidImage.args = { 46 | ...inValidSource(), 47 | viewStyle: imageStyle, 48 | resizeMode: 'contain', 49 | }; 50 | 51 | const invalidImageOnlySource = () => ({ 52 | source: { 53 | uri: `https://unsplash.com/photos/2347729843y7/download?force=true&w=2400&bust=${Math.random()}`, 54 | }, 55 | thumbnailSource: { 56 | uri: `https://unsplash.com/photos/yNvVnPcurD8/download?force=true&w=24&bust=${Math.random()}`, 57 | }, 58 | fallbackSource: { 59 | uri: `https://unsplash.com/a/img/empty-states/photos.png?bust=${Math.random()}`, 60 | }, 61 | }); 62 | export const InvalidImageButWithValidThumbnail = Template.bind({}); 63 | InvalidImageButWithValidThumbnail.args = { 64 | ...invalidImageOnlySource(), 65 | viewStyle: imageStyle, 66 | resizeMode: 'contain', 67 | }; 68 | 69 | export const CustomImageFadeDuration = Template.bind({}); 70 | CustomImageFadeDuration.args = { 71 | ...validSource(), 72 | viewStyle: imageStyle, 73 | resizeMode: 'contain', 74 | thumbnailFadeDuration: 250, 75 | imageFadeDuration: 2000, 76 | }; 77 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | on: 3 | push: 4 | branches: 5 | - master 6 | tags: 7 | - '!*' # Do not execute on tags 8 | paths: 9 | - example/* 10 | - src/* 11 | - test/* 12 | - __tests__/* 13 | - '*.json' 14 | - yarn.lock 15 | - .github/**/*.yml 16 | 17 | jobs: 18 | lint: 19 | name: lint 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@master 23 | - uses: actions/setup-node@master 24 | with: 25 | node-version: 12.x 26 | - run: npx yarn bootstrap 27 | - run: npx yarn typescript 28 | - run: npx yarn lint 29 | 30 | test: 31 | strategy: 32 | matrix: 33 | platform: [ubuntu-latest, macOS-latest] 34 | node: ['12.x'] 35 | name: test/node ${{ matrix.node }}/${{ matrix.platform }} 36 | runs-on: ${{ matrix.platform }} 37 | steps: 38 | - uses: actions/checkout@master 39 | - uses: actions/setup-node@master 40 | with: 41 | node-version: ${{ matrix.node }} 42 | - run: npx yarn bootstrap 43 | - run: npx yarn test 44 | 45 | coverage: 46 | needs: [test, lint] 47 | name: coverage 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@master 51 | - uses: actions/setup-node@master 52 | with: 53 | node-version: 12.x 54 | - run: npx yarn bootstrap 55 | - uses: paambaati/codeclimate-action@v2.5.3 56 | env: 57 | CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} 58 | with: 59 | coverageCommand: npx yarn test --coverage 60 | debug: true 61 | 62 | publish: 63 | needs: [test, lint] 64 | name: Publish example app to Expo 🚀 65 | runs-on: ubuntu-latest 66 | steps: 67 | - uses: actions/checkout@v2 68 | - uses: actions/setup-node@v1 69 | with: 70 | node-version: 12.x 71 | - uses: expo/expo-github-action@v5 72 | with: 73 | expo-version: 3.x 74 | expo-username: ${{ secrets.EXPO_CLI_USERNAME }} 75 | expo-password: ${{ secrets.EXPO_CLI_PASSWORD }} 76 | - run: npx yarn bootstrap 77 | - working-directory: example 78 | run: expo publish 79 | 80 | chromatic: 81 | needs: [test, lint] 82 | name: Publish storybook to chromatic 🧪 83 | runs-on: ubuntu-latest 84 | steps: 85 | - uses: actions/checkout@v2 86 | with: 87 | fetch-depth: 0 88 | - uses: actions/setup-node@v1 89 | with: 90 | node-version: 12.x 91 | - run: npx yarn bootstrap 92 | - run: npx yarn chromatic 93 | working-directory: example 94 | env: 95 | CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} 96 | -------------------------------------------------------------------------------- /.github/workflows/review.yml: -------------------------------------------------------------------------------- 1 | name: review 2 | on: pull_request 3 | 4 | jobs: 5 | lint: 6 | name: lint 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@master 10 | - uses: actions/setup-node@master 11 | with: 12 | node-version: 12.x 13 | - run: npx yarn bootstrap 14 | - run: npx yarn typescript 15 | - run: npx yarn lint 16 | 17 | test: 18 | strategy: 19 | matrix: 20 | platform: [ubuntu-latest, macOS-latest] 21 | node: ['12.x'] 22 | name: test/node ${{ matrix.node }}/${{ matrix.platform }} 23 | runs-on: ${{ matrix.platform }} 24 | steps: 25 | - uses: actions/checkout@master 26 | - uses: actions/setup-node@master 27 | with: 28 | node-version: ${{ matrix.node }} 29 | - run: npx yarn bootstrap 30 | - run: npx yarn test 31 | 32 | coverage: 33 | needs: [test, lint] 34 | name: coverage 35 | runs-on: ubuntu-latest 36 | steps: 37 | - uses: actions/checkout@master 38 | - uses: actions/setup-node@master 39 | with: 40 | node-version: 12.x 41 | - run: npx yarn bootstrap 42 | - run: npx yarn test --coverage 43 | - uses: romeovs/lcov-reporter-action@v0.2.16 44 | with: 45 | github-token: ${{ secrets.GITHUB_TOKEN }} 46 | 47 | chromatic: 48 | needs: [test, lint] 49 | name: Publish storybook to chromatic 🧪 50 | runs-on: ubuntu-latest 51 | steps: 52 | - uses: actions/checkout@v2 53 | with: 54 | fetch-depth: 0 55 | - uses: actions/setup-node@v1 56 | with: 57 | node-version: 12.x 58 | - run: npx yarn bootstrap 59 | - run: npx yarn chromatic 60 | working-directory: example 61 | env: 62 | CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} 63 | 64 | expo-publish: 65 | needs: [test, lint] 66 | name: Publish to Expo 🚀 67 | runs-on: ubuntu-latest 68 | steps: 69 | - uses: actions/checkout@v2 70 | - uses: actions/setup-node@v1 71 | with: 72 | node-version: 12.x 73 | - uses: expo/expo-github-action@v5 74 | with: 75 | expo-version: 3.x 76 | expo-username: ${{ secrets.EXPO_CLI_USERNAME }} 77 | expo-password: ${{ secrets.EXPO_CLI_PASSWORD }} 78 | - run: npx yarn bootstrap 79 | - run: expo publish --release-channel=pr-${{ github.event.number }} 80 | working-directory: example 81 | - uses: unsplash/comment-on-pr@master 82 | env: 83 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 84 | with: 85 | msg: App is ready for review, you can [see it here](https://expo.io/@daniakash/react-native-better-image-example?release-channel=pr-${{ github.event.number }}). 86 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useRef, useEffect } from 'react'; 2 | import { View, Text, StyleSheet, Linking } from 'react-native'; 3 | import BetterImage from 'react-native-better-image'; 4 | 5 | const styles = StyleSheet.create({ 6 | container: { 7 | flex: 1, 8 | backgroundColor: '#ccc', 9 | justifyContent: 'center', 10 | alignItems: 'center', 11 | }, 12 | titleStyle: { 13 | fontWeight: 'bold', 14 | }, 15 | }); 16 | 17 | function useInterval(callback: () => unknown, delay: number) { 18 | const savedCallback = useRef<() => unknown>(() => null); 19 | 20 | // Remember the latest callback. 21 | useEffect(() => { 22 | savedCallback.current = callback; 23 | }, [callback]); 24 | 25 | // Set up the interval. 26 | useEffect(() => { 27 | function tick() { 28 | savedCallback.current(); 29 | } 30 | if (delay !== null) { 31 | let id = setInterval(tick, delay); 32 | return () => clearInterval(id); 33 | } 34 | return () => null; 35 | }, [delay]); 36 | } 37 | 38 | const ImageUrl = `https://images.unsplash.com/photo-1610746334198-e7525c63509c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&h=900`; 39 | const ThumbnailUrl = `https://images.unsplash.com/photo-1610746334198-e7525c63509c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&h=90`; 40 | const placeholderUrl = `https://unsplash.com/a/img/empty-states/photos.png`; 41 | 42 | const validSource = { 43 | title: 'Valid Image & Thumbnail', 44 | image: () => `${ImageUrl}&bust=${Math.random()}`, 45 | thumbnail: () => `${ThumbnailUrl}&bust=${Math.random()}`, 46 | placeholder: () => placeholderUrl, 47 | }; 48 | 49 | const inValidSource = { 50 | title: 'Invalid Image & Thumbnail', 51 | image: () => `not found`, 52 | thumbnail: () => `not found`, 53 | placeholder: () => placeholderUrl, 54 | }; 55 | 56 | const invalidImageOnlySource = { 57 | title: 'Invalid Image & Valid Thumbnail', 58 | image: () => `not found`, 59 | thumbnail: () => `${ThumbnailUrl}&bust=${Math.random()}`, 60 | placeholder: () => placeholderUrl, 61 | }; 62 | 63 | const sources = [validSource, inValidSource, invalidImageOnlySource]; 64 | 65 | function App() { 66 | const [imageSource, setImageSource] = useState(sources[0]); 67 | 68 | const [intervalCounter, setIntervalCounter] = useState(0); 69 | 70 | useInterval(() => { 71 | const targetSource = 72 | intervalCounter === 0 ? 1 : intervalCounter === 1 ? 2 : 0; 73 | setImageSource(sources[targetSource]); 74 | setIntervalCounter(targetSource); 75 | }, 5000); 76 | 77 | const style = { 78 | backgroundColor: 'white', 79 | height: 346.5, 80 | width: 252, 81 | borderRadius: 9, 82 | }; 83 | 84 | return ( 85 | 86 | Various scenarios will change every 5 seconds 87 | 88 | Scenario: {imageSource.title} 89 | 90 | 103 | 104 | Photo by{' '} 105 | 108 | Linking.openURL( 109 | 'https://unsplash.com/@vovcarrot?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText' 110 | ) 111 | } 112 | > 113 | Vladimir Gladkov 114 | {' '} 115 | on{' '} 116 | 119 | Linking.openURL( 120 | 'https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText' 121 | ) 122 | } 123 | > 124 | Unsplash 125 | 126 | 127 | 128 | ); 129 | } 130 | 131 | export default App; 132 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-better-image", 3 | "version": "0.0.3", 4 | "description": "A better image component for react-native with fallback images & progressive loading support", 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-better-image.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 | "fallback-images", 35 | "progressive-image", 36 | "image" 37 | ], 38 | "repository": "https://github.com/react-native-toolkit/react-native-better-image", 39 | "author": "DaniAkash (https://github.com/DaniAkash)", 40 | "license": "MIT", 41 | "bugs": { 42 | "url": "https://github.com/react-native-toolkit/react-native-better-image/issues" 43 | }, 44 | "homepage": "https://betterimage.netlify.app", 45 | "devDependencies": { 46 | "@commitlint/config-conventional": "11.0.0", 47 | "@react-native-community/bob": "0.17.1", 48 | "@react-native-community/eslint-config": "2.0.0", 49 | "@release-it/conventional-changelog": "2.0.0", 50 | "@types/jest": "26.0.20", 51 | "@types/react": "17.0.0", 52 | "@types/react-native": "0.63.45", 53 | "commitlint": "11.0.0", 54 | "eslint": "7.18.0", 55 | "eslint-config-prettier": "7.1.0", 56 | "eslint-plugin-prettier": "3.3.1", 57 | "husky": "4.3.8", 58 | "jest": "26.6.3", 59 | "pod-install": "0.1.14", 60 | "prettier": "2.2.1", 61 | "react": "17.0.1", 62 | "react-native": "0.63.4", 63 | "react-native-web": "0.14.10", 64 | "release-it": "14.2.2", 65 | "typescript": "4.1.3" 66 | }, 67 | "peerDependencies": { 68 | "react": "*", 69 | "react-native": "*" 70 | }, 71 | "jest": { 72 | "preset": "react-native", 73 | "modulePathIgnorePatterns": [ 74 | "/example/node_modules", 75 | "/lib/" 76 | ] 77 | }, 78 | "husky": { 79 | "hooks": { 80 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 81 | "pre-commit": "yarn lint && yarn typescript" 82 | } 83 | }, 84 | "commitlint": { 85 | "extends": [ 86 | "@commitlint/config-conventional" 87 | ] 88 | }, 89 | "release-it": { 90 | "git": { 91 | "commitMessage": "chore: release ${version}", 92 | "tagName": "v${version}" 93 | }, 94 | "npm": { 95 | "publish": true 96 | }, 97 | "github": { 98 | "release": true 99 | }, 100 | "plugins": { 101 | "@release-it/conventional-changelog": { 102 | "preset": "angular" 103 | } 104 | } 105 | }, 106 | "eslintConfig": { 107 | "extends": [ 108 | "@react-native-community", 109 | "prettier" 110 | ], 111 | "rules": { 112 | "prettier/prettier": [ 113 | "error", 114 | { 115 | "quoteProps": "consistent", 116 | "singleQuote": true, 117 | "tabWidth": 2, 118 | "trailingComma": "es5", 119 | "useTabs": false 120 | } 121 | ] 122 | } 123 | }, 124 | "eslintIgnore": [ 125 | "node_modules/", 126 | "lib/" 127 | ], 128 | "prettier": { 129 | "quoteProps": "consistent", 130 | "singleQuote": true, 131 | "tabWidth": 2, 132 | "trailingComma": "es5", 133 | "useTabs": false 134 | }, 135 | "@react-native-community/bob": { 136 | "source": "src", 137 | "output": "lib", 138 | "targets": [ 139 | "commonjs", 140 | "module", 141 | "typescript" 142 | ] 143 | }, 144 | "dependencies": { 145 | "use-deep-compare-effect": "1.6.1" 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useRef, useCallback, useState, ReactNode } from 'react'; 2 | import { 3 | View, 4 | Image, 5 | ImageBackground, 6 | Animated, 7 | StyleSheet, 8 | ImageProps, 9 | ViewStyle, 10 | StyleProp, 11 | ImageSourcePropType, 12 | NativeSyntheticEvent, 13 | ImageErrorEventData, 14 | } from 'react-native'; 15 | import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect'; 16 | 17 | export interface BetterImageProps extends ImageProps { 18 | viewStyle?: StyleProp; 19 | thumbnailFadeDuration?: number; 20 | imageFadeDuration?: number; 21 | thumbnailSource?: ImageSourcePropType; 22 | thumbnailBlurRadius?: number; 23 | fallbackSource?: ImageSourcePropType; 24 | children?: ReactNode; 25 | } 26 | 27 | const { Value, createAnimatedComponent, timing } = Animated; 28 | 29 | const AnimatedImage = createAnimatedComponent(Image); 30 | const AnimatedImageBackground = createAnimatedComponent(ImageBackground); 31 | 32 | const BetterImage = ({ 33 | viewStyle, 34 | thumbnailFadeDuration = 250, 35 | imageFadeDuration = 250, 36 | thumbnailSource, 37 | source, 38 | onLoadEnd, 39 | resizeMethod, 40 | resizeMode, 41 | thumbnailBlurRadius = 1, 42 | style, 43 | fallbackSource = { uri: '' }, 44 | onError, 45 | children, 46 | ...otherProps 47 | }: BetterImageProps) => { 48 | const imageOpacity = useRef(new Value(0)).current; 49 | const thumbnailOpacity = useRef(new Value(0)).current; 50 | const thumbnailAnimationProgress = useRef< 51 | Animated.CompositeAnimation | undefined 52 | >(); 53 | const [hasError, setHasError] = useState(false); 54 | const [hasLoaded, setHasLoaded] = useState(false); 55 | 56 | const onImageLoad = () => { 57 | setHasLoaded(true); 58 | 59 | timing(imageOpacity, { 60 | toValue: 1, 61 | duration: imageFadeDuration, 62 | useNativeDriver: true, 63 | }).start(() => { 64 | thumbnailAnimationProgress.current?.stop(); 65 | timing(thumbnailOpacity, { 66 | toValue: 0, 67 | duration: thumbnailFadeDuration, 68 | useNativeDriver: true, 69 | }).start(); 70 | }); 71 | 72 | onLoadEnd && onLoadEnd(); 73 | }; 74 | 75 | const onThumbnailLoad = () => { 76 | if (!hasLoaded) { 77 | const progress = timing(thumbnailOpacity, { 78 | toValue: 1, 79 | duration: thumbnailFadeDuration, 80 | useNativeDriver: true, 81 | }); 82 | thumbnailAnimationProgress.current = progress; 83 | thumbnailAnimationProgress.current.start(); 84 | } 85 | }; 86 | 87 | const onImageLoadError = ( 88 | event: NativeSyntheticEvent 89 | ) => { 90 | setHasError(true); 91 | onError && onError(event); 92 | }; 93 | 94 | useDeepCompareEffectNoCheck( 95 | useCallback(() => { 96 | imageOpacity.setValue(0); 97 | thumbnailOpacity.setValue(0); 98 | setHasError(false); 99 | setHasLoaded(false); 100 | // eslint-disable-next-line react-hooks/exhaustive-deps 101 | }, []), 102 | [source, thumbnailSource] 103 | ); 104 | 105 | const ImageComponent = children ? AnimatedImageBackground : AnimatedImage; 106 | 107 | return ( 108 | 109 | {thumbnailSource ? ( 110 | 123 | ) : null} 124 | null : onImageLoadError} 130 | source={hasError ? fallbackSource : source} 131 | style={[styles.imageStyle, { opacity: imageOpacity }, style]} 132 | {...otherProps} 133 | /> 134 | 135 | ); 136 | }; 137 | 138 | const styles = StyleSheet.create({ 139 | imageContainerStyle: { 140 | overflow: 'hidden', 141 | }, 142 | thumbnailImageStyle: { 143 | ...StyleSheet.absoluteFillObject, 144 | }, 145 | imageStyle: { 146 | ...StyleSheet.absoluteFillObject, 147 | }, 148 | }); 149 | 150 | export default BetterImage; 151 | -------------------------------------------------------------------------------- /example/src/stories/GettingStarted.stories.mdx: -------------------------------------------------------------------------------- 1 | import { Meta } from '@storybook/addon-docs/blocks'; 2 | import BetterImage from './BetterImage'; 3 | 4 | 5 | 6 | better-image-logo 12 |
13 |
14 | 15 | # React Native Better Image 16 | 17 | A better image component for react-native with fallback images & progressive loading support 18 | 19 | Built on top of `View`, `Image` & `Animated` components 20 | 21 |
22 | 35 | 48 | 61 |
62 | 63 | ### Compatible with Expo & React Native Web 🚀 64 | 65 | ### PRs Welcome 👍✨ 66 | 67 | [![Build Status][build-badge]][build] 68 | [![Maintainability][maintainability-badge]][maintainability-url] 69 | [![Test Coverage][coverage-badge]][coverage-url] 70 | 71 | [![Version][version-badge]][package] 72 | [![Downloads][downloads-badge]][npmtrends] 73 | [![Bundlephobia][bundle-phobia-badge]][bundle-phobia] 74 | 75 | [![Star on GitHub][github-star-badge]][github-star] 76 | [![Watch on GitHub][github-watch-badge]][github-watch] 77 | [![Twitter Follow][twitter-badge]][twitter] 78 | 79 | [![donate][coffee-badge]][coffee-url] 80 | [![sponsor][sponsor-badge]][sponsor-url] 81 | [![support][support-badge]][support-url] 82 | 83 | ```jsx 84 | import BetterImage from 'react-native-better-image'; 85 | 86 | //... 87 | 88 | component inside which the component is implemented 98 | viewStyle={{ 99 | height: 150, 100 | width: 150, 101 | margin: 8, 102 | }} 103 | />; 104 | ``` 105 | 106 | [coffee-badge]: https://img.shields.io/badge/-%E2%98%95%EF%B8%8F%20buy%20me%20a%20coffee-e85b46 107 | [coffee-url]: https://www.buymeacoffee.com/daniakash 108 | [sponsor-badge]: https://img.shields.io/badge/-%F0%9F%8F%85%20sponsor%20this%20project-e85b46 109 | [sponsor-url]: https://www.buymeacoffee.com/daniakash/e/6983 110 | [support-badge]: https://img.shields.io/badge/-Get%20Support-e85b46 111 | [support-url]: https://www.buymeacoffee.com/daniakash/e/7030 112 | [build]: https://github.com/react-native-toolkit/react-native-better-image/actions 113 | [build-badge]: https://github.com/react-native-toolkit/react-native-better-image/workflows/build/badge.svg 114 | [coverage-badge]: https://api.codeclimate.com/v1/badges/acf5243d130542dde7c9/test_coverage 115 | [coverage-url]: https://codeclimate.com/github/react-native-toolkit/react-native-better-image/test_coverage 116 | [maintainability-badge]: https://api.codeclimate.com/v1/badges/acf5243d130542dde7c9/maintainability 117 | [maintainability-url]: https://codeclimate.com/github/react-native-toolkit/react-native-better-image/maintainability 118 | [bundle-phobia-badge]: https://badgen.net/bundlephobia/minzip/react-native-better-image 119 | [bundle-phobia]: https://bundlephobia.com/result?p=react-native-better-image 120 | [downloads-badge]: https://img.shields.io/npm/dm/react-native-better-image.svg?style=flat-square 121 | [npmtrends]: http://www.npmtrends.com/react-native-better-image 122 | [package]: https://www.npmjs.com/package/react-native-better-image 123 | [version-badge]: https://img.shields.io/npm/v/react-native-better-image.svg?style=flat-square 124 | [twitter]: https://twitter.com/dani_akash_ 125 | [twitter-badge]: https://img.shields.io/twitter/follow/dani_akash_?style=social 126 | [github-watch-badge]: https://img.shields.io/github/watchers/react-native-toolkit/react-native-better-image.svg?style=social 127 | [github-watch]: https://github.com/react-native-toolkit/react-native-better-image/watchers 128 | [github-star-badge]: https://img.shields.io/github/stars/react-native-toolkit/react-native-better-image.svg?style=social 129 | [github-star]: https://github.com/react-native-toolkit/react-native-better-image/stargazers 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | better-image-logo 9 | 10 | # React Native Better Image 11 | 12 | A better image component for react-native with fallback images & progressive loading support 13 | 14 | Built on top of `View`, `Image` & `Animated` components 15 | 16 | [![Build Status][build-badge]][build] 17 | [![Maintainability][maintainability-badge]][maintainability-url] 18 | [![Test Coverage][coverage-badge]][coverage-url] 19 | 20 | [![Version][version-badge]][package] 21 | [![Downloads][downloads-badge]][npmtrends] 22 | [![Bundlephobia][bundle-phobia-badge]][bundle-phobia] 23 | 24 | [![Star on GitHub][github-star-badge]][github-star] 25 | [![Watch on GitHub][github-watch-badge]][github-watch] 26 | [![Twitter Follow][twitter-badge]][twitter] 27 | 28 | [![donate][coffee-badge]][coffee-url] 29 | [![sponsor][sponsor-badge]][sponsor-url] 30 | [![support][support-badge]][support-url] 31 | 32 | [![Storybook][storybook-badge]][website] [![Chromatic][chromatic-badge]][chromatic] 33 | 34 | ![better-image-cover](https://github.com/react-native-toolkit/react-native-better-image/raw/master/assets/cover.gif) 35 | 36 | ### Compatible with Expo & React Native Web 🚀 37 | 38 | ### PRs Welcome 👍✨ 39 | 40 |
41 | 42 | - 📦 [Installation](#installation) 43 | - ℹ️ [Usage](#usage) 44 | - 📃 [Documentation][website] 45 | - ✨ [Motivation](#motivation) 46 | - 📱 [Example App][expo] 47 | 48 | ## Installation 49 | 50 | ```sh 51 | yarn add react-native-better-image 52 | 53 | #or 54 | 55 | npm install react-native-better-image 56 | ``` 57 | 58 | ## Usage 59 | 60 | ```js 61 | import BetterImage from 'react-native-better-image'; 62 | 63 | // ... 64 | 65 | 78 | ``` 79 | 80 | ## Motivation 81 | 82 | React Native only includes a basic image component. I used to try solutions like [react-native-fast-image](https://github.com/DylanVann/react-native-fast-image) but none actually worked for the two of my most important issues: 83 | 84 | - Lack of a fallback placeholder 85 | - Progressive image loading (especially for banners & cover images) 86 | 87 | This library solves two of these important issues by providing a fallbackSource & a thumbnailSource prop. If you need more features, feel free to raise an issue or send a PR ✨ I'd be happy to help 👍 88 | 89 | ## Contributing 90 | 91 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 92 | 93 | ## License 94 | 95 | MIT © [DaniAkash][twitter] 96 | 97 | [coffee-badge]: https://img.shields.io/badge/-%E2%98%95%EF%B8%8F%20buy%20me%20a%20coffee-e85b46 98 | [coffee-url]: https://www.buymeacoffee.com/daniakash 99 | [sponsor-badge]: https://img.shields.io/badge/-%F0%9F%8F%85%20sponsor%20this%20project-e85b46 100 | [sponsor-url]: https://www.buymeacoffee.com/daniakash/e/6983 101 | [support-badge]: https://img.shields.io/badge/-Get%20Support-e85b46 102 | [support-url]: https://www.buymeacoffee.com/daniakash/e/7030 103 | [build]: https://github.com/react-native-toolkit/react-native-better-image/actions 104 | [build-badge]: https://github.com/react-native-toolkit/react-native-better-image/workflows/build/badge.svg 105 | [coverage-badge]: https://api.codeclimate.com/v1/badges/acf5243d130542dde7c9/test_coverage 106 | [coverage-url]: https://codeclimate.com/github/react-native-toolkit/react-native-better-image/test_coverage 107 | [maintainability-badge]: https://api.codeclimate.com/v1/badges/acf5243d130542dde7c9/maintainability 108 | [maintainability-url]: https://codeclimate.com/github/react-native-toolkit/react-native-better-image/maintainability 109 | [bundle-phobia-badge]: https://badgen.net/bundlephobia/minzip/react-native-better-image 110 | [bundle-phobia]: https://bundlephobia.com/result?p=react-native-better-image 111 | [downloads-badge]: https://img.shields.io/npm/dm/react-native-better-image.svg 112 | [npmtrends]: http://www.npmtrends.com/react-native-better-image 113 | [package]: https://www.npmjs.com/package/react-native-better-image 114 | [version-badge]: https://img.shields.io/npm/v/react-native-better-image.svg 115 | [twitter]: https://twitter.com/dani_akash_ 116 | [twitter-badge]: https://img.shields.io/twitter/follow/dani_akash_?style=social 117 | [github-watch-badge]: https://img.shields.io/github/watchers/react-native-toolkit/react-native-better-image.svg?style=social 118 | [github-watch]: https://github.com/react-native-toolkit/react-native-better-image/watchers 119 | [github-star-badge]: https://img.shields.io/github/stars/react-native-toolkit/react-native-better-image.svg?style=social 120 | [github-star]: https://github.com/react-native-toolkit/react-native-better-image/stargazers 121 | [storybook-badge]: https://cdn.jsdelivr.net/gh/storybookjs/brand@master/badge/badge-storybook.svg 122 | [website]: https://betterimage.netlify.app 123 | [chromatic-badge]: https://img.shields.io/badge/-chromatic-%23fc521f 124 | [chromatic]: https://chromatic.com/library?appId=5f5078c6fe7d0c0022c82f06&branch=master 125 | [expo]: https://expo.io/@daniakash/react-native-better-image-example 126 | -------------------------------------------------------------------------------- /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/BetterImageExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-better-image`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativebetterimage` 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 | --------------------------------------------------------------------------------