From 971428c0cd911b8d089d0f57ec3efe586fee428a Mon Sep 17 00:00:00 2001 From: Ran Greenberg Date: Tue, 28 Jun 2016 12:14:28 +0300 Subject: [PATCH] changes --- example/GalleryScreen.js | 155 +++++++++++------------------- example/ios/example/AppDelegate.m | 2 +- index.js | 2 - 3 files changed, 58 insertions(+), 101 deletions(-) diff --git a/example/GalleryScreen.js b/example/GalleryScreen.js index b619c59..db0d307 100644 --- a/example/GalleryScreen.js +++ b/example/GalleryScreen.js @@ -8,120 +8,72 @@ import { TouchableOpacity, Image, AlertIOS, - CameraRoll + CameraRoll, + Dimensions } from 'react-native'; import _ from 'lodash'; -import Immutable from 'seamless-immutable'; import { - CameraKitGallery + CameraKitGalleryView } from 'react-native-camera-kit'; var groupByEveryN = require('groupByEveryN'); +const ds = new ListView.DataSource({ + rowHasChanged: (r1, r2) => r1 !== r2 +}); -function renderImage(asset) { - var imageSize = 150; - var imageStyle = [styles.image, {width: imageSize, height: imageSize}]; - return ( - - ); -} +const size = Math.floor((Dimensions.get('window').width) / 3); +const innerSize = size - 6; -export default class GalleryScreen extends Component { +export default class GalleryScreenNative extends Component { - constructor(props) { - super(props); - const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); - this.state = { - albums: {}, - dataSource: ds, - albumName: this.props.albumName, - assets: [] + static navigatorButtons = { + rightButtons: [ + { + title: 'Done', + id: 'navBarDone' + } + ] + }; + + async onNavigatorEvent(event) { + if (event.type === 'NavBarButtonPress') { + if (event.id === 'navBarDone') { + const selected = await this.gallery.getSelectedImages(); + + this.props.navigator.push({ + screen: 'media.PreviewScreen', + title: 'Preview', + backButtonTitle: 'Albums', + passProps: { + imagesData: selected.selectedImages + }, + navigatorStyle: { + navBarHidden: true + } + }); + } } } - componentDidMount() { - if (this.state.albumName) { - - CameraKitGallery.getPhotosForAlbum(this.state.albumName, 100, (data) => this._appendAssets(data), (e) => logError(e)); + constructor(props) { + super(props); + this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this)); + this.state = { + album: this.props.album, } } render() { return ( - - {this.state.albumName} - - - - ); - } - - rendererChanged() { - console.log('ppppp'); - var ds = new ListView.DataSource({rowHasChanged: this._rowHasChanged}); - this.state.dataSource = ds.cloneWithRows( - groupByEveryN(this.state.assets, this.props.imagesPerRow) - ); - } - - _renderImage(asset) { - var imageSize = 150; - var imageStyle = [styles.image, {width: imageSize, height: imageSize}]; - return ( - - ); - } - - _renderRow(rowData:Array, sectionID:string, rowID:string) { - console.log(rowID) - var images = rowData.map((image) => { - if (image === null) { - return null; - } - return renderImage(image); - }); - - return ( - - {images} - - ); - } - - _appendAssets(data) { - console.log('datadata', data); - if (data) { - - var assets = data.edges; - var newState:Object = {loadingMore: false}; - - if (!data.page_info.has_next_page) { - newState.noMore = true; - } - - if (assets.length > 0) { - - newState.lastCursor = data.page_info.end_cursor; - newState.assets = this.state.assets.concat(assets); - - newState.dataSource = this.state.dataSource.cloneWithRows( - groupByEveryN(newState.assets, 25) - ); - } - this.setState(newState); - } + { + this.gallery = gallery; + }} + style={{flex:1}} + albumName={this.state.album.albumName}/> + ) } } @@ -146,9 +98,16 @@ const styles = StyleSheet.create({ flex: 1, }, image: { - margin: 4, - marginBottom: 0 + width: innerSize, + height: innerSize, + alignItems: 'center', + justifyContent: 'center' + }, + rowContainer: { + width: size, + height: size, + alignItems: 'center', + justifyContent: 'center', }, }); - diff --git a/example/ios/example/AppDelegate.m b/example/ios/example/AppDelegate.m index 1f3f411..a874c68 100644 --- a/example/ios/example/AppDelegate.m +++ b/example/ios/example/AppDelegate.m @@ -31,7 +31,7 @@ * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://172.31.9.77:8081/index.ios.bundle?platform=ios&dev=true"]; + jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; /** * OPTION 2 diff --git a/index.js b/index.js index f87fb9b..c9f6806 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,9 @@ import CameraKitGallery from './src/CameraKitGallery'; import CameraKitCamera from './src/CameraKitCamera'; -import CameraKitGalleryView from './src/CameraKitGalleryView'; export { CameraKitGallery, CameraKitCamera, - CameraKitGalleryView };