File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 99 */
1010
1111declare module 'react-native-view-shot' {
12- import { Component , ReactInstance } from 'react'
12+ import { Component , ReactInstance , RefObject } from 'react'
1313 import { ViewStyle } from 'react-native'
1414
1515 export interface CaptureOptions {
@@ -81,11 +81,11 @@ declare module 'react-native-view-shot' {
8181 /**
8282 * lower level imperative API
8383 *
84- * @param {React.ReactInstance } viewRef
84+ * @param {React.ReactInstance | RefObject } viewRef
8585 * @param {"react-native-view-shot".CaptureOptions } options
8686 * @return {Promise<string> } Returns a Promise of the image URI.
8787 */
88- export function captureRef ( viewRef : ReactInstance , options ?: CaptureOptions ) : Promise < string >
88+ export function captureRef < T > ( viewRef : ReactInstance | RefObject < T > , options ?: CaptureOptions ) : Promise < string >
8989
9090 /**
9191 * This method release a previously captured uri. For tmpfile it will clean them out, for other result types it
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import React, { Component } from "react";
33import { View , NativeModules , Platform , findNodeHandle } from "react-native" ;
44const { RNViewShot } = NativeModules ;
55
6- import type { Element , ElementRef } from 'react' ;
6+ import type { Element , ElementRef , ElementType , Ref } from 'react' ;
77import type { ViewStyleProp } from 'StyleSheet' ;
88import type { LayoutEvent } from 'CoreEventTypes' ;
99
@@ -88,10 +88,13 @@ function validateOptions(
8888 return { options, errors } ;
8989}
9090
91- export function captureRef (
92- view : number | ?View ,
91+ export function captureRef < T : ElementType > (
92+ view : number | ?View | Ref < T > ,
9393 optionsObject ? : Object
9494) : Promise < string > {
95+ if ( view && typeof view === "object" && "current" in view && view . current ) { // React.RefObject
96+ view = view . current ;
97+ }
9598 if ( typeof view !== "number" ) {
9699 const node = findNodeHandle ( view ) ;
97100 if ( ! node )
You can’t perform that action at this time.
0 commit comments