You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://circleci.com/gh/jamesisaac/react-native-touchable-safe)
Consistent view hierarchy and API for React Native `Touchable*` components.
8
+
A single easy-to-use `<Touchable>` component, which harnesses the power of all React Native's`Touchable*` components.
8
9
9
-
As it stands, `TouchableOpacity` and `TouchableHighlight` wrap their children
10
-
in a `View`, whereas `TouchableNativeFeedback` and `TouchableWithoutFeedback`
11
-
do not. This can lead to headaches and platform-specific bugs when trying to
12
-
create advanced Flexbox layouts with different touchable styles on Android/iOS.
10
+
* Simple API that bridges the differences between RN's various `Touchable*` types.
11
+
* A consistent `View` hierarchy, to avoid tricky layout issues when switching between `Touchable*` types.
12
+
* Handling the incompatability of ripple customisation on Android API level < 21.
13
+
14
+
## Motivation
15
+
16
+
As it stands, `TouchableOpacity` and `TouchableHighlight` wrap their children in a `View`, whereas `TouchableNativeFeedback` and `TouchableWithoutFeedback`
17
+
do not.
18
+
This can lead to headaches and platform-specific bugs when trying to create advanced Flexbox layouts with different touchable styles on Android/iOS.
13
19
An example of this is available here: https://snack.expo.io/ry6kXjX8W
14
20
15
-
This component also provides a simpler API, where alternating the component
16
-
used per platform is as simple as:
21
+
This library makes the situation consistent and easy to reason about:
22
+
23
+
*`<Touchable>`**always** introduces another view in the hierarchy, which can have its layout customised with `outerStyle`.
24
+
*`<Touchable>`**always** must only have one child, which it applies its effect (e.g. opacity) to natively.
25
+
26
+
## Installation
27
+
28
+
```bash
29
+
$ npm install --save react-native-touchable-safe
30
+
31
+
# Or, with Yarn
32
+
$ yarn add react-native-touchable-safe
33
+
```
34
+
35
+
## Getting started
36
+
37
+
This component provides a simple API, where alternating the component used per platform is as simple as:
17
38
18
39
```js
19
40
return (
@@ -23,47 +44,35 @@ return (
23
44
)
24
45
```
25
46
26
-
In fact, these are the default behaviours, so simply `<Touchable>` is enough to
27
-
achieve this effect. The android/ios props only need to be used when deviating
28
-
from the defaults.
29
-
30
-
This component also handles the incompatability of ripple customisation on
31
-
Android API level < 21.
32
-
33
-
## Installation
34
-
35
-
```bash
36
-
$ npm install --save react-native-touchable-safe
37
-
```
47
+
In fact, these are the default behaviours, so simply `<Touchable>` is enough to achieve this effect.
48
+
The android/ios props only need to be used when deviating from the defaults.
38
49
39
50
## Props
40
51
41
-
If you don't want to use the defaults (`TouchableNativeFeedback` on Android
42
-
and `TouchableOpacity` on iOS), you can specify another type:
52
+
If you don't want to use the defaults (`TouchableNativeFeedback` on Android and `TouchableOpacity` on iOS), you can specify another type.
53
+
Use `all` to set all platforms to the same effect, or `ios` and `android` to differentiate it per platform.
Some very common behaviours used by all touchable types:
48
60
49
61
***`onPress?`**: `() => void`
50
62
***`outerStyle?`**: `Object | number` - Style to pass to the outer `View`
51
-
component which wraps every type of touchable component. Typically used to
63
+
component which wraps every type of touchable component. Typically used to
52
64
specify things like `<Touchable outerStyle={{ flex: 1 }}>`.
53
65
***`outerProps?`**: `Object` - Similar to `outerStyle`, but lets you set any
54
66
props (although `style` is the main use case).
55
67
***`disabled?`**: `boolean` - Remove any touch functionality and feedback.
56
68
57
-
Seeing as setting a custom native ripple requires calling
58
-
`TouchableNativeFeedback.Ripple`, the following top-level convenience props can
59
-
be used to quickly customise the ripple:
69
+
Seeing as setting a custom native ripple requires calling `TouchableNativeFeedback.Ripple`, the following top-level convenience props can be used to quickly customise the ripple:
60
70
61
71
***`nativeBorderless?`**: `boolean` - For `android="native"`, should the
62
72
ripple effect be borderless.
63
73
***`nativePressColor?`**: `string` - (default: `'rgba(0, 0, 0, .1)'`) - For `android="native"`, what color should the ripple be.
64
74
65
-
Any props which you only want passed to one type of touchable component can be
66
-
controlled with the following props.
75
+
Any props which you only want passed to one type of touchable component can be controlled with the following props.
67
76
68
77
***`nativeProps?`**: `Object` - Any props to pass on to a
69
78
`TouchableNativeFeedback` component.
@@ -73,9 +82,9 @@ controlled with the following props.
73
82
`TouchableHighlight` component.
74
83
***`withoutProps?`**: `Object` - Any props to pass on to a
75
84
`TouchableWithoutFeedback` component.
76
-
85
+
77
86
And finally, anything else will be passed down to all touchable components.
78
-
87
+
79
88
## Examples
80
89
81
90
### Defaults
@@ -88,7 +97,11 @@ import Touchable from 'react-native-touchable-safe'
0 commit comments