File tree Expand file tree Collapse file tree 2 files changed +34
-9
lines changed
android/src/main/java/com/documentscanner Expand file tree Collapse file tree 2 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,19 @@ public String getName() {
2222 }
2323
2424 @ ReactMethod
25- public void capture (){
26- MainView view = MainView .getInstance ();
27- view .capture ();
25+ public void capture (final int viewTag ) {
26+ final ReactApplicationContext context = getReactApplicationContext ();
27+ UIManagerModule uiManager = context .getNativeModule (UIManagerModule .class );
28+ uiManager .addUIBlock (new UIBlock () {
29+ @ Override
30+ public void execute (NativeViewHierarchyManager nativeViewHierarchyManager ) {
31+ try {
32+ MainView view = (MainView ) nativeViewHierarchyManager .resolveView (viewTag );
33+ view .capture ();
34+ } catch (Exception e ) {
35+ e .printStackTrace ();
36+ }
37+ }
38+ });
2839 }
2940}
Original file line number Diff line number Diff line change 11import React from 'react'
22import {
33 DeviceEventEmitter ,
4+ findNodeHandle ,
5+ NativeModules ,
46 Platform ,
57 requireNativeComponent ,
6- ViewStyle
7- } from 'react-native'
8+ ViewStyle } from 'react-native'
89
910const RNPdfScanner = requireNativeComponent ( 'RNPdfScanner' )
11+ const ScannerManager : any = NativeModules . RNPdfScannerManager
1012
1113export interface PictureTaken {
1214 rectangleCoordinates ?: object ;
@@ -91,15 +93,27 @@ class PdfScanner extends React.Component<PdfScannerProps> {
9193 }
9294
9395 capture ( ) {
94- let native : any = this . ref . current
95- if ( native ) { native . capture ( ) }
96+ if ( this . _scannerHandle ) {
97+ ScannerManager . capture ( this . _scannerHandle )
98+ }
9699 }
97100
98- ref = React . createRef ( ) ;
101+ _scannerRef : any = null ;
102+ _scannerHandle : number | null = null ;
103+ _setReference = ( ref : any ) => {
104+ if ( ref ) {
105+ this . _scannerRef = ref
106+ this . _scannerHandle = findNodeHandle ( ref )
107+ } else {
108+ this . _scannerRef = null
109+ this . _scannerHandle = null
110+ }
111+ } ;
112+
99113 render ( ) {
100114 return (
101115 < RNPdfScanner
102- ref = { this . ref }
116+ ref = { this . _setReference }
103117 { ...this . props }
104118 onPictureTaken = { this . sendOnPictureTakenEvent . bind ( this ) }
105119 onRectangleDetect = { this . sendOnRectangleDetectEvent . bind ( this ) }
You can’t perform that action at this time.
0 commit comments