Skip to content

Commit 5ebf1bb

Browse files
committed
Hacky, but working fix for collection order when sortDescriptors is provided.
1 parent 495a1e1 commit 5ebf1bb

6 files changed

Lines changed: 185 additions & 218 deletions

File tree

example/index.ios-ajax.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
* @flow
5+
*/
6+
7+
import React, { Component } from 'react';
8+
import { AppRegistry, StyleSheet, Text, View, Image } from 'react-native';
9+
import RNPhotosFramework from './react-native-photos-framework';
10+
import {postAsset, postAssets} from './react-native-photos-framework/src/ajax-helper';
11+
12+
export default class Example extends Component {
13+
14+
constructor() {
15+
super();
16+
this.state = {
17+
images: []
18+
};
19+
}
20+
21+
componentDidMount() {
22+
RNPhotosFramework.requestAuthorization().then((statusObj) => {
23+
if (statusObj.isAuthorized) {
24+
RNPhotosFramework.getAlbums({
25+
type: 'smartAlbum',
26+
subType: 'smartAlbumUserLibrary',
27+
assetCount: 'exact',
28+
fetchOptions: {
29+
sortDescriptors: [
30+
{
31+
key: 'title',
32+
ascending: true
33+
}
34+
],
35+
includeHiddenAssets: false,
36+
includeAllBurstAssets: false
37+
},
38+
//When you say 'trackInsertsAndDeletes or trackChanges' for an albums query result,
39+
//They will be cached and tracking will start.
40+
//Call queryResult.stopTracking() to stop this. ex. on componentDidUnmount
41+
trackInsertsAndDeletes: true,
42+
trackChanges: false
43+
44+
}).then((queryResult) => {
45+
const album = queryResult.albums[0];
46+
return album.getAssets({
47+
fetchOptions: {
48+
// mediaTypes: ['video']
49+
},
50+
includeResourcesMetadata : true,
51+
52+
//The fetch-options from the outer query will apply here, if we get
53+
startIndex: 0,
54+
endIndex: 10,
55+
//When you say 'trackInsertsAndDeletes or trackAssetsChange' for an albums assets,
56+
//They will be cached and tracking will start.
57+
//Call album.stopTracking() to stop this. ex. on componentDidUnmount
58+
trackInsertsAndDeletes: true,
59+
trackChanges: false
60+
}).then((response) => {
61+
/* response.assets[1].getImageMetadata().then((asset) => {
62+
debugger;
63+
});*/
64+
setTimeout(() => {
65+
const assets = [response.assets[0], response.assets[1]];
66+
postAssets(assets, {
67+
url: 'http://localhost:3000/upload',
68+
headers : {},
69+
onProgress: (progressPercentage, details) => {
70+
console.log('On Progress called', progressPercentage);
71+
},
72+
onComplete : (asset, status, responseText, xhr) => {
73+
console.log('Asset upload completed successfully');
74+
},
75+
onError : (asset, status, responseText, xhr) => {
76+
console.log('Asset upload failed');
77+
},
78+
onFinnished : (completedItems) => {
79+
console.log('Operation complete');
80+
},
81+
modifyAssetData : (postableAsset, asset) => {
82+
postableAsset.name = `${postableAsset.name}-special-name-maybe-guid.jpg`;
83+
return postableAsset;
84+
}
85+
}).then((result) => {
86+
console.log('Operation complete, promise resolved', result);
87+
});
88+
}, 2000);
89+
90+
this.setState({
91+
images: [response.assets[0]]
92+
});
93+
});
94+
});
95+
}
96+
});
97+
}
98+
99+
renderImage(asset, index) {
100+
return (
101+
<Image key={index} source={asset.image} style={{ width: 100, height: 100 }}></Image>
102+
);
103+
}
104+
105+
render() {
106+
return (
107+
<View style={styles.container}>
108+
{this.state.images.map(this.renderImage.bind(this))}
109+
</View>
110+
);
111+
}
112+
}
113+
114+
const styles = StyleSheet.create({
115+
container: {
116+
flex: 1,
117+
justifyContent: 'center',
118+
alignItems: 'center',
119+
backgroundColor: '#F5FCFF'
120+
},
121+
welcome: {
122+
fontSize: 20,
123+
textAlign: 'center',
124+
margin: 10
125+
},
126+
instructions: {
127+
textAlign: 'center',
128+
color: '#333333',
129+
marginBottom: 5
130+
}
131+
});
132+
133+
AppRegistry.registerComponent('Example', () => Example);

example/index.ios-old.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

example/index.ios.js

