From 1bbd6ac422340921d115eab7f089358a4d903b77 Mon Sep 17 00:00:00 2001 From: Michal Osadnik Date: Thu, 22 Aug 2019 16:08:51 +0530 Subject: [PATCH] fix: set correct pointer events when active prop changes --- .../stack/src/views/Stack/PointerEventsView.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/stack/src/views/Stack/PointerEventsView.tsx b/packages/stack/src/views/Stack/PointerEventsView.tsx index b4582e7d..8ed409e9 100644 --- a/packages/stack/src/views/Stack/PointerEventsView.tsx +++ b/packages/stack/src/views/Stack/PointerEventsView.tsx @@ -23,6 +23,13 @@ const { block, greaterThan, cond, set, call, onChange } = Animated; * whenever position changes. */ export default class PointerEventsView extends React.Component { + componentDidUpdate(prevProps: Props) { + if (this.props.active !== prevProps.active) { + this.pointerEventsEnabled.setValue(this.props.active ? TRUE : FALSE); + this.setPointerEventsEnabled(this.props.active); + } + } + private pointerEventsEnabled = new Animated.Value( this.props.active ? TRUE : FALSE ); @@ -40,13 +47,17 @@ export default class PointerEventsView extends React.Component { onChange( this.pointerEventsEnabled, call([this.pointerEventsEnabled], ([value]) => { - const pointerEvents = this.props.active && value ? 'box-none' : 'none'; - - this.root && this.root.setNativeProps({ pointerEvents }); + this.setPointerEventsEnabled(Boolean(this.props.active && value)); }) ), ]); + private setPointerEventsEnabled = (enabled: boolean) => { + const pointerEvents = enabled ? 'box-none' : 'none'; + + this.root && this.root.setNativeProps({ pointerEvents }); + }; + private root: View | null = null; render() {