React Native Study-cameraroll

Source: Internet
Author: User

The Cameraroll module in React-native provides the ability to access local albums.

In the react version of 0.23.0, Android is not supported, and the use of Cameraroll in iOS requires us to do it manually:

Ios:

    1. Add Rctcameraroll.xcodeproj to our project: Expand Project > Libraies Right-libraies click "Add Files to ' project name '" To locate the project folder/node_modules/ React-native/libraries/cameraroll/rctcameraroll.xcodeproj, added to the project.
    2. We're going to add LIBRCTCAMERAROLL.A to the link Binary with libraries of the main project, such as:

With this addition, we can use the Cameraroll function in the project without error.

There are two functions in the Cameraroll module: Saveimagewithtag (), Getphotos ().

Saveimagewithtag ()

Save an image to an album.

@param {string} tag on Android, this parameter is a local URI, for example "file:///sdcard/img.png" .

On an iOS device, it may be one of the following:

    • Local URI
    • Tags for the resource pool
    • Not more than two types, which means that the picture data will be stored in memory (and will always occupy memory while the process continues).

Returns a promise that returns a new URI when the operation succeeds.

Example:

Cameraroll.saveimagewithtag (image). Then (function (Success) {Alert.alert ("',                'Save to album success', [{text:'Determine', onpress: () =Console.log (Success)}] )}, function (Error) {Alert.alert ("',                'failed to save to album', [{text:'Determine', onpress: () =Console.log (Error)}] )        }    )}
get the photos in the album. Getphotos ()

Learning this feature is learned in the official demo, it is written in a can use JS file camerarollview.js, we need to introduce this file into our project.

Accessories: Camerarollview.js

File Open will have an error display, but the syntax is not the same, this does not affect the effect.

How to use:

Import Camerarollview from '.. /camerarollview'; exportdefault classCamerarollview extends Component {constructor (props) {super (props); Cameraroll.getphotos ({first: +, Assettype:'Photos'}). Then (function (data) {}, function (Error) {})} _renderimage (asset) {varWindowSize = require ('Dimensions').Get('window'); return (            <touchableopacity key={asset}> <image Source={asset.node.image} style={{width: (windowSize.width- -)/3, Height: the, margin:5}}/> </TouchableOpacity>        ); } render () {return(<view Style={{flex:1}}> <camerarollview renderimage={ This._renderimage}/> </View>        )    }}

React Native Study-cameraroll

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.