Lines changed: 31 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,40 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
1+
console.debug = console.debug || console.log;
72
import React, { Component } from 'react';
8-
import { AppRegistry, StyleSheet, Text, View, Image } from 'react-native';
9-
import RNPhotosFramework from './react-native-photos-framework';
10-
import {postAsset, postAssets} from './react-native-photos-framework/src/ajax-helper';
11-
12-
export default class Example extends Component {
13-
14-
constructor() {
15-
super();
16-
this.state = {
17-
images: []
18-
};
19-
}
3+
import { AppRegistry, StyleSheet, Text, View, TouchableOpacity, AlertIOS } from 'react-native';
4+
import AlbumList from './album-list';
5+
import { Scene, Router } from 'react-native-router-flux';
6+
import CameraRollPicker from './react-native-camera-roll-picker';
7+
import { Actions } from 'react-native-router-flux'
208

21-
componentDidMount() {
22-
RNPhotosFramework.requestAuthorization().then((statusObj) => {
23-
if (statusObj.isAuthorized) {
24-
RNPhotosFramework.getAlbums({
25-
type: 'smartAlbum',
26-
subType: 'smartAlbumUserLibrary',
27-
assetCount: 'exact',
28-
fetchOptions: {
29-
sortDescriptors: [
30-
{
31-
key: 'title',
32-
ascending: true
33-
}
34-
],
35-
includeHiddenAssets: false,
36-
includeAllBurstAssets: false
37-
},
38-
//When you say 'trackInsertsAndDeletes or trackChanges' for an albums query result,
39-
//They will be cached and tracking will start.
40-
//Call queryResult.stopTracking() to stop this. ex. on componentDidUnmount
41-
trackInsertsAndDeletes: true,
42-
trackChanges: false
439

44-
}).then((queryResult) => {
45-
const album = queryResult.albums[0];
46-
return album.getAssets({
47-
fetchOptions: {
48-
// mediaTypes: ['video']
49-
},
50-
includeResourcesMetadata : true,
51-
52-
//The fetch-options from the outer query will apply here, if we get
53-
startIndex: 0,
54-
endIndex: 10,
55-
//When you say 'trackInsertsAndDeletes or trackAssetsChange' for an albums assets,
56-
//They will be cached and tracking will start.
57-
//Call album.stopTracking() to stop this. ex. on componentDidUnmount
58-
trackInsertsAndDeletes: true,
59-
trackChanges: false
60-
}).then((response) => {
61-
/* response.assets[1].getImageMetadata().then((asset) => {
62-
debugger;
63-
});*/
64-
setTimeout(() => {
65-
const assets = [response.assets[0], response.assets[1]];
66-
postAssets(assets, {
67-
url: 'http://localhost:3000/upload',
68-
headers : {},
69-
onProgress: (progressPercentage, details) => {
70-
console.log('On Progress called', progressPercentage);
71-
},
72-
onComplete : (asset, status, responseText, xhr) => {
73-
console.log('Asset upload completed successfully');
74-
},
75-
onError : (asset, status, responseText, xhr) => {
76-
console.log('Asset upload failed');
77-
},
78-
onFinnished : (completedItems) => {
79-
console.log('Operation complete');
80-
},
81-
modifyAssetData : (postableAsset, asset) => {
82-
postableAsset.name = `${postableAsset.name}-special-name-maybe-guid.jpg`;
83-
return postableAsset;
84-
}
85-
}).then((result) => {
86-
console.log('Operation complete, promise resolved', result);
87-
});
88-
}, 2000);
89-
90-
this.setState({
91-
images: [response.assets[0]]
92-
});
93-
});
94-
});
95-
}
96-
});
97-
}
98-
99-
renderImage(asset, index) {
100-
return (
101-
<Image key={index} source={asset.image} style={{ width: 100, height: 100 }}></Image>
102-
);
103-
}
10+
export default class Example extends Component {
10411

105-
render() {
106-
return (
107-
<View style={styles.container}>
108-
{this.state.images.map(this.renderImage.bind(this))}
109-
</View>
110-
);
111-
}
12+
constructor() {
13+
super();
14+
this.state = {
15+
albumEditMode: false
16+
};
17+
}
18+
19+
render() {
20+
return (
21+
<Router>
22+
<Scene key="root">
23+
<Scene
24+
key="albumList"
25+
component={AlbumList}
26+
title="Album" />
27+
<Scene key="cameraRollPicker" component={CameraRollPicker} title="Bilder" />
28+
</Scene>
29+
</Router>
30+
);
31+
}
11232
}
11333

11434
const styles = StyleSheet.create({
115-
container: {
116-
flex: 1,
117-
justifyContent: 'center',
118-
alignItems: 'center',
119-
backgroundColor: '#F5FCFF'
120-
},
121-
welcome: {
122-
fontSize: 20,
123-
textAlign: 'center',
124-
margin: 10
125-
},
126-
instructions: {
127-
textAlign: 'center',
128-
color: '#333333',
129-
marginBottom: 5
130-
}
35+
container: {
36+
flex: 1
37+
}
13138
});
13239

133-
AppRegistry.registerComponent('Example', () => Example);
40+
AppRegistry.registerComponent('Example', () => Example);

example/react-native-camera-roll-picker/camera-roll-picker.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from 'react-native';
1111
import ImageItem from './ImageItem';
1212
import RNPhotosFramework from '../react-native-photos-framework';
13+
import {postAssets} from '../react-native-photos-framework/src/ajax-helper'
1314
var simple_timer = require('simple-timer')
1415

1516
class CameraRollPicker extends Component {
@@ -94,36 +95,14 @@ class CameraRollPicker extends Component {
9495
startIndex: this.state.images.length,
9596
endIndex: this.state.images.length + 20,
9697
fetchOptions: {
97-
// includeHiddenAssets: true,
98+
includeHiddenAssets: true,
9899
sortDescriptors: [{
99100
key: 'creationDate',
100-
ascending: true
101+
ascending: false
101102
}]
102103
},
103-
assetDisplayBottomUp: false,
104-
assetDisplayStartToEnd: false
105104
})
106105
.then((data) => {
107-
108-
setTimeout(() => {
109-
data.assets[0].postAsset().then((result) => {
110-
111-
});
112-
/* var photo = {
113-
uri: 'testimage.jpg',
114-
type: 'image/jpeg',
115-
name: 'testimagefff.jpg',
116-
};
117-
118-
var body = new FormData();
119-
// body.append('photo', photo);
120-
121-
body.append('photo', data.assets[0].image);
122-
var xhr = new XMLHttpRequest();
123-
xhr.open('POST', 'http://localhost:3000/upload');
124-
xhr.send(body);*/
125-
}, 2000);
126-
127106
console.log(data.assets.map(x => x.collectionIndex));
128107
simple_timer.stop('fetch_timer');
129108
console.log('react-native-photos-framework fetch request took %s milliseconds.', simple_timer.get('fetch_timer').delta)

0 commit comments

Comments
 (0)