From 1497bb4d725ae91c8219c095c916d3539a70d2fb Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 7 Jul 2020 11:35:54 -0700 Subject: [PATCH] [fix] TouchableWithoutFeedback child ref Fix #1663 --- .../exports/TouchableWithoutFeedback/index.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/react-native-web/src/exports/TouchableWithoutFeedback/index.js b/packages/react-native-web/src/exports/TouchableWithoutFeedback/index.js index f3d5d56a..03199968 100644 --- a/packages/react-native-web/src/exports/TouchableWithoutFeedback/index.js +++ b/packages/react-native-web/src/exports/TouchableWithoutFeedback/index.js @@ -81,12 +81,6 @@ function TouchableWithoutFeedback(props: Props, forwardedRef): React.Node { } = props; const hostRef = useRef(null); - const setRef = setAndForwardRef({ - getForwardedRef: () => forwardedRef, - setLocalRef: hostNode => { - hostRef.current = hostNode; - } - }); const pressConfig = useMemo( () => ({ @@ -121,7 +115,20 @@ function TouchableWithoutFeedback(props: Props, forwardedRef): React.Node { supportedProps.accessible = accessible !== false; supportedProps.accessibilityState = { disabled, ...props.accessibilityState }; supportedProps.focusable = focusable !== false && onPress !== undefined; - supportedProps.ref = setRef; + supportedProps.ref = setAndForwardRef({ + getForwardedRef: () => forwardedRef, + setLocalRef: hostNode => { + const { ref } = element; + if (ref != null) { + if (typeof ref === 'function') { + ref(hostNode); + } else { + ref.current = hostNode; + } + } + hostRef.current = hostNode; + } + }); const elementProps = Object.assign(supportedProps, pressEventHandlers);