{"id":26579003,"url":"https://github.com/m10c/react-native-touchable-safe","last_synced_at":"2025-03-23T05:20:05.244Z","repository":{"id":57340970,"uuid":"98219800","full_name":"m10c/react-native-touchable-safe","owner":"m10c","description":"A single easy-to-use `\u003cTouchable\u003e` component, which harnesses the power of all React Native's `Touchable*` components.","archived":false,"fork":false,"pushed_at":"2020-05-15T11:15:58.000Z","size":29,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-13T09:47:48.177Z","etag":null,"topics":["android","ios","react-native","react-native-component"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/m10c.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}},"created_at":"2017-07-24T18:02:25.000Z","updated_at":"2020-08-13T15:25:38.000Z","dependencies_parsed_at":"2022-09-08T03:00:42.758Z","dependency_job_id":null,"html_url":"https://github.com/m10c/react-native-touchable-safe","commit_stats":null,"previous_names":["jamesisaac/react-native-touchable-safe"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m10c%2Freact-native-touchable-safe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m10c%2Freact-native-touchable-safe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m10c%2Freact-native-touchable-safe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m10c%2Freact-native-touchable-safe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m10c","download_url":"https://codeload.github.com/m10c/react-native-touchable-safe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245057766,"owners_count":20554004,"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":["android","ios","react-native","react-native-component"],"created_at":"2025-03-23T05:20:04.680Z","updated_at":"2025-03-23T05:20:05.215Z","avatar_url":"https://github.com/m10c.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-touchable-safe\n\n[![npm version](https://img.shields.io/npm/v/react-native-touchable-safe.svg)](https://www.npmjs.com/package/react-native-touchable-safe)\n[![Circle CI Status](https://circleci.com/gh/jamesisaac/react-native-touchable-safe.svg?style=shield)](https://circleci.com/gh/jamesisaac/react-native-touchable-safe)\n[![license](https://img.shields.io/github/license/jamesisaac/react-native-touchable-safe.svg)](https://opensource.org/licenses/MIT)\n[![npm downloads](https://img.shields.io/npm/dm/react-native-touchable-safe.svg)](https://www.npmjs.com/package/react-native-touchable-safe)\n\nA single easy-to-use `\u003cTouchable\u003e` component, which harnesses the power of all React Native's `Touchable*` components.\n\n* Simple API that bridges the differences between RN's various `Touchable*` types.\n* A consistent `View` hierarchy, to avoid tricky layout issues when switching between `Touchable*` types.\n* Handling the incompatability of ripple customisation on Android API level \u003c 21.\n\n## Motivation\n\nAs it stands, `TouchableOpacity` and `TouchableHighlight` wrap their children in a `View`, whereas `TouchableNativeFeedback` and `TouchableWithoutFeedback`\ndo not.\nThis can lead to headaches and platform-specific bugs when trying to create advanced Flexbox layouts with different touchable styles on Android/iOS.\nAn example of this is available here: https://snack.expo.io/ry6kXjX8W\n\nThis library makes the situation consistent and easy to reason about:\n\n* `\u003cTouchable\u003e` **always** introduces another view in the hierarchy, which can have its layout customised with `outerStyle`.\n* `\u003cTouchable\u003e` **always** must only have one child, which it applies its effect (e.g. opacity) to natively.\n\n## Installation\n\n```bash\n$ npm install --save react-native-touchable-safe\n\n# Or, with Yarn\n$ yarn add react-native-touchable-safe\n```\n\n## Getting started\n\nThis component provides a simple API, where alternating the component used per platform is as simple as:\n\n```js\nreturn (\n  \u003cTouchable android=\"native\" ios=\"opacity\"\u003e\n    \u003cMyButton /\u003e\n  \u003c/Touchable\u003e\n)\n```\n\nIn fact, these are the default behaviours, so simply `\u003cTouchable\u003e` is enough to achieve this effect.\nThe android/ios props only need to be used when deviating from the defaults.\n\n## Props\n\nIf you don't want to use the defaults (`TouchableNativeFeedback` on Android and `TouchableOpacity` on iOS), you can specify another type.\nUse `all` to set all platforms to the same effect, or `ios` and `android` to differentiate it per platform.\n\n* **`all?`**: `'opacity' | 'highlight' | 'without'`\n* **`ios?`**: `'opacity' | 'highlight' | 'without'` - (default: `'opacity'`)\n* **`android?`**: `'native' | 'opacity' | 'highlight' | 'without'` - (default: `'native'`)\n\nSome very common behaviours used by all touchable types:\n\n* **`onPress?`**: `() =\u003e void`\n* **`outerStyle?`**: `Object | number` - Style to pass to the outer `View`\n  component which wraps every type of touchable component. Typically used to\n  specify things like `\u003cTouchable outerStyle={{ flex: 1 }}\u003e`.\n* **`outerProps?`**: `Object` - Similar to `outerStyle`, but lets you set any\n  props (although `style` is the main use case).\n* **`disabled?`**: `boolean` - Remove any touch functionality and feedback.\n\nSeeing as setting a custom native ripple requires calling `TouchableNativeFeedback.Ripple`, the following top-level convenience props can be used to quickly customise the ripple:\n\n* **`nativeBorderless?`**: `boolean` - For `android=\"native\"`, should the\n  ripple effect be borderless.\n* **`nativePressColor?`**: `string` - (default: `'rgba(0, 0, 0, .1)'`) - For `android=\"native\"`, what color should the ripple be.\n\nAny props which you only want passed to one type of touchable component can be controlled with the following props.\n\n* **`nativeProps?`**: `Object` - Any props to pass on to a\n  `TouchableNativeFeedback` component.\n* **`opacityProps?`**: `Object` - Any props to pass on to a\n  `TouchableOpacity` component.\n* **`highlightProps?`**: `Object` - Any props to pass on to a\n  `TouchableHighlight` component.\n* **`withoutProps?`**: `Object` - Any props to pass on to a\n  `TouchableWithoutFeedback` component.\n\nAnd finally, anything else will be passed down to all touchable components.\n\n## Examples\n\n### Defaults\n\nNativeFeedback on Android, Opacity on iOS\n\n```js\nimport React from 'react'\nimport Touchable from 'react-native-touchable-safe'\nimport MyButton from './MyButton'\n\nexport default () =\u003e (\n  \u003cTouchable onPress={() =\u003e console.log('Pressed')}\u003e\n    \u003cMyButton /\u003e\n  \u003c/Touchable\u003e\n)\n```\n\n### Mixed\n\nA row of different styled buttons, which all behave consistently\n\n```js\nimport React from 'react'\nimport { StyleSheet } from 'react-native'\nimport Touchable from 'react-native-touchable-safe'\nimport MyButton from './MyButton'\n\nexport default ({ disabled }) =\u003e (\n  \u003cView style={styles.row}\u003e\n    {/* Android: native, iOS: highlight */}\n    \u003cTouchable\n      ios=\"highlight\"\n      onPress={() =\u003e {\n        console.log('Pressed A')\n      }}\n      outerStyle={styles.touchWrap}\n      nativeBorderless\n      nativePressColor=\"rgba(0, 0, 255, .5)\"\n    \u003e\n      \u003cMyButton title=\"A\" /\u003e\n    \u003c/Touchable\u003e\n\n    {/* Both: opacity (50% opacity) */}\n    \u003cTouchable\n      all=\"opacity\"\n      onPress={() =\u003e {\n        console.log('Pressed B')\n      }}\n      outerStyle={styles.touchWrap}\n      opacityProps={{ activeOpacity: 0.5 }}\n    \u003e\n      \u003cMyButton title=\"B\" /\u003e\n    \u003c/Touchable\u003e\n\n    {/* Both: no feedback */}\n    \u003cTouchable\n      all=\"without\"\n      onPress={() =\u003e {\n        console.log('Pressed C')\n      }}\n      outerStyle={styles.touchWrap}\n    \u003e\n      \u003cMyButton title=\"C\" /\u003e\n    \u003c/Touchable\u003e\n\n    {/* Both: defaults, disabled based on prop */}\n    \u003cTouchable\n      onPress={() =\u003e {\n        console.log('Pressed D')\n      }}\n      outerStyle={styles.touchWrap}\n      disabled={disabled}\n    \u003e\n      {/* Visual styling of disabled elements handled manually */}\n      \u003cMyButton title=\"D\" greyedOut={disabled} /\u003e\n    \u003c/Touchable\u003e\n  \u003c/View\u003e\n)\n\nconst styles = StyleSheet.create({\n  row: {\n    flexDirection: 'row',\n    alignItems: 'top',\n    height: 200,\n  },\n  touchWrap: {\n    flex: 1,\n    height: 100,\n  },\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm10c%2Freact-native-touchable-safe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm10c%2Freact-native-touchable-safe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm10c%2Freact-native-touchable-safe/lists"}