2015-03-11 02:11:28 +00:00
|
|
|
/**
|
2016-07-12 12:51:57 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule CameraRollExample
|
2015-03-11 02:11:28 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
2016-01-14 12:31:51 +00:00
|
|
|
const {
|
2015-03-11 02:11:28 +00:00
|
|
|
CameraRoll,
|
|
|
|
Image,
|
2016-06-14 05:15:47 +00:00
|
|
|
Slider,
|
2015-03-11 02:11:28 +00:00
|
|
|
StyleSheet,
|
2016-01-14 12:31:51 +00:00
|
|
|
Switch,
|
2015-03-11 02:11:28 +00:00
|
|
|
Text,
|
|
|
|
View,
|
2015-07-21 12:39:57 +00:00
|
|
|
TouchableOpacity
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-10-16 09:12:20 +00:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
2016-09-06 21:31:15 +00:00
|
|
|
|
2016-01-14 12:31:51 +00:00
|
|
|
const CameraRollView = require('./CameraRollView');
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-01-14 12:31:51 +00:00
|
|
|
const AssetScaledImageExampleView = require('./AssetScaledImageExample');
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class CameraRollExample extends React.Component {
|
|
|
|
state = {
|
|
|
|
groupTypes: 'SavedPhotos',
|
|
|
|
sliderValue: 1,
|
|
|
|
bigImages: true,
|
|
|
|
};
|
2016-09-06 21:31:15 +00:00
|
|
|
_cameraRollView: ?CameraRollView;
|
2015-03-11 02:11:28 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
2016-01-14 12:31:51 +00:00
|
|
|
<Switch
|
2015-03-11 02:11:28 +00:00
|
|
|
onValueChange={this._onSwitchChange}
|
2016-09-06 21:31:15 +00:00
|
|
|
value={this.state.bigImages}
|
|
|
|
/>
|
2015-03-11 02:11:28 +00:00
|
|
|
<Text>{(this.state.bigImages ? 'Big' : 'Small') + ' Images'}</Text>
|
2016-06-14 05:15:47 +00:00
|
|
|
<Slider
|
2015-03-11 02:11:28 +00:00
|
|
|
value={this.state.sliderValue}
|
|
|
|
onValueChange={this._onSliderChange}
|
|
|
|
/>
|
|
|
|
<Text>{'Group Type: ' + this.state.groupTypes}</Text>
|
|
|
|
<CameraRollView
|
2016-09-06 21:31:15 +00:00
|
|
|
ref={(ref) => { this._cameraRollView = ref; }}
|
2015-07-21 12:39:57 +00:00
|
|
|
batchSize={20}
|
2015-03-11 02:11:28 +00:00
|
|
|
groupTypes={this.state.groupTypes}
|
|
|
|
renderImage={this._renderImage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
loadAsset = (asset) => {
|
2016-01-14 12:31:51 +00:00
|
|
|
if (this.props.navigator) {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: 'Camera Roll Image',
|
|
|
|
component: AssetScaledImageExampleView,
|
|
|
|
backButtonTitle: 'Back',
|
|
|
|
passProps: { asset: asset },
|
|
|
|
});
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-07-21 12:39:57 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_renderImage = (asset) => {
|
2016-01-14 12:31:51 +00:00
|
|
|
const imageSize = this.state.bigImages ? 150 : 75;
|
|
|
|
const imageStyle = [styles.image, {width: imageSize, height: imageSize}];
|
2016-09-06 21:31:15 +00:00
|
|
|
const {location} = asset.node;
|
|
|
|
const locationStr = location ? JSON.stringify(location) : 'Unknown location';
|
2015-03-11 02:11:28 +00:00
|
|
|
return (
|
2015-12-12 05:21:02 +00:00
|
|
|
<TouchableOpacity key={asset} onPress={ this.loadAsset.bind( this, asset ) }>
|
|
|
|
<View style={styles.row}>
|
2015-07-21 12:39:57 +00:00
|
|
|
<Image
|
|
|
|
source={asset.node.image}
|
|
|
|
style={imageStyle}
|
|
|
|
/>
|
|
|
|
<View style={styles.info}>
|
|
|
|
<Text style={styles.url}>{asset.node.image.uri}</Text>
|
2016-09-06 21:31:15 +00:00
|
|
|
<Text>{locationStr}</Text>
|
2015-07-21 12:39:57 +00:00
|
|
|
<Text>{asset.node.group_name}</Text>
|
|
|
|
<Text>{new Date(asset.node.timestamp).toString()}</Text>
|
|
|
|
</View>
|
2015-03-11 02:11:28 +00:00
|
|
|
</View>
|
2015-07-21 12:39:57 +00:00
|
|
|
</TouchableOpacity>
|
2015-03-11 02:11:28 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onSliderChange = (value) => {
|
2016-01-14 12:31:51 +00:00
|
|
|
const options = CameraRoll.GroupTypesOptions;
|
|
|
|
const index = Math.floor(value * options.length * 0.99);
|
|
|
|
const groupTypes = options[index];
|
2015-03-11 02:11:28 +00:00
|
|
|
if (groupTypes !== this.state.groupTypes) {
|
|
|
|
this.setState({groupTypes: groupTypes});
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onSwitchChange = (value) => {
|
2016-09-06 21:31:15 +00:00
|
|
|
invariant(this._cameraRollView, 'ref should be set');
|
|
|
|
this._cameraRollView.rendererChanged();
|
2015-03-11 02:11:28 +00:00
|
|
|
this.setState({ bigImages: value });
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-01-14 12:31:51 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-03-11 02:11:28 +00:00
|
|
|
row: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
fontSize: 9,
|
|
|
|
marginBottom: 14,
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
margin: 4,
|
|
|
|
},
|
|
|
|
info: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-07-21 12:39:57 +00:00
|
|
|
exports.title = 'Camera Roll';
|
2015-03-11 02:11:28 +00:00
|
|
|
exports.description = 'Example component that uses CameraRoll to list user\'s photos';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Photos',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> { return <CameraRollExample />; }
|
2015-03-11 02:11:28 +00:00
|
|
|
}
|
|
|
|
];
|