1. Phenomenon1. Requirement: Capture a certain display page and save it to the album, and share it in the form of a poster; 2. Support iOS and Android 2. Solution1. Installation: npm i --save react-native-view-shot 2. Link processing: react-native link react-native-view-shot 3. When running on iOS, you also need to execute the following command (not required for Android): cd ios && pod install && cd .. 4. Use: (1) References: import { captureRef } from "react-native-view-shot"; (2) Template: <View ref="shareImageRef">Here is the content to be displayed</View> (3) Methods: // Get the intercepted image link doDownLoadImage = () => { captureRef(this.refs.shareImageRef, { format: "jpg", quality: 0.8 }).then( uri => { console.error("Link is:", uri) }, error => { console.error("Error message:", error) } ); } // Evolution method, get the intercepted image link and save it to the album doDownLoadImage = () => { captureRef(this.refs.shareImageRef, { format: "jpg", quality: 0.8 }).then( uri => { console.error("Link is:", uri) let promise = CameraRoll.saveToCameraRoll(uri); promise .then((result) => { alert('Save successfully!'); }) .catch((error) => { alert('Save failed!'); }); }, error => { console.error("Error message:", error) } ); } Note: Save the reference (self-installation): import CameraRoll from '@react-native-community/cameraroll'; // Convert the generated link to base64 and process it into a shareable link doShareImg = () => { captureRef(this.refs.shareImageRef, { format: "jpg", quality: 0.8 }).then( uri => { console.error("Link is:", uri) RNFS.readFile(uri, 'base64') .then((content) => { // The shared poster image address is: const link = 'data:image/png;base64,' + content console.log("The shared poster image address is" + link) }) .catch((err) => { console.log("reading error: " + err); }); }, error => { console.error("Error message:", error) } ); } Note: The image is converted to base64 and referenced: import RNFS from 'react-native-fs'; 3. Summary:More usage methods and parameters can be obtained as needed: https://www.npmjs.com/package/react-native-view-shot TIPS: You may encounter such a problem on Android, as shown in the figure: Trying to resolve view with tag 2573 which doesn't exist or Trying to resolve view with tag 2105 which doesn't exist I encountered both of these phenomena. The solution is to add a background color to the content that needs to be intercepted. If you add to the module: <View ref="shareImageRef" style={{backgroundColor: 'white'}}>Here is the content to be displayed</View> This is the end of this article about the introduction and use of React-Native screenshot component react-native-view-shot. For more relevant React Native screenshot component content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: VMware15 installation of Deepin detailed tutorial (picture and text)
>>: Detailed tutorial on installing MySQL 8.0.19 in zip version on win10
1. Experimental description In the virtual machin...
Build a simulation environment: Operating system:...
Today I saw a friend asking a question in the Q&a...
Preview versions of Safari (Technology Preview 10...
This article shares the installation tutorial of ...
Table of contents 1. View the tables in the curre...
1. Use the df command to view the overall disk us...
1. Download First of all, I would like to recomme...
Preface Recently, during an interview, I was aske...
Table of contents Understand the core concept of ...
Table of contents Preface props context state Sum...
This article example shares the specific code of ...
MySQL5.6.40 installation process under CentOS7 64...
Without further ado, I will post the code for you...
Some time ago, the blogger installed the Ubuntu s...