From 389adfc542fee64c48cf040510bd2dcce8546c74 Mon Sep 17 00:00:00 2001 From: cailenmusselman Date: Thu, 30 Mar 2017 15:15:34 -0600 Subject: [PATCH] findNodeHandle also accepts base react-native components (#15444) * findNodeHandle also accepts base react-native components We're also able to pass in base react-native components like View, TextView, etc. to findNodeHandle * Added static tests for findNodeHandle definition * Removed trailing whitespace * Okay NOW all trailing white-space is removed --- types/react-native/index.d.ts | 2 +- types/react-native/test/index.tsx | 37 ++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 3742bf5003..083c646be7 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -8418,7 +8418,7 @@ export function requireNativeComponent

( extraConfig?: {nativeOnly?: any} ): React.ComponentClass

; -export function findNodeHandle(componentOrHandle: null | number | React.Component): null | number; +export function findNodeHandle(componentOrHandle: null | number | React.Component | React.ComponentClass): null | number; export function processColor(color: any): number; diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 575693211e..45a5b510e9 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -25,6 +25,7 @@ import { View, ViewStyle, ViewPagerAndroid, + findNodeHandle } from 'react-native'; function testDimensions() { @@ -88,20 +89,43 @@ const stylesAlt = StyleSheet.create( } ) +class CustomView extends React.Component<{}, {}> { + + render() { + return ( + Custom View + ); + } + +} class Welcome extends React.Component { refs: { - [key: string]: any - rootView: View + [key: string]: any + rootView: View + customView: CustomView } testNativeMethods() { - // this.setNativeProps({}); + // this.setNativeProps({}); - const { rootView } = this.refs; + const { rootView } = this.refs; + + rootView.measure((x: number, y: number, width: number, height: number) => { + }); + + } + + testFindNodeHandle() { + + const { rootView, customView } = this.refs; + + let nativeComponentHandle = findNodeHandle(rootView); + + let customComponentHandle = findNodeHandle(customView); + + let fromHandle = findNodeHandle(customComponentHandle); - rootView.measure((x: number, y: number, width: number, height: number) => { - }); } render() { @@ -117,6 +141,7 @@ class Welcome extends React.Component { Press Cmd+R to reload,{'\n'} Cmd+D or shake for dev menu + ) }