{"id":4291,"url":"https://github.com/mfrachet/rn-displayable","last_synced_at":"2025-04-13T14:50:47.715Z","repository":{"id":66323504,"uuid":"113044565","full_name":"mfrachet/rn-displayable","owner":"mfrachet","description":":computer: :dash: Make your component visible with animations and a set of rules or simple props","archived":false,"fork":false,"pushed_at":"2018-09-17T11:11:39.000Z","size":195,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T05:41:46.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfrachet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-12-04T13:14:35.000Z","updated_at":"2023-03-14T23:09:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd63ffc3-e2b3-44a2-af8a-a52ae710040b","html_url":"https://github.com/mfrachet/rn-displayable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfrachet%2Frn-displayable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfrachet%2Frn-displayable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfrachet%2Frn-displayable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfrachet%2Frn-displayable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfrachet","download_url":"https://codeload.github.com/mfrachet/rn-displayable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732508,"owners_count":21152850,"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":"2024-01-05T20:17:07.083Z","updated_at":"2025-04-13T14:50:47.696Z","avatar_url":"https://github.com/mfrachet.png","language":"JavaScript","funding_links":[],"categories":["Components","Others"],"sub_categories":["UI"],"readme":"[![Build Status](https://travis-ci.org/mfrachet/rn-displayable.svg?branch=master)](https://travis-ci.org/mfrachet/rn-displayable)\n[![Coverage Status](https://coveralls.io/repos/github/mfrachet/rn-displayable/badge.svg?branch=master)](https://coveralls.io/github/mfrachet/rn-displayable?branch=master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nMake your component visible with animations and a set of rules or simple props\n\n# Content\n\n- \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\n- \u003ca href=\"#props\"\u003eDisplay content with simple props\u003c/a\u003e\n- \u003ca href=\"#rules\"\u003eDisplay content using business rules\u003c/a\u003e\n- \u003ca href=\"#animation\"\u003eMake the transition beautiful with animation\u003c/a\u003e\n\n# Usage\n\n\u003ch3 name=\"installation\"\u003eInstallation\u003c/h3\u003e\n\n```shell\n$ yarn add rn-displayable\n```\n\n### In your code\n\n\u003ch4 name=\"props\"\u003eUsage with primitive props\u003c/h4\u003e\n\n```javascript\n/* react stuff... */\nimport { makeDisplayable, makeVisible } from \"rn-displayable\";\n\nconst DisplayableText = makeDisplayable(Text);\nconst VisibleText = makeVisible(Text);\n\nexport default function() {\n  return (\n    \u003cView\u003e\n      \u003cDisplayableText isDisplayed\u003eThis is displayed\u003c/DisplayableText\u003e\n      \u003cDisplayableText\u003eThis is NOT displayed\u003c/DisplayableText\u003e\n\n      \u003cVisibleText isVisible\u003eThis is visible\u003c/VisibleText\u003e\n      \u003cVisibleText isVisible\u003eThis is NOT visible\u003c/VisibleText\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n**Why two different ways to handle the same thing?**\n\nThe `makeDisplayable` HoC allows to **create** and **remove** the view on the native part. The view doesn't exist anymore. This operation has a cost in React Native: multiple messages go across the bridge and can lead to slowness.\n\nThe `makeVisible` on the other side only deals with `style` under the hood. It's better in term of performances because the element always exist and is not recreated each time it's displayed: it only changes its style.\n\n\u003ch4 name=\"rules\"\u003eUsing rules\u003c/h4\u003e\n\n```javascript\n/* react stuff... */\nimport { makeDisplayable, makeVisible } from \"rn-displayable\";\n\nconst isBiggerThan5 = props =\u003e props.number \u003e 5;\nconst isBiggerThan10 = props =\u003e props.number \u003e 10;\n\nconst rules = [isBiggerThan5, isBiggerThan10];\n\nconst DisplayableText = makeDisplayable(Text);\nconst VisibleText = makeVisible(Text);\n\nexport default function() {\n  return (\n    \u003cView\u003e\n      \u003cDisplayableText number={3} rules={rules}\u003e\n        This is not displayed ! (first rule not resolved)\n      \u003c/DisplayableText\u003e\n\n      \u003cDisplayableText number={12} rules={rules}\u003e\n        This is displayed !\n      \u003c/DisplayableText\u003e\n\n      \u003cVisibleText number={8} rules={rules}\u003e\n        This is not visible ! (second rule not resolved)\n      \u003c/VisibleText\u003e\n\n      \u003cVisibleText number={15} rules={rules}\u003e\n        This is visible !\n      \u003c/VisibleText\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n\u003ch4 name=\"animation\"\u003eUsage with Animation\u003c/h4\u003e\n\nThe library provides a `Animation` prop with the HoC. This animation is playing while _entering_ (in the future, a leaving animation will be added).\n\nHere's a little example:\n\n```javascript\nconst CustomFade = ({ children }) =\u003e {\n  const animation = new Animated.Value(0);\n\n  Animated.timing(animation, {\n    toValue: 1,\n    duration: 1000,\n    useNativeDriver: true\n  }).start();\n\n  const style = { opacity: animation };\n  return \u003cAnimated.View style={style}\u003e{children}\u003c/Animated.View\u003e;\n};\n\n/* ... */\nconst SomeComponent = ({ isVisible }) =\u003e (\n  \u003cVisibleView isVisible={isVisible} Animation={CustomFade}\u003e\n    \u003cText\u003eAppearing with a wonderful (\\o/) opacity animation\u003c/Text\u003e\n  \u003c/VisibleView\u003e;\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfrachet%2Frn-displayable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfrachet%2Frn-displayable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfrachet%2Frn-displayable/lists"}