mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Animated: Forward Ref to Component
Summary: Changes `createAnimatedComponent` so that a `ref` assigned to an Animated component will now be forwarded to the internal component. Previously, a ref to the internal component was accessed using the `getNode` method. The `getNode` method is now deprecated and will return the same `ref` but show a deprecation error. Changelog: [General] [Changed] - Refs on an Animated component are now the internal component. The `getNode` call has been deprecated. Reviewed By: TheSavior Differential Revision: D18290474 fbshipit-source-id: 5849809583a17624a89071db8be1282a12caedf3
This commit is contained in:
committed by
Facebook Github Bot
parent
894ee72278
commit
66e72bb4e0
@@ -25,6 +25,8 @@ const {
|
||||
View,
|
||||
} = require('react-native');
|
||||
|
||||
import {useEffect, useRef, useState} from 'react';
|
||||
|
||||
const forceTouchAvailable =
|
||||
(Platform.OS === 'ios' && Platform.constants.forceTouchAvailable) || false;
|
||||
|
||||
@@ -299,6 +301,48 @@ class TouchableHitSlop extends React.Component<{}, $FlowFixMeState> {
|
||||
}
|
||||
}
|
||||
|
||||
function TouchableNativeMethodChecker<
|
||||
T: React.AbstractComponent<any, any>,
|
||||
>(props: {|Component: T, name: string|}): React.Node {
|
||||
const [status, setStatus] = useState<?boolean>(null);
|
||||
const ref = useRef<?React.ElementRef<T>>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setStatus(ref.current != null && typeof ref.current.measure === 'function');
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View style={[styles.row, styles.block]}>
|
||||
<props.Component ref={ref}>
|
||||
<View />
|
||||
</props.Component>
|
||||
<Text>
|
||||
{props.name + ': '}
|
||||
{status == null
|
||||
? 'Missing Ref!'
|
||||
: status === true
|
||||
? 'Native Methods Exist'
|
||||
: 'Native Methods Missing!'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function TouchableNativeMethods() {
|
||||
return (
|
||||
<View>
|
||||
<TouchableNativeMethodChecker
|
||||
Component={TouchableHighlight}
|
||||
name="TouchableHighlight"
|
||||
/>
|
||||
<TouchableNativeMethodChecker
|
||||
Component={TouchableOpacity}
|
||||
name="TouchableOpacity"
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
class TouchableDisabled extends React.Component<{}> {
|
||||
render() {
|
||||
return (
|
||||
@@ -551,6 +595,13 @@ exports.examples = [
|
||||
return <TouchableHitSlop />;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Touchable Native Methods',
|
||||
description: ('Some <Touchable*> components expose native methods like `measure`.': string),
|
||||
render: function(): React.Element<any> {
|
||||
return <TouchableNativeMethods />;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Disabled Touchable*',
|
||||
description: ('<Touchable*> components accept disabled prop which prevents ' +
|
||||
|
||||
Reference in New Issue
Block a user