jeanpan / react-native-camera-roll-picker

📷 A React Native component providing images selection from camera roll
https://www.npmjs.com/package/react-native-camera-roll-picker
MIT License
422 stars 176 forks source link

is there a way to preselect items? #12

Closed ndao closed 8 years ago

ndao commented 8 years ago

Hi, after selecting some images, I would like to preserve the state so when I go back to it they're already selected. Is there a way to do that currently?

Thanks!

jeanpan commented 8 years ago

@ndao. I will prepare a commit for preserving the state by passing an array of selected image as a props to the component and setting this props as the default value of selected state.

jeanpan commented 8 years ago

@ndao. Now you can pass a selected array as a props to the component, as the example here https://github.com/jeanpan/react-native-camera-roll-picker/blob/master/Example/index.ios.js#L50 to preserve the selected state. Let me know if this solve your problem.

ndao commented 8 years ago

@jeanpan wow that was fast! thanks so much! Question: in the latest version, the callback now returns an array of Objects whereas before it was returning an array of string. As they're objects now, this won't return the right index https://github.com/jeanpan/react-native-camera-roll-picker/blob/master/index.js#L159 to satisfy the selected state. it is breaking for me. thoughts?

jeanpan commented 8 years ago

@ndao. Yes, before the callback returns an array of string ( image uri ) but now it returns an array of Objects ( image object ). The indexOf works fine for me. Is your selected state a object array or a string array ? Could you please provide me your code so I can help you to fix the problem ?

ndao commented 8 years ago

@jeanpan, i am basically using Redux to store the objects that returned from callback and pass it back again to CameraRollPicker component Below is what the array of objects looks like image like so

<View
        style={{flex: 1, flexDirection: 'column'}}>
          <CameraRollPicker
            groupTypes='All'
            maximum={15}
            assetType='All'
            imagesPerRow={3}
            imageMargin={5}
            selectedMarker={<Marker />}
            selected={selected}
            callback={this.props.attachPhotos} />
      </View>
ndao commented 8 years ago

it also looks like the Camera component adds the selected array that i am passing in to its state (but not showing those images are selected). it then returns all the newly selected items PLUS the selected array items that was passed in.

jeanpan commented 8 years ago

@ndao It seems there is something wrong with selected state. I will fix it asap. Thanks for the comments.

jeanpan commented 8 years ago

@ndao I fixed the problem in the latest version ( 1.1.5 ). Please check it and let me know if there is any problem. Thanks !

ndao commented 8 years ago

looks like 1.1.5 fixed it! thanks so much!

ndao commented 8 years ago

@jeanpan, there's another issue. The selected state is kept despite new selected props being passed in. perhaps it needs a componentWillReceiveProps to update state.

jeanpan commented 8 years ago

@ndao ok. Will fix it asap. Thanks!

jeanpan commented 8 years ago

@ndao Fixed at the latest version 1.1.6. Please let me know if there is any question. Thanks ! https://github.com/jeanpan/react-native-camera-roll-picker/commit/16991b522c53b50b567cb47b8c482dd8472358b0

ndao commented 8 years ago

thanks @jeanpan, fyi there are some warnings with the SGListView stuff image

jeanpan commented 8 years ago

@ndao Thanks for the fyi. I will created another issue to track the warnings of SGListView.