Skip to content

Commit 8222cf4

Browse files
okb1100iRoachie
authored andcommitted
Add enablePointerEvents prop to Collapsible (oblador#250)
1 parent 082c77b commit 8222cf4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Collapsible.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class Collapsible extends Component {
1010
align: PropTypes.oneOf(['top', 'center', 'bottom']),
1111
collapsed: PropTypes.bool,
1212
collapsedHeight: PropTypes.number,
13+
enablePointerEvents: PropTypes.bool,
1314
duration: PropTypes.number,
1415
easing: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
1516
style: ViewPropTypes.style,
@@ -21,6 +22,7 @@ export default class Collapsible extends Component {
2122
align: 'top',
2223
collapsed: true,
2324
collapsedHeight: 0,
25+
enablePointerEvents: false,
2426
duration: 300,
2527
easing: 'easeOutCubic',
2628
onAnimationEnd: () => null,
@@ -165,7 +167,7 @@ export default class Collapsible extends Component {
165167
};
166168

167169
render() {
168-
const { collapsed } = this.props;
170+
const { collapsed, enablePointerEvents } = this.props;
169171
const { height, contentHeight, measuring, measured } = this.state;
170172
const hasKnownHeight = !measuring && (measured || collapsed);
171173
const style = hasKnownHeight && {
@@ -196,7 +198,10 @@ export default class Collapsible extends Component {
196198
];
197199
}
198200
return (
199-
<Animated.View style={style} pointerEvents={collapsed ? 'none' : 'auto'}>
201+
<Animated.View
202+
style={style}
203+
pointerEvents={!enablePointerEvents && collapsed ? 'none' : 'auto'}
204+
>
200205
<Animated.View
201206
ref={this._handleRef}
202207
style={[this.props.style, contentStyle]}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Collapsible from 'react-native-collapsible';
2626
| **`align`** | Alignment of the content when transitioning, can be `top`, `center` or `bottom` | `top` |
2727
| **`collapsed`** | Whether to show the child components or not | `true` |
2828
| **`collapsedHeight`** | Which height should the component collapse to | `0` |
29+
| **`enablePointerEvents`** | Enable pointer events on collapsed view | `false` |
2930
| **`duration`** | Duration of transition in milliseconds | `300` |
3031
| **`easing`** | Function or function name from [`Easing`](https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/Easing.js) (or [`tween-functions`](https://github.com/chenglou/tween-functions) if < RN 0.8). Collapsible will try to combine `Easing` functions for you if you name them like `tween-functions`. | `easeOutCubic` |
3132
| **`style`** | Optional styling for the container | |

index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ export interface CollapsibleProps {
6363
*/
6464
duration?: number;
6565

66+
/**
67+
* Enable pointer events on collapsed view
68+
*
69+
* @default false
70+
*/
71+
enablePointerEvents?: boolean;
72+
6673
/**
6774
* Function or function name from Easing (or tween-functions if < RN 0.8). Collapsible will try to combine Easing functions for you if you name them like tween-functions
6875
*

0 commit comments

Comments
 (0)