{"id":27447979,"url":"https://github.com/react-native-community/react-native-linear-gradient","last_synced_at":"2025-04-15T07:01:20.452Z","repository":{"id":29658418,"uuid":"33200340","full_name":"react-native-linear-gradient/react-native-linear-gradient","owner":"react-native-linear-gradient","description":"A \u003cLinearGradient /\u003e component for react-native","archived":false,"fork":false,"pushed_at":"2025-03-04T07:12:59.000Z","size":2251,"stargazers_count":4921,"open_issues_count":180,"forks_count":700,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-04-09T15:50:28.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-linear-gradient","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/react-native-linear-gradient.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-31T17:44:40.000Z","updated_at":"2025-04-06T03:50:22.000Z","dependencies_parsed_at":"2022-07-14T06:10:29.666Z","dependency_job_id":"a24b0709-b666-4e96-bd04-f296a0db2caa","html_url":"https://github.com/react-native-linear-gradient/react-native-linear-gradient","commit_stats":{"total_commits":355,"total_committers":109,"mean_commits":3.256880733944954,"dds":0.8422535211267606,"last_synced_commit":"2d67c42e2935bb1da425f1f890bcaf64594806d5"},"previous_names":["react-native-community/react-native-linear-gradient","brentvatne/react-native-linear-gradient"],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-linear-gradient%2Freact-native-linear-gradient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-linear-gradient%2Freact-native-linear-gradient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-linear-gradient%2Freact-native-linear-gradient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-linear-gradient%2Freact-native-linear-gradient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-native-linear-gradient","download_url":"https://codeload.github.com/react-native-linear-gradient/react-native-linear-gradient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023713,"owners_count":21199958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-15T07:01:05.000Z","updated_at":"2025-04-15T07:01:20.389Z","avatar_url":"https://github.com/react-native-linear-gradient.png","language":"Java","readme":"# react-native-linear-gradient\n\nA `\u003cLinearGradient\u003e` element for React Native\n\n[![ci][1]][2]\n[![npm version][3]][4]\n[![npm downloads][5]][4]\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/react-native-linear-gradient/react-native-linear-gradient/assets/743291/8ff2a78b-f0b1-463a-aa5b-555df2e71360\" width=\"300\"\u003e \u003cimg src=\"https://github.com/react-native-linear-gradient/react-native-linear-gradient/assets/743291/9c738be3-6fba-43d5-9c9f-1db1c10fd377\" width=\"300\"\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage and Examples](#examples)\n- [Props](#props)\n- [Example App](#an-example-app)\n- [Troubleshooting](#troubleshooting)\n- [Other Platforms](#other-platforms)\n\n## Installation\n\n```sh\nyarn add react-native-linear-gradient\n```\n\nOr, using npm: `npm install react-native-linear-gradient`\n\n## Examples\n\n[react-native-login](https://github.com/brentvatne/react-native-login) is a\nlegacy component which showcases the use of `\u003cLinearGradient\u003e`.\n\n### Simple\n\nThe following code will produce something like this:\n\n![Example code result](https://raw.githubusercontent.com/react-native-community/react-native-linear-gradient/HEAD/images/example.png)\n\n```javascript\nimport LinearGradient from 'react-native-linear-gradient';\n\n// Within your render function\n\u003cLinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} style={styles.linearGradient}\u003e\n  \u003cText style={styles.buttonText}\u003e\n    Sign in with Facebook\n  \u003c/Text\u003e\n\u003c/LinearGradient\u003e\n\n// Later on in your styles..\nvar styles = StyleSheet.create({\n  linearGradient: {\n    flex: 1,\n    paddingLeft: 15,\n    paddingRight: 15,\n    borderRadius: 5\n  },\n  buttonText: {\n    fontSize: 18,\n    fontFamily: 'Gill Sans',\n    textAlign: 'center',\n    margin: 10,\n    color: '#ffffff',\n    backgroundColor: 'transparent',\n  },\n});\n```\n\n### Horizontal gradient\n\nUsing the styles from above, set `start` and `end` like this to make the gradient go from left to right, instead of from top to bottom:\n\n```javascript\n\u003cLinearGradient start={{x: 0, y: 0}} end={{x: 1, y: 0}} colors={['#4c669f', '#3b5998', '#192f6a']} style={styles.linearGradient}\u003e\n  \u003cText style={styles.buttonText}\u003e\n    Sign in with Facebook\n  \u003c/Text\u003e\n\u003c/LinearGradient\u003e\n```\n\n### Text gradient (iOS)\n\nOn iOS you can use the `MaskedViewIOS` to display text with a gradient. The trick here is to render the text twice; once for the mask, and once to let the gradient have the correct size (hence the `opacity: 0`):\n\n```jsx\n\u003cMaskedViewIOS maskElement={\u003cText style={styles.text} /\u003e}\u003e\n  \u003cLinearGradient colors={['#f00', '#0f0']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}\u003e\n    \u003cText style={[styles.text, { opacity: 0 }]} /\u003e\n  \u003c/LinearGradient\u003e\n\u003c/MaskedViewIOS\u003e\n```\n\n### Animated Gradient\n\nCheck out the [example app](https://github.com/react-native-linear-gradient/react-native-linear-gradient/tree/HEAD/example/) (`git clone` this project, cd into it, npm install, open in Xcode and run) to see how this is done:\n\n![Example with extra props](https://raw.githubusercontent.com/react-native-community/react-native-linear-gradient/HEAD/images/example-animated.gif)\n\n*This gif was created using [licecap](http://www.cockos.com/licecap/) - a great piece of free OSS*\n\n### Transparent Gradient\n\nThe use of `transparent` color will most likely not lead to the expected result. `transparent` is actually a transparent black color (`rgba(0, 0, 0, 0)`). If you need a gradient in which the color is \"fading\", you need to have the same color with changing alpha channel. Example:\n\n```jsx\n// RGBA\n\n\u003cLinearGradient colors={['rgba(255, 255, 255, 0)', 'rgba(255, 255, 255, 1)']} {...otherGradientProps} /\u003e\n\n// Hex\n\n\u003cLinearGradient colors={['#FFFFFF00', '#FFFFFF']} {...otherGradientProps} /\u003e\n```\n\n## Props\n\nIn addition to regular `View` props, you can also provide additional props to customize your gradient look:\n\n#### colors\n\nAn array of at least two color values that represent gradient colors. Example: `['red', 'blue']` sets gradient from red to blue.\n\n#### start\n\nAn optional object of the following type: `{ x: number, y: number }`. Coordinates declare the position that the gradient starts at, as a fraction of the overall size of the gradient, starting from the top left corner. Example: `{ x: 0.1, y: 0.1 }` means that the gradient will start 10% from the top and 10% from the left.\n\n#### end\n\nSame as start, but for the end of the gradient.\n\n#### locations\n\nAn optional array of numbers defining the location of each gradient color stop, mapping to the color with the same index in `colors` prop. Example: `[0.1, 0.75, 1]` means that first color will take 0% - 10%, second color will take 10% - 75% and finally third color will occupy 75% - 100%.\n\n```javascript\n\u003cLinearGradient\n  start={{x: 0.0, y: 0.25}} end={{x: 0.5, y: 1.0}}\n  locations={[0,0.5,0.6]}\n  colors={['#4c669f', '#3b5998', '#192f6a']}\n  style={styles.linearGradient}\u003e\n  \u003cText style={styles.buttonText}\u003e\n    Sign in with Facebook\n  \u003c/Text\u003e\n\u003c/LinearGradient\u003e\n```\n\n![Example with extra props](https://raw.githubusercontent.com/react-native-community/react-native-linear-gradient/HEAD/images/example-other-props.png)\n\n#### useAngle / angle / angleCenter\n\nYou may want to achieve an angled gradient effect, similar to those in image editors like Photoshop.\nOne issue is that you have to calculate the angle based on the view's size, which only happens asynchronously and will cause unwanted flickr.\n\nIn order to do that correctly you can set `useAngle={true} angle={45} angleCenter={{x:0.5,y:0.5}}`, to achieve a gradient with a 45 degrees angle, with its center positioned in the view's exact center.\n\n`useAngle` is used to turn on/off angle based calculation (as opposed to `start`/`end`).\n`angle` is the angle in degrees.\n`angleCenter` is the center point of the angle (will control the weight and stretch of the gradient like it does in photoshop.\n\n## An example app\n\nYou can see this component in action in [brentvatne/react-native-login](https://github.com/brentvatne/react-native-login/blob/HEAD/App/Screens/LoginScreen.js#L58-L62).\n\n## Troubleshooting\n\n### iOS build fails: library not found, \"BVLinearGradient\" was not found in the UIManager\n\n1. Ensure to run `pod install` before running the app on iOS\n2. Ensure you use `ios/**.xcworkspace` file instead of `ios./**.xcodeproj`\n\n### Testing with Jest\n\nIf you do not have a Jest Setup file configured, you should add the following to your Jest settings and create the jest.setup.js file in project root:\n\n```js\nsetupFiles: ['\u003crootDir\u003e/jest.setup.js'];\n```\n\nYou should then add the following to your Jest setup file to mock the LinearGradient Native Module:\n\n```js\nimport mockRNLinearGradient from 'react-native-linear-gradient/jest/linear-gradient-mock';\n\njest.mock('react-native-linear-gradient', () =\u003e mockRNLinearGradient);\n```\n\n### Other\n\nClearing build caches and reinstalling dependencies sometimes solve some issues. Try next steps:\n\n1. Reinstalling `node_modules` with `rm -rf node_modules \u0026\u0026 yarn`\n2. Clearing Android Gradle cache with `(cd android \u0026\u0026 ./gradlew clean)`\n3. Reinstalling iOS CocoaPods with `(cd ios \u0026\u0026 rm -rf ./ios/Pods/**) \u0026\u0026 npx pod-install`\n4. Clearing Xcode Build cache (open Xcode and go to Product -\u003e Clean Build Folder)\n\nFor other troubleshooting issues, go to [React Native Troubleshooting](https://reactnative.dev/docs/troubleshooting.html)\n\n## Other platforms\n\n- Web: [react-native-web-community/react-native-web-linear-gradient](https://github.com/react-native-web-community/react-native-web-linear-gradient)\n\n## License\n\nMIT\n\n[1]: https://github.com/react-native-linear-gradient/react-native-linear-gradient/workflows/ci/badge.svg\n[2]: https://github.com/react-native-linear-gradient/react-native-linear-gradient/actions\n[3]: https://img.shields.io/npm/v/react-native-linear-gradient.svg\n[4]: https://www.npmjs.com/package/react-native-linear-gradient\n[5]: https://img.shields.io/npm/dm/react-native-linear-gradient.svg\n","funding_links":[],"categories":["Libraries","\u003ca name=\"UI:-Native-Modules\"\u003eUI: Native Modules\u003c/a\u003e","JavaScript"],"sub_categories":["Releases"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-native-community%2Freact-native-linear-gradient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freact-native-community%2Freact-native-linear-gradient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-native-community%2Freact-native-linear-gradient/lists"}