gre / react-native-view-shot

Snapshot a React Native view and save it to an image
https://github.com/gre/react-native-view-shot-example
MIT License
2.64k stars 343 forks source link

The view cannot be captured. drawViewHierarchyInRect was not successful. This is a potential technical or security limitation. #477

Open daheeahn opened 1 year ago

daheeahn commented 1 year ago

I faced these errors What is the error and how can I fix it?

my code

captureRef.current.capture()
  .then(uri => {
    // success
  })
  .catch(e => {
    // fail
    console.log(e);
  });

error

 {"code":"EUNSPECIFIED","message":"The view cannot be captured. drawViewHierarchyInRect was not successful. This is a potential technical or security limitation.","domain":"RCTErrorDomain","userInfo":null,"nativeStackIOS":["0   roubit                              0x0000000100a3be18 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 676124","1   roubit                              0x0000000100a12db4 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 508088","2   roubit                              0x0000000100cf80c0 __cxa_throw + 1658776","3   roubit                              0x0000000100a37384 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 657032","4   roubit                              0x0000000100a37474 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 657272","5   libdispatch.dylib                   0x000000019995c320 B74732B5-D7FE-34A4-9346-41945701F020 + 8992","6   libdispatch.dylib                   0x000000019995deac B74732B5-D7FE-34A4-9346-41945701F020 + 16044","7   libdispatch.dylib                   0x000000019996c6a4 B74732B5-D7FE-34A4-9346-41945701F020 + 75428","8   libdispatch.dylib                   0x000000019996c2f4 _dispatch_main_queue_callback_4CF + 44","9   CoreFoundation                      0x000000019252dd18 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 625944","10  CoreFoundation                      0x000000019250f650 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 501328","11  CoreFoundation                      0x00000001925144dc CFRunLoopRunSpecific + 612","12  GraphicsServices                    0x00000001cd77435c GSEventRunModal + 164","13  UIKitCore                           0x00000001948a037c B0858D8E-7220-37BF-873F-ECC2B0A358C3 + 3789692","14  UIKitCore                           0x000000019489ffe0 UIApplicationMain + 340","15  roubit                              0x0000000100578ba4 roubit + 19364","16  dyld                                0x00000001b199cdec 41605DC7-F412-37D1-B51B-FEE1A26701E9 + 89580"]}
iliapnmrv commented 10 months ago
const filepath = await captureRef(viewShotRef, {
     format: 'jpg',
     quality: 0.9,
     useRenderInContext: true,
});

<ViewShot ref={viewShotRef}>
          ...
</ViewShot>         

captureRef was the solution for me

Akyna commented 9 months ago

The same error for IOS

[Error: The view cannot be captured. drawViewHierarchyInRect was not successful. This is a potential technical or security limitation.]
"react-native": "0.72.7",
Akyna commented 9 months ago
const filepath = await captureRef(viewShotRef, {
     format: 'jpg',
     quality: 0.9,
     useRenderInContext: true,
});

<ViewShot ref={viewShotRef}>
          ...
</ViewShot>         

captureRef was the solution for me

It didn't fix the error for me

iliapnmrv commented 9 months ago

@Akyna can you please share more data? "react-native": "0.72.7" works fine for me

Akyna commented 9 months ago

@Akyna can you please share more data? "react-native": "0.72.7" works fine for me

"react-native-view-shot": "^3.8.0",

cc @iliapnmrv

Akyna commented 9 months ago

@iliapnmrv this help

useRenderInContext: true,

Thx!